Skip to content

Instantly share code, notes, and snippets.

@fblundun
fblundun / cookie_update.js
Last active August 29, 2015 14:10
Cookie transformation snippet
@fblundun
fblundun / duid.js
Last active August 29, 2015 14:07
Extracting the user ID from the first-party Snowplow cookie
/*
* Function to extract the Snowplow user ID from the first-party cookie set by the Snowplow JavaScript Tracker
*
* @param string cookieName (optional) The value used for "cookieName" in the tracker constructor argmap
* (leave blank if you did not set a custom cookie name)
*
* @return string or bool The ID string if the cookie exists or false if the cookie has not been set yet
*/
function getSnowplowDuid(cookieName) {
cookieName = cookieName || '_sp_';
@fblundun
fblundun / invocation-tag-example-2.0.0.html
Last active August 29, 2015 14:05
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.
-->
@fblundun
fblundun / struct-event-example.js
Last active August 29, 2015 14:04
Structured event with contexts
// A structured event corresponding to playing some music with no context attached
window.snowplow_name_here('trackStructEvent', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0');
// The same unstructured event, with two custom contexts attached -
// one regarding the page background and one regarding the user type
window.snowplow_name_here('trackStructEvent', 'Mixes', 'Play', 'MRC/fabric-0503-mix', '', '0.0', [
{
schema: "iglu:com.mycompany/page_style/jsonschema/1-0-0",
data: {
background_color: "white",
@fblundun
fblundun / unstruct-event-example.js
Last active August 29, 2015 14:04
Unstructured event with contexts
// An unstructured event with no context attached
window.snowplow_name_here('trackUnstructEvent', {
schema: 'iglu:com.acme_company/viewed_product/jsonschema/2-0-0',
data: {
productId: 'ASO01043',
category: 'Dresses',
brand: 'ACME',
returning: true,
price: 49.95,
sizes: ['xs', 's', 'l', 'xl', 'xxl'],