Tracking visitors behaviour in your web application

ASP.NET, PHP, Tutorials

So you want to know how much time users spend on any specific page of your web application? This article explains how to log what pages your users visit and how much time they spend on each page. This kind of data can provide valuable insight into what forms of your application are too complicated and need to be split into several smaller forms. Or if they keep coming back to the welcome page this may mean your navigation inside the app can be improved.

1. Create log table

The following SQL script creates the log table in the database. The syntax is for MySQL, you can create a similar table in any other database manually, just make sure that field names and datatypes stay the same.

A few notes here:

Note 1: Login is not required. If your project doesn’t use login, ‘userID’ field will be empty.

Note 2: if ‘timeoff’ field is empty that means user spent less than five seconds on the page.

Note 3: it makes sense to add ‘timetracker’ table to the project as well so you can test this functionality. If you do so, set ‘View as’ time of timeon/timeoff fields to ‘Datetime’.

2. Javascript code

The following Javascript code needs to be added under Event Editor -> custom_functions.js

3. Server-side code (PHP and C#)

The following code goes to the AfterAppInit event.



4 thoughts on “Tracking visitors behaviour in your web application

  1. To get the C# code working I had to make 2 changes:

    To get the code to compile I needed to declare ‘data’
    dynamic data = null;

    And to get the date and time to store I need to work I need to change
    XVar.Clone(CommonFunctions.localdatetime2db((XVar)(MVCFunctions.runner_date_format(new XVar(“m-d-y H:i:s”)))));

    dynamic currentDateTimeForDb = null;
    currentDateTimeForDb = DateTime.Now;
    if(MVCFunctions.postvalue(new XVar(“pageOpen”)) != false)
    dynamic data = null;
    data = XVar.Clone(XVar.Array());
    data.InitAndSetArrayItem(MVCFunctions.postvalue(new XVar(“pageName”)), “pagename”);
    data.InitAndSetArrayItem(currentDateTimeForDb, “timeon”);

Leave a Reply

Your email address will not be published. Required fields are marked *