Campaign Design API > How to properly track visitor's activities

Who is this article for?

  • Web Developers who build optimization campaigns
  • Marketers working closely with Web Developers managing optimization campaigns

Overview

Visitor behaviour tracking is done in two possible ways:

  1. Maxymiser server (Content Generator) detects environmental parameters automatically (e.g., geo-location, traffic source, wheather conditions, etc.)
  2. CD API scripts capture visitor activities in the browser (for instance: click on a link, logging in, scroll to a specific part of a page, etc.)

On the client-server communication schema (shown below) environmental data is gathered with the help of the first (initial) request to the Maxymiser server (request #1 to Content Generator) and all custom parameters are sent with the subsequent requests (requests #2, #3, #4, etc.) triggered by manually-coded CD API scripts.

CG requests

In this article we will look at examples of CD API code and recommendations for the most common use cases of:

  • action tracking
  • custom attribute capturing
  • visitor ID setting

All of these are passed as parameters to the Maxymiser server whenever corresponding custom CD API code is executed.

How to track a visitor's action

"Action" is visitors' reaction to a specific experience. You can choose it to be a click, page view, number of purchases, or whatever you need by doing it via custom coding. Every configured action serves as a vote for a specific variants combination whenever a visitor does it.

Action data is passed to Maxymiser in the same way as any other client-side visitor activity or charachteristic – via a pre-set URL parameter. For example, if you assign a click handler with the action tracking code to a link on a page, every visitor's click on the link will be passed to supplement corresponding data in Maxymiser reports.

Action means something to a report only after visitor has been involved into corresponding optimization campaign. In the other case all the actions that are passed to Maxymiser are ignored.

Different methods of CD API can only define when the information is passed to the server:

actions.send()

Sends action data. Can be called individually to pass an action to Maxymiser or with preceding actions.set() calls to pass the whole queue of actions collected on the current page.

Code example

actions.send('Add2Basket', '1'); // sends "Add2Basket" action to Maxymiser

actions.set()

Collects action data, so that more than one action can be sent at a time. This method captures the action info to be passed with the next Content Generator call on the page (i.e., with actions.send(), visitor.requestPage() or renderer.getContent() call).

Code example

actions.set('Purchase', '1'); actions.set('PurchasedItems', pageData.items); actions.set('PurchaseAmount', pageData.total); actions.send(); // sends the 3 actions to Maxymiser CG

actions.postpone()

Persistently saves action data for the next Maxymiser request, so that action data is not lost between pages. Saving the action info to an internal cookie helps in situations when sending a request immediately is not an option, for instance when visitors travels between pages on action. In this scenario browser will likely close all open connections if you try passing action data immediately.

In case actions.postpone() is used for transferring action data to the next page of the visitor's journey, the Maxymiser tag should be present on the target page so that the information is not lost. Otherwise action data will be tracked only when visitor gets back to a page with the Maxymiser tag.

Code example

jQuery('.continue-link').on('click', function() { actions.postpone('ContinueClick', '1'); // passed to Maxymiser on the next page });

actions.trackClicks()

Assigns a click handler to a link that passes action data to Maxymiser automatically. actions.trackClicks() is a high-level method that detects link type and applies either actions.send() or actions.postpone() correspondingly.

Code example

actions.trackClicks('.continue-link', { name: 'ContinueClick', value: 1 }, 1);

How to assign a custom attribute's value

"Custom attribute" is a visitor's characteristic used to segment visitors into groups. These attributes can be used for campaign/content targeting and reporting. In contrast with out-of-the-box attributes that can be calculated by Maxymiser server, custom attributes are captured on the client and only then passed to the server with help of CD API scripts.

Custom attribute value should be set before the target optimization campaign has been generated for a visitor. It should be done in order to enable proper targeting rules and record the corresponding values into the reports.

visitor.setAttr()

Captures custom attribute information to be passed with the next request to the Maxymiser server on the current page. This method is used when a custom attribute should not be persistently stored in a cookie for several campaigns. By putting the tracking code in a campaign script and not storing the custom attribute persistently you can make your code-base and visitor's browser cookies cleaner.

Code example

visitor .setAttr('AccountType', dataLayer.customer) // "visitor", "standard" or "premium" .requestPage('Lightbox') .done(function() { renderer.runVariantJs(); });

visitor.storeAttr()

Captures custom attribute data persistently to be passed with any further requests to the Maxymiser server on any page. This method is used when a custom attribute should be tracked for several campaigns. Please note that long custom attribute names and values increase visitor cookies size (more insight on optimal usage of Maxymiser cookies is available at Reducing Maxymiser's Cookies Size).

Code example

// makes the attribute available for all the campaigns visitor will generate into visitor.storeAttr('AccountType', dataLayer.customer);

How to set an external visitor ID

"External visitor ID" is an unique identifier used to associate a visitor with his profile imported to Maxymiser (i.e., assign imported custom attribute values to every site visitor).

visitor.setId()

Captures external visitor ID value to be passed with the next request to the Maxymiser server on the current page. This method is used when the ID should not be persistently stored in a cookie for several campaigns. By putting the tracking code in a campaign script and not storing the ID persistently you can make your code-base and visitor's browser cookies cleaner.

Code example

visitor .setId(1, dataLayer.customerId) .requestPage('Lightbox') .done(function() { renderer.runVariantJs(); });

visitor.storeId()

Captures external visitor ID value persistently to be passed with any further requests to the Maxymiser server on any page. This method is used when the ID should be tracked for several campaigns. Please note that long ID values increase visitor cookies size (more insight on optimal usage of Maxymiser cookies is available at Reducing Maxymiser's Cookies Size).

Code example

// makes the ID available for all the campaigns visitor will generate into visitor.storeId(1, dataLayer.customerId);