Skip to content

Commit c7165be

Browse files
committed
Added console.warn function to helpers.js
1 parent 65ed59c commit c7165be

3 files changed

Lines changed: 23 additions & 24 deletions

File tree

src/js/in_queue.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636

3737
var
3838
lodash = require('./lib_managed/lodash'),
39-
39+
helpers = require('./lib/helpers'),
40+
4041
object = typeof exports !== 'undefined' ? exports : this; // For eventual node.js environment support
4142

4243
/************************************************************
@@ -64,7 +65,7 @@
6465
if (trackerDictionary.hasOwnProperty(names[i])) {
6566
namedTrackers.push(trackerDictionary[names[i]]);
6667
} else if (!lodash.isUndefined(console)) {
67-
console.log('Warning: Tracker namespace "' + names[i] + '" not configured');
68+
helpers.warn('Warning: Tracker namespace "' + names[i] + '" not configured');
6869
}
6970
}
7071
}
@@ -81,14 +82,12 @@
8182
* TODO: remove this in 2.1.0
8283
*/
8384
function legacyCreateNewNamespace(f, endpoint, namespace) {
84-
if (!lodash.isUndefined(console)) {
85-
console.log(f, 'is deprecated.'); //TODO: more instructions for switching
86-
}
85+
helpers.warn(f, 'is deprecated.'); //TODO: more instructions for switching
8786

8887
var name;
8988

9089
if (lodash.isUndefined(namespace)) {
91-
name = 'sp' // TODO: make default names work properly
90+
name = 'sp'; // TODO: make default names work properly
9291
} else {
9392
name = namespace;
9493
}

src/js/lib/helpers.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,4 +145,13 @@
145145
return decodeURIComponent(match[1].replace(/\+/g, ' '));
146146
}
147147

148+
/*
149+
* Only log deprecation warnings if they won't cause an error
150+
*/
151+
object.warn = function(message) {
152+
if (typeof console !== undefined) {
153+
console.warn('Snowplow: ' + message);
154+
}
155+
}
156+
148157
}());

src/js/tracker.js

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -202,15 +202,6 @@
202202

203203
outQueueManager = new requestQueue.OutQueueManager(namespace);
204204

205-
/*
206-
* Only log deprecation warnings if they won't cause an error
207-
*/
208-
function warn(message) {
209-
if (typeof console !== undefined) {
210-
console.log(message);
211-
}
212-
}
213-
214205
/*
215206
* Initializes an empty ecommerce
216207
* transaction and line items
@@ -1018,7 +1009,7 @@
10181009
* @param int|string appId
10191010
*/
10201011
setAppId: function (appId) {
1021-
warn('setAppId is deprecated. Instead add an "appId" field to the argmap argument of newTracker.');
1012+
helpers.warn('setAppId is deprecated. Instead add an "appId" field to the argmap argument of newTracker.');
10221013
configTrackerSiteId = appId;
10231014
},
10241015

@@ -1073,7 +1064,7 @@
10731064
* @param string cookieNamePrefix
10741065
*/
10751066
setCookieNamePrefix: function (cookieNamePrefix) {
1076-
warn('setCookieNamePrefix is deprecated. Instead add a "cookieName" field to the argmap argument of newTracker.');
1067+
helpers.warn('setCookieNamePrefix is deprecated. Instead add a "cookieName" field to the argmap argument of newTracker.');
10771068
configCookieNamePrefix = cookieNamePrefix;
10781069
},
10791070

@@ -1083,7 +1074,7 @@
10831074
* @param string domain
10841075
*/
10851076
setCookieDomain: function (domain) {
1086-
warn('setCookieDomain is deprecated. Instead add a "cookieDomain" field to the argmap argument of newTracker.');
1077+
helpers.warn('setCookieDomain is deprecated. Instead add a "cookieDomain" field to the argmap argument of newTracker.');
10871078
configCookieDomain = helpers.fixupDomain(domain);
10881079
updateDomainHash();
10891080
},
@@ -1120,7 +1111,7 @@
11201111
* @param number seed The seed used for MurmurHash3
11211112
*/
11221113
setUserFingerprintSeed: function(seed) {
1123-
warn('setUserFingerprintSeed is deprecated. Instead add a "userFingerprintSeed" field to the argmap argument of newTracker.');
1114+
helpers.warn('setUserFingerprintSeed is deprecated. Instead add a "userFingerprintSeed" field to the argmap argument of newTracker.');
11241115
configUserFingerprintHashSeed = seed;
11251116
userFingerprint = detectors.detectSignature(configUserFingerprintHashSeed);
11261117
},
@@ -1130,7 +1121,7 @@
11301121
* @param bool enable If false, turn off user fingerprinting
11311122
*/
11321123
enableUserFingerprint: function(enable) {
1133-
warn('enableUserFingerprintSeed is deprecated. Instead add a "userFingerprint" field to the argmap argument of newTracker.');
1124+
helpers.warn('enableUserFingerprintSeed is deprecated. Instead add a "userFingerprint" field to the argmap argument of newTracker.');
11341125
if (!enable) {
11351126
userFingerprint = '';
11361127
}
@@ -1144,7 +1135,7 @@
11441135
* @param bool enable If true and Do Not Track feature enabled, don't track.
11451136
*/
11461137
respectDoNotTrack: function (enable) {
1147-
warn('This usage of respectDoNotTrack is deprecated. Instead add a "respectDoNotTrack" field to the argmap argument of newTracker.');
1138+
helpers.warn('This usage of respectDoNotTrack is deprecated. Instead add a "respectDoNotTrack" field to the argmap argument of newTracker.');
11481139
var dnt = navigatorAlias.doNotTrack || navigatorAlias.msDoNotTrack;
11491140

11501141
configDoNotTrack = enable && (dnt === 'yes' || dnt === '1');
@@ -1307,7 +1298,7 @@
13071298
* @param string platform Overrides the default tracking platform
13081299
*/
13091300
setPlatform: function(platform) {
1310-
warn('setPlatform is deprecated. Instead add a "platform" field to the argmap argument of newTracker.');
1301+
helpers.warn('setPlatform is deprecated. Instead add a "platform" field to the argmap argument of newTracker.');
13111302
configPlatform = platform;
13121303
},
13131304

@@ -1318,7 +1309,7 @@
13181309
* @param boolean enabled A boolean value indicating if the Base64 encoding for unstructured events should be enabled or not
13191310
*/
13201311
encodeBase64: function (enabled) {
1321-
warn('This usage of encodeBase64 is deprecated. Instead add an "encodeBase64" field to the argmap argument of newTracker.');
1312+
helpers.warn('This usage of encodeBase64 is deprecated. Instead add an "encodeBase64" field to the argmap argument of newTracker.');
13221313
configEncodeBase64 = enabled;
13231314
},
13241315

@@ -1484,7 +1475,7 @@
14841475
* @param object Custom context relating to the event
14851476
*/
14861477
trackImpression: function (bannerId, campaignId, advertiserId, userId, context) {
1487-
warn('Snowplow: trackImpression is deprecated. When version 1.1.0 is released, switch to trackAdImpression.');
1478+
helpers.warn('Snowplow: trackImpression is deprecated. When version 1.1.0 is released, switch to trackAdImpression.');
14881479
logImpression(bannerId, campaignId, advertiserId, userId, context);
14891480
},
14901481

0 commit comments

Comments
 (0)