Implementing Mixpanel tracking

To implement Mixpanel tracking, you need a token, an API key and a secret. These are provided by SPiD when new clients are created. There are four steps to enable Mixpanel tracking for your site:

  1. Install the Mixpanel library
  2. Include the JavaScript SDK
  3. Identify the visitor via the SPiD SDK
  4. Track events using the provided SPiD visitor unique id

It is recommended to read through the Mixpanel documentation and research which events to track, and which funnels to implement before pushing events to Mixpanel.

1. Installing the Mixpanel library

We recommend using the Mixpanel JavaScript library, although there are other implementations too.

2. Include the JavaScript SDK

Add the JavaScript SDK just before the </head> end tag of your page, for example (remember to use the latest version):

<script src="https://identity-pre.schibsted.com/js/spid-sdk-1.7.9.js"></script>

Read more here.

3. Identify the visitor via the SPiD SDK

When the page has loaded, subscribe to the "auth.visitor" event. This event is triggered when SPiD identifies the current visitor and the SDK is initialized. When the user is identified, you can identify the user with Mixpanel by calling mixpanel.identify(SPID_VISITOR_ID).

Place the following code in a script block right before the closing </body> tag, or in a DOMContentLoaded event handler (e.g. $(document).ready(function () { /* Here */ }) if using jQuery).

VGS.Event.subscribe('auth.visitor', function(data) {
    mixpanel.identify(data.uid);
    var signedData = '{YOUR SIGNED JSON OBJECT}';
});

VGS.init({
    client_id: '{YOUR STAGE/PRE CLIENT ID}',
    server: 'identity-pre.schibsted.com',
    prod: false,
    logging: true,
    status:true
});

4. Track events using the provided SPiD unique visitor id

// your own tracking
mixpanel.track('Viewed campaign page', {'campaign': 'Sommerkampanje'});

Read more about Mixpanel

Help us improve

Did you spot an error? Or maybe you just have a suggestion for how we can improve? Leave a comment, or better yet, send us a pull request on GitHub to fix it (in-browser editing, only takes a moment).

History of this page

Comments/feedback

Do you have questions, or just want to contribute some newly gained insight? Want to share an example? Please leave a comment. SPiD reads and responds to every question. Additionally, your experience can help others using SPiD, and it can help us continuously improve our documentation.