Skip to content

Instantly share code, notes, and snippets.

@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'],
@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 / 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 / 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 / cookie_update.js
Last active August 29, 2015 14:10
Cookie transformation snippet
@fblundun
fblundun / clones.js
Last active August 29, 2015 14:14
safari-tools
/**
* @license
* Lo-Dash 2.4.1 (Custom Build) <http://lodash.com/>
* Build: `lodash exports="node" include="isArray, isFunction, isString, isObject, isDate, isUndefined, isNull, map, filter, find, compact, isEmpty, clone, cloneDeep" --debug --output src/js/lib_managed/lodash.js`
* Copyright 2012-2013 The Dojo Foundation <http://dojofoundation.org/>
* Based on Underscore.js 1.5.2 <http://underscorejs.org/LICENSE>
* Copyright 2009-2013 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
* Available under MIT license <http://lodash.com/license>
*/
;(function() {
@fblundun
fblundun / incomplete.rb
Last active August 29, 2015 14:25
List Github issues not addressed in a branch
require 'octokit'
page = 1
issues = []
while true do
current_page = Octokit.list_issues('snowplow/snowplow', {milestone: 78, state: 'open',page: page}).map {|x| x.to_hash()};
if current_page.empty?
break
end
issues += current_page
@fblundun
fblundun / AvroUtils.scala
Created September 16, 2015 14:51
Examples of using Avro to write to and read from files and in-memory streams
import org.apache.avro.io._
import org.apache.avro.specific._
import org.apache.avro.file.DataFileWriter
import java.util.ArrayList
import java.io.File
import example.avro._
import org.apache.avro.Schema
import org.apache.avro.generic._
import org.apache.avro.file.DataFileReader
import org.apache.avro.util.ByteBufferOutputStream
@fblundun
fblundun / fix_copyright.sh
Created September 29, 2015 11:19
Script to update Snowplow copyright notices
@fblundun
fblundun / enhancedecommerce.html
Last active October 21, 2015 12:14
Enhanced Ecommerce tag
<script>
// If this tag fires more than once (e.g. page view followed by ecommerce action),
// we don't want to repeat the trackPageView here
if (!window.snowplow) {
;(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.5.2/sp.js","snowplow"));