- Download the Analytics Monitor.
- Add the monitor to your application.
- Ensure the monitor is started on each page load.
- Handle sign-in and sign-out in your application.
- Other considerations.
The main requirement is that the browser has cookies enabled. Having cookies enabled allows the monitor to track users and sessions between page loads.
In the following sections, we will enable the Analytics Monitor in a simple ASP.NET MVC 5 application. The steps in more complex or other web frameworks are similar.
Say we have created a brand new application using Visual Studio 2013, then we simply add the monitor to our solution in the scripts section:
Next we need to ensure that the script is included on the the pages where we need tracking. Say we need to do that on any page in our application, one thing we could do is to either add the monitor to an existing script bundle or create a separate bundle. Open the bundle configuration file:
In the RegisterBundles method, add the monitor as a separate bundle:
And you are almost done.
In this simple scenario, we want to ensure that we are utilizing the monitor on all pages in our web application, so we decide to include the script bundle in each rendered page. This can easily be achieved by rendering the script in the shared _Layout.cshtml page:
And then simply render the script, and ensure that it is rendered:
Of course, in more complex applications, this might need to be done in multiple places.
Whenever you want to track a feature, ie. on rendering the About page, all you need to do is open the About.cshtml file:
And then invoke the trackFeature method in the start of rendering the page:
In the above example, we have utilized the well known dot-notation, meaning that the first string before the first dot by Analytics is considered a category, and then followed by the name of the feature we track.
Say we now do simple feature-tracking on our standard application from above, meaning we just blindly track clicks in the menu, then after a while (remembering the five minutes delay) we will have the following analytics data:
As you can see the first string "TAT" has been used to categorize our feature tracking. In case you forget this, a separate category named (No Category) will be created in the top.
In web applications, where a "session" is a thing that logically goes on as long as a user is signed in, and logically stops upon signing out, these two events are natural candidates for invoking the start() and stop() methods on the monitor.