Source code of logging visitor's action

 Web Access Recorder Logs the Action of the website's visitors by using techique called the JSONP. By using JSONP, you can send data to the server where the domain is different.

Logger's source code

 The logger's source code is in th folder below.


logger's source code

The source code consists from Javascript and server side script.

Javascript to log the action

 The JavaScript to log the website visitor's action is "log.js" in the folder. It does operations below.

  1. Initialize access and write cookie.
  2. Watch user's action and store it into array variable of the Javascript
  3. Flush it periodically.

Initialize Javascript

 At first, the "alinousLogToolsInit()" called from the Javascript.

This code registers the callback functions of each event. The functions are returned by a closure of Javascript.

initialize access code

 After the callback functions for the events registerd, the function for the "onload" event fired at first.

This function gathers information about this access, and sent it by using JSONP. The jsonp() function is one to do it.


 JSONP is technique to access server in the external domain, and send information.

In this script, it does

  • Check the script tag for JSONP and delete it if exsits
  • Create script tag dynamically

This program uses JSONP many times, so it has to delete the script tag used before.

Send report with JSONP

 This Javascript baffers mouse-click, mouse-move, window-scroll and window-resize by the event handler. By calling fireReport() function, it send event to the server side program.

Server side program

The server side program is the "ac.alns". This program is written in Alinous-Core programming language. The Javascript send a parameter named "cmd" and the script selects the operation by the parameter.

This program is mainly logging, but at the first access from the javascirpt, it returns Javascript to write a cookie to the browser.

First Access

 At the first access, it request to atchive the page in the backbround. By using parallel block, it runs in the background simultaneously. About the archiver's source code, please take a look at Archive web page.

 Next, call the "getAccessCode()" function.

This function checks the "user_id" and "access_id". The "user_id" is identifier of user, and the "access_id" is of page access. After check them, insert access record into the "wic_user_page_access" table.

After this function returned, load Jacascript file, which is "/api/addcookie.js", replace the string to replace in this Javascript and return it to the browser.

This program is accessed as source of the Javascript, therefore returned Javascript is executed on the browser.

Store logged data sent from Javascript

if the "cmd" parameter is "sendClicked", "sendScrolled", "sendMouseMoved", or "sendWindowResized", it insert the log into the database.

Go to Top