API Transactional Track & Engage Push
Javascript

Tracking Page

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?

The Track&Engage Tracking code looks as follows:

var _egoiaq = _egoiaq || [];
(function () {
    var u = (("https:" == document.location.protocol) ? "http://egoimmerce.e-goi.com/" : "https://egoimmerce.e-goi.com/");
    _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']);
    _egoiaq.push(['addEcommerceItem',
        "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
    _egoiaq.push(['trackEcommerceOrder',
        "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)
    ]);
    _egoiaq.push(['trackPageView']);
    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);
})();

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

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

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

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

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.

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]);
_egoiaq.push(['trackPageView']);

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

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

Manually Trigger a Page View on Click or on JS Event

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>

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.

Manually Trigger a Conversion for a Goal

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(); ?>]);

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:

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

_egoiaq.push(['trackSiteSearch',
    // Search keyword searched for
    "Banana",
    // 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
    0
]);

// We recommend not to call
trackPageView()
// on the Site Search Result page
_egoiaq.push(['trackPageView']);

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.

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.

Tracking Ecommerce

Egoimmerce Analytics Documentation

Once you have enabled Ecommerce tracking for a website, you need to implement tracking of the various Ecommerce interactions on your website. There are three main Ecommerce interactions that are tracked with Egoimmerce:

The following sections explain how to set up Ecommerce tracking, using the JavaScript Tracker Ecommerce tracking methods

Tracking Ecommerce Orders & Items Purchased (required)

Here’s an example of tracking an Ecommerce order containing two products – this code should be inserted in the “Order confirmation” page, once the visitor has checked out and issued payment. If you installed Egoimmerce correctly, your pages should already have a tracking code. The Ecommerce code below must be added and generated based on the Order:

// add the first product to the order
_egoiaq.push(['addEcommerceItem',
    "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
]);
// Here you can add other products in the order
[...]
// Specifiy the order details to Egoimmerce server & sends the data to Egoimmerce server
_egoiaq.push(['trackEcommerceOrder',
    "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)
]);
// we recommend to leave the call to trackPageView() on the Order confirmation page
_egoiaq.push(['trackPageView']);

Tracking Ecommerce orders and product details will allow Egoimmerce to process reports on:

To track Ecommerce orders, two Javascript functions are used:

  1. addEcommerceItem(productSKU, productName, productCategory, price, quantity) This adds a product into the order, and must be called for each product in the order. productSKU is a required parameter, it is also recommended that you send other parameters if they are applicable in your Ecommerce shop.
  2. trackEcommerceOrder(orderId, grandTotal, subTotal, tax, shipping, discount) This tracks an Ecommerce order and sends the data to your Egoimmerce server, for both this order and products previously added. Only orderId and grandTotal (ie. revenue) are required.

Important notes about the functions parameters:

Tracking Add to Cart & Items Added to the Cart (optional)

time a visitor adds (or updates, deletes) an item from his/her cart, you can use Egoimmerce to track the latest cart subtotal as well as products left in the cart. Tracking cart updates will allow you to see how much revenue was left in your visitors’ carts for each day/week/etc, as well as getting reports on which products are most often left in the cart and which product categories are most often left abandoned in carts.

Some frequent causes for cart abandonment are:

When you make changes to your website to lower the cart abandonment rate, and try to increase your revenues, you can use Egoimmerce to understand if your changes are making a positive impact.

To track Shopping Carts with Egoimmerce, you would call the javascript function trackEcommerceCartUpdate() every time a user is adding, updating or deleting a product from the cart.

Example tracking an Ecommerce order containing two products:

The code is added every time the “cart” page is loaded, or when the “Add to cart” button is clicked:

// add the first product to the order
_egoiaq.push(['addEcommerceItem',
    "9780786706211", // (required) SKU: Product unique identifier
    "Endurance: Shackleton's Incredible Voyage", // (optional) Product name
    ["Adventure Books", "Best sellers"], // (optional) Product category, string or array of up to 5 categories
    8.8, // (recommended) Product price
    1 // (optional, default to 1) Product quantity
]);

// Here it is important to add all other products found in the cart, even the products not updated by the current "Add to cart" click
[...]

// Records the cart for this visit
_egoiaq.push(['trackEcommerceCartUpdate',
    15.5]); // (recommended) Cart amount

_egoiaq.push(['trackPageView']);

Tracking Product Page Views & Category Page Views (optional)

Tracking product page views, and/or category page views lets Egoimmerce process the conversion rate for each product and/or category. It can be useful to know which product or category pages have converted your visitors into customers. For example, perhaps some product pages have below average conversion rates but generate high revenue. You may decide to improve these product pages and check their conversion rates over time.

To track a product or category page view, the function setEcommerceView(productSKU, productName, categoryName, price) is used, just before the call to egoimmerceTracker.trackPageView() on the product/category page.

Example Tracking a Product Page View

In this example, the following code is added to the Product page for the book “Endurance” which is in the category “Adventure Books”:

// all parameters are optional, but we recommend to set at minimum productSKU and productName
_egoiaq.push(['setEcommerceView',
    "9780786706211", // (required) SKU: Product unique identifier
    "Endurance: Shackleton's Incredible Voyage", // (optional) Product name
    "Adventure Books", // (optional) Product category, or array of up to 5 categories
    20.11 // (optional) Product Price as displayed on the page
]);
_egoiaq.push(['trackPageView']);

Example tracking a Category page view

This code is added on the Category page “Adventure Books”

// on a category page, productSKU and productName are not applicable and are set to false
_egoiaq.push(['setEcommerceView',
    productSku = false, // No product on Category page
    productName = false, // No product on Category page
    category = "Adventure Books" // Category Page, or array of up to 5 categories
]);
_egoiaq.push(['trackPageView']);