Skip to content

Instantly share code, notes, and snippets.

@fblundun
Last active August 29, 2015 14:05
Show Gist options
  • Save fblundun/beccfe1d5036b47d3eba to your computer and use it in GitHub Desktop.
Save fblundun/beccfe1d5036b47d3eba to your computer and use it in GitHub Desktop.
2.0.0 invocation tag example
<!--
In this example, there are two script elements on the page: one firing a page view and the other a structured event.
Each script separately contains the invocation tag for sp.js.
Having the invocation tag appear in each script element before any calls to snowplow_name_here guarantees that the
asynchronous queue is set up before any calls to snowplow_name_here push events onto it (regardless of how long it
takes sp.js itself to load).
Even though the tag is fired twice, it is designed to only set up the asynchronous queue and load sp.js once.
See https://github.com/snowplow/snowplow-javascript-tracker/blob/master/tags/tag.js for a more detailed explanation of the tag.
-->
<script type="text/javascript" async=1>
;(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","//d1fc8wv8zag5ca.cloudfront.net/2.1.0/sp.js","snowplow_name_here"));
snowplow_name_here('trackPageView');
</script>
<script type="text/javascript" async=1>
;(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","//d1fc8wv8zag5ca.cloudfront.net/2.1.0/sp.js","snowplow_name_here"));
snowplow_name_here('trackStructEvent', 'clothing', 'add_to_basket', 'red hat');
</script>
<!--
Below is equivalent code for version 1.0.3 and earlier, using _snaq.
<script type="text/javascript" async=1>
window. _snaq = window._snaq || [];
_snaq.push(['trackPageView']);
(function() {
var sp = document.createElement('script'); sp.type = 'text/javascript'; sp.async = true; sp.defer = true;
sp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://d1fc8wv8zag5ca.cloudfront.net/0.13.0/sp.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sp, s);
})();
</script>
<script type="text/javascript" async=1>
window. _snaq = window._snaq || [];
_snaq.push(['trackStructEvent', 'clothing', 'add_to_basket', 'red hat']);
</script>
-->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment