Register

Install website tracking using the JS tracking library

If are unable to install website tracking using our supported plugins, you have the option to install the JS tracking library by copying and pasting the appropriate code snippet into your website's <head> section. This enables website tracking of your visitors' actions which you can use as triggers for automation workflows. Use the following procedures to install different types of website tracking using the JS tracking library after adding your website:

A. Find the custom installation script

  1. In the top navigation bar, click Account_icon.png and click Websites.
  2. Click the URL of the website you want to track to display the Connect your website page with your domain and your website ID. Take note of this website ID for the next procedure.
  3.  Click the Install connection script tab, navigate to Custom installation, and click Install.

B. Install the JS Tracking Library

Install the JS tracking library by copying and pasting a code snippet within the <head> section of your website. The first part of the code snippet loads the tracker and the second part initializes it to gather tracking events.

  • In the Install Connection Script page, under Custom installation, click </> Copy to copy the code.  Alternatively, you can manually copy the following: 

    <script>
    //load TrackerJS
    !function(t,n,e,o,a){function d(t){var n=~~(Date.now()/3e5),o=document.createElement(e);o.async=!0,o.src=t+"?ts="+n;var a=document.getElementsByTagName(e)[0];a.parentNode.insertBefore(o,a)}t.MooTrackerObject=a,t[a]=t[a]||function( ){return t[a].q?void t[a].q.push(arguments):void(t[a].q=[arguments])},window .attachEvent?window.attachEvent("onload",d.bind(this,o) ):window.addEventListener("load",d.bind(this,o),!1)}(window,document,"script","//cdn.stat-track.com/statics/moosend-tracking.min.js","mootrack");

    //tracker has to be initialized otherwise it will generate warnings and wont send tracking events
    mootrack('init', '12A3B4C56D7890EF12345678GH901IJ2');
    </script>

    Note: Make sure that the last part of the initialize code '12A3B4C5-6D78-90EF-12345678GH901IJ2' is replaced with your website ID.

B. Identify visitors

You can add an identify call to allow you to identify your visitors, connect them to their actions, and record their traits. The code in this call allows you to to identify a user via a unique email and name. We recommend that you call identify after a user registers, after a user logs in, and if applicable, after a user provides their email as part of your newsletter subscription form. 

  • Scroll down the Install Connection Script page, under Identify Visitors, click </> Copy to copy the code or you can manually copy the following: 

    // identify with email
    mootrack('identify', 'john@doe.com');

    // identify with email and name
    // commented out as you need to choose one of these calls only
    //mootrack('identify', 'john@doe.com', 'John Doe');

C. Track page view events

If you also want to track page view events, you can use the track page view call on our platform's tracker library. We recommend that you add this event within the <head> section of your HTML master or template page, after the you initialize the library. 

  • Scroll down the Install Connection Script page, under Track Page View Events, click </> Copy to copy the code or you can manually copy the following: 

    // track a view of the current page
    mootrack('trackPageView');

D. Track item added to cart

One of the most recommended tracking in e-commerce is tracking when a user adds an item to their cart and when they complete an order. By tracking these events, you can implement Cart abandonment emails when a user adds an item to their cart.

  • Scroll down the Install Connection Script page, under Track item added to cart, click </> Copy to copy the code or you can manually copy the following: 
    // mandatory - a unique code for the product, like its SKU
    var itemCode = 'COW-T-SHIRT';
    // mandatory - the price of this product
    var itemPrice = 12.02;
    // mandatory - the url to get to the relevant product page
    var itemUrl = 'http://your.store/product-101';
    // mandatory
    var itemQuantity = 2;
    // mandatory - the total price for purchasing the given quantity of this product
    var itemTotalPrice = 24.04;
    // mandatory - the name / title of this product
    var itemName = 'Cow T-Shirt'; // mandatory
    // mandatory - the image url of this product
    var itemImage = 'http://your.store/product-color-blue.jpg';
    // optional - the category of this product
    var itemCategory = 'T-Shirts';
    // optional - the manufacturer, brand name or company / owner of this product (if any)
    var itemManufacturer = 'Acme Co';

    // you can add custom properies and later use them in segmentations or automations
    // You can track things like the category or the manufacturer of the t-shirt in this case
    var extraProps = {
       itemCategory: itemCategory,
       itemManufacturer: itemManufacturer

    };

    // Tracking add to cart events with mandatory arguments mootrack('trackAddToOrder', itemCode, itemPrice, itemUrl ,itemQuantity);

    // Tracking add to cart events with mandatory arguments + optional mootrack('trackAddToOrder', itemCode, itemPrice, itemUrl, itemQuantity, itemTotalPrice, itemName, itemImage, extraProps);

E. Track order completed events

Another useful e-commerce tracking is tracking when a user successfully completes an order. Using a tracking code, you can track this type of event to implement Purchase completed follow-up emails when an item is purchased. 

  • Scroll down the Install Connection Script page, under Track order completed events, click </> Copy to copy the code or you can manually copy the following: 

    // send order completed events

    var product1 = {
       // mandatory - a unique code for the product, like its SKU
       itemCode: 'COW-T-SHIRT',
       // mandatory - the name / title of this product
       itemName: 'Cow T-Shirt',
       // mandatory - the image url of this product
       itemImage: 'http://your.store/product-color-blue.jpg',
       // mandatory - the price of this product
       itemPrice: 12.02,
       // mandatory - the url to get to the relevant product page
       itemUrl: 'http://your.store/product-101',
       // mandatory
       itemQuantity: 2,
       // mandatory - the total price for purchasing the given quantity of this product     
    itemTotalPrice: 24.04,
       // optional - the category of this product
       itemCategory: 'T-Shirts',
       // optional - the manufacturer, brand name or company / owner of this product (if any)
       itemManufacturer: 'Acme Co'
    };

    // Products should be an array with an object like product.
    var products = [product1, product2, ....];
    mootrack('trackOrderCompleted', products);

F. Track product view events

You can also track the event when a user views a product, before adding it to cart or purchasing. By tracking these events, you can implement advanced re-targeting strategies like browse abandonment. You can then engage recipients when there is a user who viewed a product but did not purchase it.

  • Scroll down the Install Connection Script page, under Track product view events, click </> Copy to copy the code or you can manually copy the following: 

    var product1 = {
    // mandatory - a unique code for the product, like its SKU
    itemCode: 'COW-T-SHIRT',
    // mandatory - the name / title of this product
    itemName: 'Cow T-Shirt',
    // mandatory - the image url of this product
    itemImage: 'http://your.store/product-color-blue.jpg',
    // mandatory - the price of this product
    itemPrice: 12.02,
    // mandatory - the url to get to the relevant product page
    itemUrl: 'http://your.store/product-101',
    // mandatory 
    itemQuantity: 2,
    // mandatory - the total price for purchasing the given quantity of this product 
    itemTotalPrice: 24.04,
    // optional - the category of this product
    itemCategory: 'T-Shirts',
    // optional - the manufacturer, brand name or company / owner of this product (if any) itemManufacturer: 'Acme Co',
    // optional - the supplier of this product (if any)
    itemSupplier: 'Supplier Co',

    // you can add custom properties and later use them in segmentations or automations
    color: 'Red', // You can track things like the color
     size: 'XXL' // or the size of the t-shirt in this case

    };

    // Product should be sent back as an array with an object which includes the product above
    var productInfo = [{ product: product1 }];
    mootrack('PAGE_VIEWED', productInfo);
     

G. Tracking custom events

Optionally, you can track any custom event relevant to your business using a single line of tracking code. For example, if you want to track a simple event like "Video played" and track custom event properties, such as "length" and "id", you can use a code to describe the event you are tracking or the user who triggered that event.

  • Scroll down the Install Connection Script page, under Track custom events, click </> Copy to copy the code or you can manually copy the following: 
    mootrack('Video Played', { "Video length": 123, "id": "h17gQr0" });

In this example, you can include your own properties by including them in the object as the second argument to the mootrack code. You must refresh the page after adding this tracking.