-
-
Save yalisassoon/4596577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Alias. Worth keeping in because it's so verbose. | |
var encodeWrapper = window.encodeURIComponent; | |
// This is the crust ol' code for building a request. | |
// Two things: | |
// 1. You won't be able to populate all of these | |
// 2. You will need to come up with some custom values - e.g. for tv (tracker version), maybe no-js-0.1.0 | |
// 3. Rather than this crusty code, you can build the whole thing up using requestStringBuilder, see below for code and example | |
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)) : ''); | |
/** | |
* 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 | |
*/ | |
function requestStringBuilder(initialValue) { | |
var str = initialValue || ''; | |
return { | |
add: function(key, value) { | |
if (value !== undefined && value !== '') { | |
str += '&' + key + '=' + encodeWrapper(value); | |
} | |
}, | |
build: function() { | |
return str; | |
} | |
} | |
} | |
// You won't need this, but it's an example of using requestStringBuilder() | |
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); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment