Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.

Commit 8da2fff

Browse files
committed
Added setter methods for version, namespace, app ID, and IP address (snowplow#242)
1 parent f7918e0 commit 8da2fff

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

core/lib/core.js

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,33 @@ function trackerCore(base64, callback) {
155155
payloadPairs = payload.isJson(dict) ? dict : {};
156156
},
157157

158+
/**
159+
* Set the tracker version
160+
*
161+
* @param string version
162+
*/
163+
setTrackerVersion: function (version) {
164+
addPayloadPair('tv', version)
165+
},
166+
167+
/**
168+
* Set the tracker namespace
169+
*
170+
* @param string name
171+
*/
172+
setTrackerNamespace: function (name) {
173+
addPayloadPair('tna', name);
174+
},
175+
176+
/**
177+
* Set the application ID
178+
*
179+
* @param string appId
180+
*/
181+
setAppId: function (appId) {
182+
addPayloadPair('aid', appId)
183+
},
184+
158185
/**
159186
* Set the platform
160187
*
@@ -220,6 +247,15 @@ function trackerCore(base64, callback) {
220247
addPayloadPair('lang', lang);
221248
},
222249

250+
/**
251+
* Set the IP address
252+
*
253+
* @param string appId
254+
*/
255+
setIpAddress: function (ip) {
256+
addPayloadPair('ip', ip)
257+
},
258+
223259
trackUnstructEvent: trackUnstructEvent,
224260

225261
/**

core/tests/core.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -378,24 +378,32 @@ define([
378378

379379
"Use setter methods": function () {
380380
var tracker = core(false);
381+
tracker.setTrackerVersion('js-3.0.0');
382+
tracker.setTrackerNamespace('cf1');
383+
tracker.setAppId('my-app');
381384
tracker.setPlatform('web');
382385
tracker.setUserId('jacob');
383386
tracker.setScreenResolution(400, 200);
384387
tracker.setViewport(500, 800);
385388
tracker.setColorDepth(24);
386389
tracker.setTimezone('Europe London');
390+
tracker.setIpAddress('37.151.33.154');
387391
var url = 'http://www.example.com';
388392
var page = 'title page';
389393
var expected = {
390394
e: 'pv',
391395
url: url,
392396
page: page,
397+
tna: 'cf1',
398+
tv: 'js-3.0.0',
399+
aid: 'my-app',
393400
p: 'web',
394401
uid: 'jacob',
395402
res: '400x200',
396403
vp: '500x800',
397404
cd: 24,
398-
tz: 'Europe London'
405+
tz: 'Europe London',
406+
ip: '37.151.33.154'
399407
};
400408

401409
compare(tracker.trackPageView(url, page), expected, 'setXXX methods should work correctly');

0 commit comments

Comments
 (0)