Skip to content

Instantly share code, notes, and snippets.

@alexanderdean
Last active December 11, 2015 11:48
Show Gist options
  • Save alexanderdean/4596562 to your computer and use it in GitHub Desktop.
Save alexanderdean/4596562 to your computer and use it in GitHub Desktop.
Excerpts for no-js-tracker.js
var encodeWrapper: windowAlias.encodeURIComponent;
/**
* A helper to build a SnowPlow request string from an
* an optional initial value plus a set of individual
* key-value pairs, provided using the add method.
*
* @param string initialValue The initial querystring, ready to have additional key-value pairs added
*
* @return object The request string builder, with add and build methods
*/
// TODO: add encode flag to add
// TODO: add addIf() function
function requestStringBuilder(initialValue) {
var str = initialValue || '';
return {
add: function(key, value) {
if (value !== undefined && value !== '') {
str += '&' + key + '=' + SnowPlow.encodeWrapper(value);
}
},
build: function() {
return str;
}
}
}
function logEvent(category, action, label, property, value) {
var sb = requestStringBuilder();
sb.add('e', 'ev'); // 'ev' for custom EVent
sb.add('ev_ca', category);
sb.add('ev_ac', action)
sb.add('ev_la', label);
sb.add('ev_pr', property);
sb.add('ev_va', value);
var params = sb.build();
request = getRequest(params, 'event');
sendRequest(request, configTrackerPause);
}
// Build a request
request +=
'&p=' + configPlatform +
'&tid=' + String(Math.random()).slice(2, 8) +
(configAttachUserId ? '&uid=' + uuid : '') +
'&fp=' + SnowPlow.encodeWrapper(fingerprint) +
'&vid=' + visitCount +
'&tv=' + SnowPlow.encodeWrapper(SnowPlow.version) +
(configTrackerSiteId.length ? '&aid=' + SnowPlow.encodeWrapper(configTrackerSiteId) : '') +
'&lang=' + browserLanguage +
(configReferrerUrl.length ? '&refr=' + SnowPlow.encodeWrapper(purify(configReferrerUrl)) : '');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment