Application Usage Tracking System
My Application Usage Tracking System
This document explains why the system was developed, its design and implementation.
Business Requirements
Need to track the web application usage. How often is the application accessed, how many different users access the
system, what features of the site are accessed, and how these visits change over time.
System Requirements
A simple system was decided upon. A system to keep track of who, where, and when a particular web page is visited.
This information will be stored when a page is accessed.
The information captured is simple:
•
•
•
Place Visited, this value is supplied when the tracking is made.
When Visit is made, this value is generated when the tracking is made.
Who is Visiting, this value is stored and is accessible by all other tracking calls.
In order to standardize the Place value and give more meaning to the places visited, a list of places will be created. This
way, the places can be better organized for later study and more meaning can be derived from the tracking information.
When will be a timestamp taken at the time when the visit is made.
Who, the Id of the tracked user. Takes much more thought of how to implement. A simple non-intrusive method needs
to be devised to identify who is tracked. After much thought, the initial who id will be a string version of the first
timestamp taken by the system. This value will be stored on the client so that further tracking can access this value.
The storage of the who id has caused a lot of problems. This is discussed at the end of this document.
Design
What needs to be created then is a place (Database Table) to store the tracking data(Data Structure); a standard method
of writing the information to the data store (Stored Procedure); a standard method of that method (Web API); finally,
JavaScript functions and a .Net Class needs to be developed so that JavaScript and ASP.Net code can make tracking calls.
In detail this is defined as
•
•
•
•
•
•
•
•
Database Table: Tracking
Data Structure: ReqTrackingInfo - Request Tracking Information
Stored Procedure: addTrackingInfo
Web API: This will be handled by the site’s - MyWebAPI
JavaScript Function: TrackIt()
C# Class: Tracker
JavaScript Usage: trackIt("ProductionTimer");
C# Usage: Tracker tracker = new Tracker(Request, Response); tracker.addUsage("Gallery");
Tracking System Database Tables
Contact *
Tracking *
Column Name
Data Type
Column Name
Allow Nulls
Data Type
place
nvarchar(20)
ContactId
int
who
nvarchar(30)
Name
nvarchar(50)
whenTS
datetime2(7)
Email
nvarchar(50)
VisitorType
nvarchar(30)
Comment
nvarchar(254)
Who
nvarchar(30)
Rating
tinyint
Actual
bit
Created
datetime2(7)
Allow Nulls
WhoControlTable *
Column Name
Places *
Column Name
Data Type
Place
nvarchar(20)
ParentPlace
nvarchar(20)
DisplayName
nvarchar(50)
KeyPlaceName
nvarchar(20)
SortOrder
int
SortOrderKey
int
IsGeneral
bit
IsKey
bit
IsApplication
bit
Allow Nulls
Data Type
Who
nvarchar(30)
Name
nvarchar(50)
ContactEmail
nvarchar(50)
Created
datetime2(7)
Verified
bit
CreatedPlace
nvarchar(20)
Allow Nulls
Place to CreatedPlace
Place to App
ConnectedUser *
Column Name
Data Type
Who
nvarchar(30)
App
nvarchar(20)
AppWhoId
nvarchar(30)
Allow Nulls
The primary table is the Tracking table
The primary key to the tracking table is the When Time Stamp as it is the field that will always unique in this table under
the usage of this application.
The Places table controls the values used in the Place column.
The who control table, along with the Connected User tables are temporary tables used to analyze who is using the
entire system and is used to connect tracking system to the Contact table and to other applications controlled by the
system such as the Notebook and Production Timer apps.
Data Structure
ReqTrackingInfo – Request Tracking Information
public class ReqTrackingInfo
{
public string Place { get; set; }
public string Who { get; set; }
public string WhenTS { get; set; }
}
Stored Procedure
A very simple stored procedure addTrackingInfo that takes 3 parameters, place, who and when. These are for simplicity
all variable character parameters. The when variable is converted to a timestamp. These values are inserted into the
Tracking Table.
addTrackingInfo
@place
@who
@when
NVARCHAR(20),
NVARCHAR(30),
NVARCHAR(30)
Web API
MyWebAPI is the API Controller that handles the Posted REST call to the
http://www.DSBburn.com/api/MyWebApi/Track URL with the payload contained in the ReqTrackingInfo data structure.
This action then makes a call to the Stored Procedure addTrackingInfo.
JavaScript Function to set tracking information
function trackIt(placeName)
This function does the following:
Creates a local persistent cookie for the current web page that tracks when the page was visited. If a
cookie already exists, then use it otherwise create a new one. If this is a return visit that has
occurred within 10 minutes then return with no tracking information saved.
Otherwise save the current time.
Retrieve the who session variable value. If It doesn’t exist then retrieve the general cookie value
for the who id. If that doesn’t exist then create a new who id, and store the value as a general
cookie. Set the session variable value to the cookie value.
Set the ReqTrackingInfo data structure.
Make an AJAX call to the Web API using the ReqTrackingInfo data structure.
The Web API does not return any value.
C# Class
This class is accessible for any ASP.NET MVC application that uses the Tracker system.
The addUsage method will act similarly to the JavaScript TrackIt() function.
JavaScript Usage
The way to use this function is to within an initialization function call the TrackIt() function. This is done by doing the
following:
1. Define in the HTML as part of the tag an onload JavaScript event function
2. Define the event function
function initializeForm() {
extractCookies();
trackIt("ProductionTimer");
…
}
Note that the extractCookies(); is a function that extracts all of the app level cookies this needs to be done outside of the
function so that the local cookies and general cookies are extracted. This will store the visited place ProductionTimer.
C#/ASP.Net MVC Usage
In order to use the Tracker class you must reference its namespace. The suggested place to place the call define and call
the addUsage method is in the controller class that defines the web page’s view. For instance in the DSBburnAbout
page it would be in the Default Controller’s Abouit ActionResult method. It would look like this…
public ActionResult About()
{
Tracker tracker = new Tracker(Request, Response);
tracker.addUsage("DSBBurnAbout");
return View();
}
The Who Problem
The main problem I have had with this system has been persisting on the client side the Who value. The first thing I
tried was using cookies. However, many phone browsers and computer users either reject or don’t allow persistent
cookies.
A partial solution was to use session variable. The first time accessed the who cookie was accessed, if it didn’t exist then
a new who value was created, regardless this who value was then stored as a session variable and this value would be
used for the current and subsequent session tracking. However, it appears that mobile browsers do always utilize
session data. Another solution needs to be found to solve this problem.
This is not a high priority problem. There is a work around at the reporting end and it will do until this problem is fully
resolved.