Menu Sheet Overlay
Search Sheet

JavaScript Client

A JavaScript client is available to Mobify customers and partners. Please contact your Customer Success Manager or Partner Manager for access. With the JavaScript client, sending events can be done via a simple JavaScript integration.

Step 1. Adding the Event Tracking Snippet

(function(s,a) {
    s['SandyAnalyticsObject'] = a;
    s[a] = s[a] || function() {
        (s[a].q = s[a].q || []).push(arguments)
})(window, 'sandy');

Step 2. Creating a JavaScript Tracker

A tracker will make sending events simple, especially across sessions for the same unique user by creating and handling unique client and session identifiers. A tracker requires a slug and a cookie domain. The cookie domain can be β€˜auto’ for automatic configuration.

Creating a single tracker

Typically a web page will require only one tracker to be created:

sandy('create', 'example-slug', 'auto');

Creating multiple trackers

In the rare case that multiple trackers are needed on a given page, there are two options:

Share a global tracker

if (!Sandy.isInitialised(window)) {
    sandy('create', 'beyond-the-rack', 'auto');

Namespace multiple trackers

Sandy.init(window, {'name': 'tracker2'})
tracker2('create', 'example-slug', 'auto');

Step 3. Sending events via a tracker

The JavaScript tracker supports sending pre-defined events and custom events, either of which can be sent with additional metadata stored as Dimensions. Dimensions can be set on a tracker that apply to all future events.

// set one dimension at a time
sandy('set', 'region', 'americas');

// or several at once
sandy('set', {
   'region': 'americas',
   'language': 'en-ca'

In the above scenario, all future events will be sent with region and language dimensions. Dimensions require a string key and a primitive value (boolean, string, number).

Example Events

Page View Events

Page View events will track which pages shoppers visit via a simple call such as:

sandy('send', 'pageview');

Additional dimensions for page title, URL path and URL will be added automatically if they are not provided. Otherwise they can be defined explicitly:

sandy('send', 'pageview', {
    page: '/category/shirts',
    title: 'Shirts!',
    location: ''

Timing Events

Timing Events can track different categories of timing data to allow real-user performance monitoring to ensure an optimal mobile experience. See the list of different Timing Events for full details.

// send category, action, label and value as parameter values
sandy('send', 'timing', 'timing', 'DOMContentLoaded', '', myTimerValue);

Ecommerce Events

ecommerce Events track shopper behavior such as completing a purchase. See the list of different ecommerce Events for full details.

// command, category, action, label, value, dimension object
sandy('send', 'event', 'playerActions', 'pause', '', 95, {
    'trackName': 'Nowhere to Run',
    'trackArtist': 'Martha Reeves and the Vandellas'

What's Next?

Review what events can be sent


Was this page helpful?