Track


The track method lets you send custom tracking events to all of your installed apps.

stackpile.analytics.track(event, [data], [settings], callback);
Parameter Required Description
event Yes This is the name of the event you'd like to track. This is a required parameter.
data No An object containing the custom data you would like to send with the tracking event. Data can be sent to all installed apps, or individual apps, for example mixpanel or heap. See examples below for more info.
settings No An object containing Stackpile specific options. Currently only supports timeout and only. Use the timeout setting to set the timeout duration before the callback function is called. If you only need to send an event to specific apps in your stack, use the only setting. For example: only: ['mixpanel', 'keenio']
callback No A function that is called after the set timeout. Can be used if you need to wait before continuing with a process on your page.

Examples


A few examples of how you can use track to send custom data to your installed apps:

stackpile.analytics.track('Clicked Sign Up', {
    all: {
        type: 'button'
    },
    mixpanel: {
        caption: 'Sign Up'
    }
});

This will send type: "button" to all installed apps and caption: "Sign Up" to Mixpanel.

stackpile.analytics.track('Page View', {}, {
        only: ['mixpanel']
    }
});

This will send a Page View event only to Mixpanel.

You can use the following custom data properties to send custom data to selected apps:

Property App
all All installed apps
amplitude Amplitude
customerio Customer.io
facebookpixel Facebook Pixel
googleanalytics Google Analytics
gosquared GoSquared
heap Heap
keenio Keen IO
kissmetrics Kissmetrics
logrocket LogRocket
mixpanel Mixpanel
optimizely Optimizely
webengage WebEngage
woopra Woopra

If you're using jQuery on your site, you can track a click event with the following code:

$('[data-event]').on('click', function() {
    if (window.stackpile) {
        stackpile.analytics.track($(this).data('event'));
    }
});
<a href="/signup" data-event="Clicked Sign Up">Sign Up</a>

Adding the data-event attribute to any HTML element will then allow you to track a custom event for that action.

onReady


Because our scripts are loaded asynchronous, you could run into an issue when trying to track events as soon as the page loads if the API is not ready yet. The onReady event is a callback function that lets you know when the Stackpile Unified Analytics API is ready.

(_stackpile = window._stackpile || []).push(['onReady', onSPReady]);
function onSPReady() {
    // Code that will be fired as soon as 
    // the API is ready. For example:

    stackpile.analytics.track('Page View');
}

Google Analytics


When sending events to Google Analytics you can make use of the following special properties:

Name Description
category Category that this event should be grouped under. If not set we will use the last bit of the event name. For example Clicked Sign Up would set the category to Sign Up
action Action for this event. If not set we will use the first word of the event name. For example Clicked Sign Up would set the action to Clicked
label Label for this event. If not set we do not send any default for this property.
value Value for this event. If not set we do not send any default for this property.

An example event with custom Google Analytics properties set:

stackpile.analytics.track('Created Widget', {
    googleanalytics: {
        category: 'Widget',
        action: 'New Widget Added',
        label: 'Source',
        value: 'Widget Popup'
    }
});

Mixpanel


Mixpanel has a few special properties that is used to link an event to a person. We automatically transform the email, created and name properties to the special properties if they are set.

Property Mixpanel Property
email $email
created $created
name $name