Background

AJAX (or Asynchronous JavaScript And XML) is a technique which allows a web page to draw content from the server without requiring a full reload of the page. Sites using AJAX extensively to display new content (such as some photo galleries and forums) are tracked correctly by the standard Effective Measure tag when a page is loaded, however they may be under-represented in the Page View count. This is because the standard Effective Measure tag posts a record of the a page loading as part of the load process. The tag does not, by default, register an event for AJAX calls for new content after the page has loaded. To support sites using this technique, functionality to register these content requests via AJAX has been included within the Effective Measure code.

Implementation

To access the AJAX tracking features of the Effective Measure code, a function has been created that can be called during the AJAX request for new content.

The first step to implementing AJAX tracking, is to ensure the latest version of the Effective Measure tags are working correctly on the site. This should be completed as described in the standard Effective Measure tagging instructions.

Once the tags are inserted in the pages and working correctly, the client will then need to include in their own AJAX code, a call to the Effective Measure AJAX function (see below).

_em.trackAjaxPageview("optional_page_url_or_label");
An example of the AJAX tracking implementation
//...
http_request.onreadystatechange = sendAlert;
http_request.open('GET', url, true);
http_request.send(null);
//...
function sendAlert() {
  if (http_request.readyState == 4) {
    if (http_request.status == 200) {
      alert(http_request.responseText);
      _em.trackAjaxPageview("http://www.examplesite.com/path");
    }
  else {
    alert('Error.');
  }
}
//..

Demonstration URL: 

http://demo.effectivemeasure.com/demo/ajaxdemo.html

A Flash file embedded in HTML page can also send AJAX like requests and/or load new content without a full reload of a page. The Effective Measure AJAX function can also be used to track such events inside the Flash files.

The flash file needs to trigger a call to the Effective Measure AJAX function in the event of loading new content:

//...
getURL('javascript:_em.trackAjaxPageview("http://www.examplesite.com/path")'); //Actionscript 2
//OR
import flash.external.ExternalInterface;
ExternalInterface.call('_em.trackAjaxPageview', "http://www.examplesite.com/path"); //Actionscript 3
//..

Once this has been setup, you should be able to see a call to the Effective Measure servers with each AJAX content request. This can be easily confirmed using a web developer tool such as Firebug to track the requests as they occur.

If you have any questions, please contact support@effectivemeasure.com

Short Link: http://emeasu.re/_ajax

Did this answer your question?