Setup Clickstream Tag

How to add clickstream tracking

  1. Open the profile and select API keys tab and create an API key with permissions "clickstream:write", click add:
  2. Open your GTM (Google Tag Manager) account and create new tag, name it something like stacktome-clickstream-tag - select "Custom HTML" and copy the template below:

      <!-- Snowplow starts plowing -->
    <script type="text/javascript">
    var o = XMLHttpRequest.prototype.open;
    XMLHttpRequest.prototype.open = function(){
      var res = o.apply(this, arguments);
      var err = new Error();  
      if((arguments[1] || '').indexOf('stacktome') > 0)
        this.setRequestHeader('apikey', '{{API_KEY}}' );
      return res;
    }
    ;(function () {
        ;(function(p,l,o,w,i,n,g){if(!p[i]){p.GlobalSnowplowNamespace=p.GlobalSnowplowNamespace||[];
        p.GlobalSnowplowNamespace.push(i);p[i]=function(){(p[i].q=p[i].q||[]).push(arguments)
        };p[i].q=p[i].q||[];n=l.createElement(o);g=l.getElementsByTagName(o)[0];n.async=1;
        n.src=w;g.parentNode.insertBefore(n,g)}}(window,document,"script","//cdn.stacktome.com/snowplow/2.14.0/sp.js","snowplow"));
        
         window.snowplow('newTracker', 'cf1', 'services.stacktome.com/clickstream/collector',
        { // Initialise a tracker
          appId: '{{ACCOUNT_NAME}}', // account_name that is tracked
          platform: 'web',
          cookieDomain: '{{WEBSITE_DOMAIN}}',
          sessionCookieTimeout: 3600, // one hour
          post: true,
          contexts: {
              performanceTiming: true,
              webPage: true
          }
        });
    }());
    
    
    <!-- Snowplow stops plowing -->
    window.snowplow('trackPageView', null , null, null);
    </script>
    	
  3. Replace placeholder values for
    - {{API_KEY}} - API key with clickstream:write permisions
    - {{ACCOUNT_NAME}} - the account name in profile
    - {{WEBSITE_DOMAIN}}  - with your website domain, e.g. stacktome.com
  4. Once the tracker is set you can verify if clickstream events get sent by using this extension and opening your website

Still need help? Contact Us Contact Us