Javascript Tracking client How-to

Track&Engage is equipped with a powerful JavaScript Tracking API. Advanced users can use the Track&Engage tracking code to customize the way some of the web analytics data is recorded in Track&Engage.

Where can I Find the Track&Engage Tracking Code?

You can now copy and paste the JavaScript Tracking code into your pages, just before the </body> tag.

The Track&Engage Tracking code looks as follows:

var _egoiaq = _egoiaq || [];
(function () {
    var u = (("https:" == document.location.protocol) ? "" : "");
    _egoiaq.push(['setClientId', "1"]);
    _egoiaq.push(['setSubscriber', "1234"]); // You can use the uid (unique identifier) or the email or the phone number
    _egoiaq.push(['setListId', "3"]); // List identifier
    _egoiaq.push(['setCampaignId', "4"]); // Campaign identifier
    _egoiaq.push(['setTrackerUrl', 'rest/collector/collect']);
        "9780786706211", // (required) SKU: Product unique identifier
        "Endurance: Shackleton's Incredible Voyage", // (optional) Product name
        "Adventure Books", // (optional) Product category. You can also specify an array of up to 5 categories eg. ["Books", "New releases", "Biography"]
        8.8, // (recommended) Product price
        1 // (optional, default to 1) Product quantity

    // Specifiy the order details to Track&Engage server & sends the data to Track&Engage server
        "A10000123", // (required) Unique Order ID
        35, // (required) Order Revenue grand total (includes tax, shipping, and subtracted discount)
        30, // (optional) Order sub total (excludes shipping)
        5.5, // (optional) Tax amount
        4.5, // (optional) Shipping amount
        false // (optional) Discount offered (set to false for unspecified parameter)
    var d = document, g = d.createElement('script'), s = d.getElementsByTagName('script')[0];
    g.type = 'text/javascript';
    g.defer = true;
    g.async = true;
    g.src = u + 'egoimmerce.js';
    s.parentNode.insertBefore(g, s);

This code might look a bit strange to those of you familiar with JavaScript, but that is because it is made to run asynchronously. In other words, browsers will not wait for the Track&Engage.js file to be downloaded in order to show your page.

Customize the Page Name Displayed in Track&Engage

By default, Track&Engage uses the URL of the current page as the page title in the Track&Engage interface. If your URLs are not simple, or if you want to customize the way Track&Engage tracks your pages, you can specify the page title to use in the JavaScript code.

A common use is to set the HTML Title value as the document title:

_egoiaq.push(['setDocumentTitle', document.title]);

If you track multiple sub-domains in the same website, you may want your page titles to be prefixed by the sub-domain make it easy for you to see the traffic and data for each sub-domain. You can do so simply in JavaScript:

_egoiaq.push(['setDocumentTitle', document.domain + "/" + document.title]);

Advanced users can also dynamically generate the page name, for example, in PHP:

_egoiaq.push(['setDocumentTitle', "<?php echo $myPageTitle ?>"]);

Manually Trigger a Page View on Click or on JS Event

By default, Track&Engage tracks page views when the Javascript tracking code loads and executes on each page view. However, on modern websites or web applications, user interactions do not necessarily involve loading a new page. For example, when users click on a JavaScript link, or when they click on a tab (which triggers a JS event), or when they interact with elements of the user interface, you can still track these interactions with Track&Engage.

To track any user interaction or click with Track&Engage, you can manually call the Javascript function trackPageView(). For example, if you wanted to track a click on a JavaScript menu, you could write:

<a href="#" onclick="javascript:_egoiaq.push(['trackPageView', 'Menu/Freedom']);">Freedom page</a>

Manually Trigger a Conversion for a Goal

By default, Goals in Track&Engage are defined as "matching" parts of the URL (starts with, contains, or regular expression matching). You can also track goals for given page views, downloads, or outlink clicks.

In some situations, you may want to register conversions on other types of actions, for example:

  • when a user submits a form
  • when a user has stayed more than a given amount of time on the page
  • when a user does some interaction in your Flash application
  • when a user has submitted his cart and has done the payment: you can give the Track&Engage tracking code to the payment website which will then register the conversions in your Track&Engage database, with the conversion's custom revenue

To trigger a goal using the Track&Engage JavaScript Tracking, you can simply do:

// logs a conversion for goal 1
_egoiaq.push(['trackGoal', 1]);

You can also register a conversion for this goal with a custom revenue. For example, you can generate the call to trackGoal dynamically to set the revenue of the transaction:

/* logs a conversion for goal 1 with the custom revenue set */
_egoiaq.push(['trackGoal', 1, <?php echo $cart->getCartValue(); ?>]);

Tracking Ecommerce Orders, Cart Updates and Product/Category Page Views

Track&Engage allows for advanced and powerful Ecommerce tracking. Check out the Ecommerce Analytics documentation for more information about Ecommerce reports and how to set up Ecommerce tracking.

Tracking internal Search Keywords, categories, and No Result Search Keywords

Track&Engage offers advanced Site Search Analytics feature, letting you track how your visitors use your internal website search engine. By default, Track&Engage can read URL parameters that will contain the search keyword. However, you can also record the site search keyword manually using the Javascript function trackSiteSearch(...)

In your website, in standard pages, you would typically have a call to record Page views via trackPageView(). On your search result page, you would call instead trackSiteSearch(keyword, category, searchCount) function to record the internal search request. Note: the 'keyword' parameter is required, but category and searchCount are optional.

    // Search keyword searched for
    // Search category selected in your search engine. If you do not need this, set to false
    "Organic Food",
    // Number of results on the Search results page. Zero indicates a 'No Result Search Keyword'. Set to false if you don't know

// We recommend not to call
// on the Site Search Result page

We also highly recommend to set the searchCount parameter, as Track&Engage will specifically report "No Result Keywords", ie. Keywords that were searched, but did not return any result. It is usually very interesting to know what users search for but can't find (yet?) on your website.