Skip to content

Commit 016db35

Browse files
mjacquetchuwy
authored andcommitted
Add an option to change life of the visitor cookie, or disable, on tracker creation (close snowplow#504)
1 parent 7c4f9fc commit 016db35

1 file changed

Lines changed: 34 additions & 33 deletions

File tree

src/js/tracker.js

Lines changed: 34 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -8,27 +8,27 @@
88
* modification, are permitted provided that the following conditions are
99
* met:
1010
*
11-
* * Redistributions of source code must retain the above copyright
12-
* notice, this list of conditions and the following disclaimer.
11+
* * Redistributions of source code must retain the above copyright
12+
* notice, this list of conditions and the following disclaimer.
1313
*
14-
* * Redistributions in binary form must reproduce the above copyright
15-
* notice, this list of conditions and the following disclaimer in the
16-
* documentation and/or other materials provided with the distribution.
14+
* * Redistributions in binary form must reproduce the above copyright
15+
* notice, this list of conditions and the following disclaimer in the
16+
* documentation and/or other materials provided with the distribution.
1717
*
1818
* * Neither the name of Anthon Pang nor Snowplow Analytics Ltd nor the
1919
* names of their contributors may be used to endorse or promote products
20-
* derived from this software without specific prior written permission.
20+
* derived from this software without specific prior written permission.
2121
*
22-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23-
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24-
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25-
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26-
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27-
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28-
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29-
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30-
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31-
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
22+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
3232
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3333
*/
3434

@@ -80,6 +80,7 @@
8080
* 18. crossDomainLinker, false
8181
* 19. maxPostBytes, 40000
8282
* 20. discoverRootDomain, false
83+
* 21. cookieLifetime, 63072000
8384
*/
8485
object.Tracker = function Tracker(functionName, namespace, version, mutSnowplowState, argmap) {
8586

@@ -162,7 +163,7 @@
162163
configCountPreRendered,
163164

164165
// Life of the visitor cookie (in seconds)
165-
configVisitorCookieTimeout = 63072000, // 2 years
166+
configVisitorCookieTimeout = argmap.hasOwnProperty('cookieLifetime') ? argmap.cookieLifetime : 63072000, // 2 years
166167

167168
// Life of the session cookie (in seconds)
168169
configSessionCookieTimeout = argmap.hasOwnProperty('sessionCookieTimeout') ? argmap.sessionCookieTimeout : 1800, // 30 minutes
@@ -484,11 +485,11 @@
484485
*/
485486
function resetMaxScrolls() {
486487
var offsets = getPageOffsets();
487-
488+
488489
var x = offsets[0];
489490
minXOffset = x;
490491
maxXOffset = x;
491-
492+
492493
var y = offsets[1];
493494
minYOffset = y;
494495
maxYOffset = y;
@@ -499,7 +500,7 @@
499500
*/
500501
function updateMaxScrolls() {
501502
var offsets = getPageOffsets();
502-
503+
503504
var x = offsets[0];
504505
if (x < minXOffset) {
505506
minXOffset = x;
@@ -512,7 +513,7 @@
512513
minYOffset = y;
513514
} else if (y > maxYOffset) {
514515
maxYOffset = y;
515-
}
516+
}
516517
}
517518

518519
/*
@@ -1310,7 +1311,7 @@
13101311
* @param string total
13111312
* @param string tax
13121313
* @param string shipping
1313-
* @param string city
1314+
* @param string city
13141315
* @param string state
13151316
* @param string country
13161317
* @param string currency The currency the total/tax/shipping are expressed in
@@ -1343,7 +1344,7 @@
13431344
* E.g: (moz, hidden) -> mozHidden
13441345
*/
13451346
function prefixPropertyName(prefix, propertyName) {
1346-
1347+
13471348
if (prefix !== '') {
13481349
return prefix + propertyName.charAt(0).toUpperCase() + propertyName.slice(1);
13491350
}
@@ -1576,7 +1577,7 @@
15761577
* where tracking is:
15771578
* 1) Sending events to a collector
15781579
* 2) Setting first-party cookies
1579-
* @param bool enable If true and Do Not Track feature enabled, don't track.
1580+
* @param bool enable If true and Do Not Track feature enabled, don't track.
15801581
*/
15811582
respectDoNotTrack: function (enable) {
15821583
helpers.warn('This usage of respectDoNotTrack is deprecated. Instead add a "respectDoNotTrack" field to the argmap argument of newTracker.');
@@ -1619,7 +1620,7 @@
16191620
* be "_self", "_top", or "_parent").
16201621
*
16211622
* @see https://bugs.webkit.org/show_bug.cgi?id=54783
1622-
*
1623+
*
16231624
* @param object criterion Criterion by which it will be decided whether a link will be tracked
16241625
* @param bool pseudoClicks If true, use pseudo click-handler (mousedown+mouseup)
16251626
* @param bool trackContent Whether to track the innerHTML of the link element
@@ -1726,7 +1727,7 @@
17261727

17271728
/**
17281729
* Set the business-defined user ID for this user using the location querystring.
1729-
*
1730+
*
17301731
* @param string queryName Name of a querystring name-value pair
17311732
*/
17321733
setUserIdFromLocation: function(querystringField) {
@@ -1736,7 +1737,7 @@
17361737

17371738
/**
17381739
* Set the business-defined user ID for this user using the referrer querystring.
1739-
*
1740+
*
17401741
* @param string queryName Name of a querystring name-value pair
17411742
*/
17421743
setUserIdFromReferrer: function(querystringField) {
@@ -1746,15 +1747,15 @@
17461747

17471748
/**
17481749
* Set the business-defined user ID for this user to the value of a cookie.
1749-
*
1750+
*
17501751
* @param string cookieName Name of the cookie whose value will be assigned to businessUserId
17511752
*/
17521753
setUserIdFromCookie: function(cookieName) {
17531754
businessUserId = cookie.cookie(cookieName);
17541755
},
17551756

17561757
/**
1757-
* Configure this tracker to log to a CloudFront collector.
1758+
* Configure this tracker to log to a CloudFront collector.
17581759
*
17591760
* @param string distSubdomain The subdomain on your CloudFront collector's distribution
17601761
*/
@@ -1766,7 +1767,7 @@
17661767
*
17671768
* Specify the Snowplow collector URL. No need to include HTTP
17681769
* or HTTPS - we will add this.
1769-
*
1770+
*
17701771
* @param string rawUrl The collector URL minus protocol and /i
17711772
*/
17721773
setCollectorUrl: function (rawUrl) {
@@ -1976,7 +1977,7 @@
19761977
* Track an ad being served
19771978
*
19781979
* @param string impressionId Identifier for a particular ad impression
1979-
* @param string costModel The cost model. 'cpa', 'cpc', or 'cpm'
1980+
* @param string costModel The cost model. 'cpa', 'cpc', or 'cpm'
19801981
* @param number cost Cost
19811982
* @param string bannerId Identifier for the ad banner displayed
19821983
* @param string zoneId Identifier for the ad zone
@@ -1990,12 +1991,12 @@
19901991
core.trackAdImpression(impressionId, costModel, cost, targetUrl, bannerId, zoneId, advertiserId, campaignId, addCommonContexts(context), tstamp);
19911992
});
19921993
},
1993-
1994+
19941995
/**
19951996
* Track an ad being clicked
19961997
*
19971998
* @param string clickId Identifier for the ad click
1998-
* @param string costModel The cost model. 'cpa', 'cpc', or 'cpm'
1999+
* @param string costModel The cost model. 'cpa', 'cpc', or 'cpm'
19992000
* @param number cost Cost
20002001
* @param string targetUrl (required) The link's target URL
20012002
* @param string bannerId Identifier for the ad banner displayed

0 commit comments

Comments
 (0)