Skip to content

Commit e2deb0e

Browse files
fblundunalexanderdean
authored andcommitted
Added setUserIdFromReferrer and setUserIdFromLocation (snowplow#57)
1 parent e3ac68b commit e2deb0e

5 files changed

Lines changed: 41 additions & 8 deletions

File tree

CHANGELOG

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ Renamed requestStringBuilder to payloadBuilder and moved it into its own file, p
66
Introduced gzipped sp.js library (#48)
77
Updated grunt and intern dependencies (#54)
88
Replaced snowpak.sh with Grunt and grunt-yui-compressor (#53)
9-
Added setUserIdFromReferer('oaid') (#57) (TODO)
10-
Added ability to pass a referer to Snowplow from an IFRAME (#1) (TODO)
9+
Added setUserIdFromReferrer and setUserIdFromLocation (#57)
10+
Added ability to pass a referrer to Snowplow from an IFRAME (#1) (TODO)
1111
Added user fingerprinting on/off switch and configurable hash seed (#7) (TODO)
1212

1313
Version 0.13.1 (2014-01-28)

examples/web/async.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323

2424
_snaq.push(['setCollectorCf', 'd3rkrsqld9gmqf']); // Update to your CloudFront distribution subdomain
2525
_snaq.push(['setAppId', 'CFe23a']); // Site ID can be anything you want. Set it if you're tracking more than one site in this account
26-
_snaq.push(['setUserId', 'alex 123']); // Business-defined user ID
27-
// Deprecated _snaq.push(['attachUserId', false]); // Don't attach &uid=xxx to the querystring
26+
//_snaq.push(['setUserId', 'alex 123']); // Business-defined user ID
27+
//_snaq.push(['setUserIdFromLocation', 'id']); // To test this, reload the page with ?id=xxx
2828
_snaq.push(['setCustomUrl', '/overridden-url/']); // Override the page URL
2929
_snaq.push(['enableActivityTracking', 10, 10]); // Ping every 10 seconds after 10 seconds
3030
_snaq.push(['enableLinkTracking']);
@@ -45,7 +45,7 @@
4545
(function() {
4646
var sp = document.createElement('script'); sp.type = 'text/javascript'; sp.async = true; sp.defer = true;
4747
//sp.src = ('https:' == document.location.protocol ? 'https' : 'http') + '://d1fc8wv8zag5ca.cloudfront.net/0.13.0/sp.js';
48-
sp.src = '../../dist/sp.js'; // For testing
48+
sp.src = '../../dist/sp.nogz.js'; // For testing
4949
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(sp, s);
5050
})();
5151
</script>

examples/web/sync.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- Snowplow starts plowing -->
2121
<script type="text/javascript">
2222
//var spSrc = ('https:' == document.location.protocol ? 'https' : 'http') + '://d1fc8wv8zag5ca.cloudfront.net/0.13.0/sp.js';
23-
var spSrc = '../../dist/sp.js'; // For testing
23+
var spSrc = '../../dist/sp.nogz.js'; // For testing
2424
document.write(unescape("%3Cscript src='" + spSrc + "' type='text/javascript'%3E%3C/script%3E"));
2525
</script>
2626
<script type="text/javascript">

src/js/helpers.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,3 +324,10 @@ SnowPlow.executePluginMethod = function (methodName, callback) {
324324
return result;
325325
}
326326

327+
SnowPlow.fromQuerystring = function (field, url) {
328+
var match = RegExp('[?&]' + field + '=([^&]*)').exec(url);
329+
if (!match) {
330+
return null;
331+
}
332+
return SnowPlow.decodeWrapper(match[1].replace(/\+/g, ' '));
333+
}

src/js/tracker.js

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,11 @@ SnowPlow.Tracker = function Tracker(argmap) {
5252
************************************************************/
5353

5454
var
55+
// Get the referrer URL
56+
referrer = SnowPlow.getReferrer(),
57+
5558
// Current URL and Referrer URL
56-
locationArray = SnowPlow.fixupUrl(SnowPlow.documentAlias.domain, SnowPlow.windowAlias.location.href, SnowPlow.getReferrer()),
59+
locationArray = SnowPlow.fixupUrl(SnowPlow.documentAlias.domain, SnowPlow.windowAlias.location.href, referrer),
5760
domainAlias = SnowPlow.fixupDomain(locationArray[0]),
5861
locationHrefAlias = locationArray[1],
5962
configReferrerUrl = locationArray[2],
@@ -1545,6 +1548,29 @@ SnowPlow.Tracker = function Tracker(argmap) {
15451548
businessUserId = userId;
15461549
},
15471550

1551+
/**
1552+
* Set the business-defined user ID for this user using the location querystring.
1553+
*
1554+
* @param string queryName Name of a querystring name-value pair
1555+
*/
1556+
1557+
setUserIdFromLocation: function(queryName) {
1558+
1559+
var location = document.URL;
1560+
businessUserId = SnowPlow.fromQuerystring(queryName, location);
1561+
},
1562+
1563+
/**
1564+
* Set the business-defined user ID for this user using the referrer querystring.
1565+
*
1566+
* @param string queryName Name of a querystring name-value pair
1567+
*/
1568+
1569+
setUserIdFromReferrer: function(queryName) {
1570+
1571+
businessUserId = SnowPlow.fromQuerystring(queryName, referrer);
1572+
},
1573+
15481574
/**
15491575
* Toggle whether to attach User ID to the querystring or not
15501576
*
@@ -1553,7 +1579,7 @@ SnowPlow.Tracker = function Tracker(argmap) {
15531579
* cookie). So there's no need to enable or disable specific user IDs.
15541580
*
15551581
* @param bool attach Whether to attach User ID or not
1556-
*/
1582+
*/
15571583
attachUserId: function (attach) {
15581584

15591585
if (typeof console !== 'undefined') {

0 commit comments

Comments
 (0)