Skip to content

Commit ce1f09e

Browse files
committed
The Snowplow function name is passed into out_queue.js to help with namespacing in localStorage (snowplow#24)
1 parent 8738af6 commit ce1f09e

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

src/js/in_queue.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
* after the Tracker has been initialized and loaded
4747
************************************************************/
4848

49-
object.InQueueManager = function(TrackerConstructor, version, mutSnowplowState, asyncQueue) {
49+
object.InQueueManager = function(TrackerConstructor, version, mutSnowplowState, asyncQueue, functionName) {
5050

5151
var trackerDictionary = {},
5252
usedCookieNames = {};
@@ -88,12 +88,12 @@
8888
* TODO: remove this in 2.1.0
8989
*/
9090
function legacyCreateNewNamespace(f, endpoint, namespace) {
91-
helpers.warn(f + ' is deprecated.'); //TODO: more instructions for switching
91+
helpers.warn(f + ' is deprecated. Set the collector when a new tracker instance using newTracker.');
9292

9393
var name;
9494

9595
if (lodash.isUndefined(namespace)) {
96-
name = 'sp'; // TODO: make default names work properly
96+
name = 'sp';
9797
} else {
9898
name = namespace;
9999
}
@@ -115,7 +115,7 @@
115115
} else {
116116
usedCookieNames[argmap.cookieName] = true;
117117
}
118-
trackerDictionary[namespace] = new TrackerConstructor(namespace, version, mutSnowplowState, argmap);
118+
trackerDictionary[namespace] = new TrackerConstructor(functionName, namespace, version, mutSnowplowState, argmap);
119119
trackerDictionary[namespace].setCollectorUrl(endpoint);
120120
}
121121

src/js/init.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ var snowplow = require('./snowplow'),
4646
if (windowAlias.GlobalSnowplowNamespace && windowAlias.GlobalSnowplowNamespace.length > 0) {
4747
queueName = windowAlias.GlobalSnowplowNamespace.shift();
4848
queue = windowAlias[queueName];
49-
queue.q = new snowplow.Snowplow(queue.q);
49+
queue.q = new snowplow.Snowplow(queue.q, queueName);
5050
} else {
5151
windowAlias._snaq = windowAlias._snaq || [];
52-
windowAlias._snaq = new snowplow.Snowplow(windowAlias._snaq);
52+
windowAlias._snaq = new snowplow.Snowplow(windowAlias._snaq, '_snaq');
5353
}

src/js/out_queue.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@
4040
localStorageAccessible = require('./lib/detectors').localStorageAccessible(),
4141
object = typeof exports !== 'undefined' ? exports : this; // For eventual node.js environment support
4242

43-
object.OutQueueManager = function(namespace) {
43+
object.OutQueueManager = function(functionName, namespace) {
4444

45-
var queueName = 'snowplowOutQueue_' + namespace,
45+
var queueName = ['snowplowOutQueue', functionName, namespace].join('_'),
4646
executingQueue = false,
4747
configCollectorUrl,
4848
outQueue;

src/js/snowplow.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282

8383
object = typeof exports !== 'undefined' ? exports : this; // For eventual node.js environment support
8484

85-
object.Snowplow = function(asynchronousQueue) {
85+
object.Snowplow = function(asynchronousQueue, functionName) {
8686

8787
var
8888
documentAlias = document,
@@ -203,7 +203,7 @@
203203
* @param string distSubdomain The subdomain on your CloudFront collector's distribution
204204
*/
205205
getTrackerCf: function (distSubdomain) {
206-
var t = new tracker.Tracker('', version, mutSnowplowState, {});
206+
var t = new tracker.Tracker(functionName, '', version, mutSnowplowState, {});
207207
t.setCollectorCf(distSubdomain);
208208
return t;
209209
},
@@ -215,7 +215,7 @@
215215
* @param string rawUrl The collector URL minus protocol and /i
216216
*/
217217
getTrackerUrl: function (rawUrl) {
218-
var t = new tracker.Tracker('', version, mutSnowplowState, {});
218+
var t = new tracker.Tracker(functionName, '', version, mutSnowplowState, {});
219219
t.setCollectorCf(rawUrl);
220220
return t;
221221
},
@@ -226,7 +226,7 @@
226226
* @return Tracker
227227
*/
228228
getAsyncTracker: function () {
229-
return new tracker.Tracker('', version, mutSnowplowState, {});
229+
return new tracker.Tracker(functionName, '', version, mutSnowplowState, {});
230230
}
231231
};
232232

@@ -239,7 +239,7 @@
239239
addReadyListener();
240240

241241
// Now replace initialization array with queue manager object
242-
return new queue.InQueueManager(tracker.Tracker, version, mutSnowplowState, asynchronousQueue);
242+
return new queue.InQueueManager(tracker.Tracker, version, mutSnowplowState, asynchronousQueue, functionName);
243243
}
244244

245245
}());

src/js/tracker.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
* 9. pageUnloadTimer, 500
7171
* 10. writeCookies, true
7272
*/
73-
object.Tracker = function Tracker(namespace, version, mutSnowplowState, argmap) {
73+
object.Tracker = function Tracker(functionName, namespace, version, mutSnowplowState, argmap) {
7474

7575
/************************************************************
7676
* Private members
@@ -213,7 +213,7 @@
213213
// Will be committed, sent and emptied by a call to trackTrans.
214214
ecommerceTransaction = ecommerceTransactionTemplate(),
215215

216-
outQueueManager = new requestQueue.OutQueueManager(namespace);
216+
outQueueManager = new requestQueue.OutQueueManager(functionName, namespace);
217217

218218
/*
219219
* Creates a JSON from the default header and a custom contexts array

0 commit comments

Comments
 (0)