Integration Scenario for ASP.NET

This article will describe how to integrate the Analytics JavaScript monitor in an ASP.NET web application.

The utilization of the JavaScript monitor in web applications has the following steps:

  1. Download the Analytics Monitor.
  2. Add the monitor to your application.
  3. Ensure the monitor is started on each page load.
  4. Handle sign-in and sign-out in your application.
  5. Other considerations.


In general this article targets any web application not being an SPA (Single Page Application), that is, as long as the client is capable of running JavaScript and the browser has cookies enabled everything is fine, and the server backend can be anything: ASP.NET (Web Forms or MVC), NodeJS, JSP hosted, PHP etc.

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.

Step 1. Download the Analytics Monitor

The JavaScript monitor can be downloaded here (requires sign in on the Telerik Platform)

Step 2. Add the monitor to your application

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:

Adding the monitor to a new solution

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:

Open bundle configuration file

In the RegisterBundles method, add the monitor as a separate bundle:

Register script bundle

And you are almost done.

Step 3. Ensure the monitor is started on each page load

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:

Open Layout.cshtml

And then simply render the script, and ensure that it is rendered:

Render script

We render our previously registered script bundle and then on each page we start our monitor. In the current version of the monitor, the settings default to useCookies = true, meaning that we do not have to add that. Besides that everything is as recommended in the JavaScript monitor. From here on we have started the monitor and added a reference to it named _equatecmonitor on the window-object. We will reference this instance each time we do feature tracking.

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:

Open About.cshtml

And then invoke the trackFeature method in the start of rendering the page:

Invoke trackFeature

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:

Feature use

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.

Handle sign-in and sign-out in your application

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.

Other considerations

As mentioned above, the JavaScript monitor can be utilized in any web application, as long as you initialize the monitor on each page where you need to do feature-, timing- or value-tracking. If you want to ensure that the monitor correctly tracks sessions and users it is imperative, that you ensure that cookies are enabled for the user session for this to work, else the monitor will not be able to follow the user between page loads.

Start a free trial Request a demo
Contact us: +1-888-365-2779
Copyright © 2016-2017, Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.