Skip to content

Commit b77ea49

Browse files
miikePaul Boocock
authored andcommitted
Add function to allow setting Useragent (close #744)
1 parent fd6d93d commit b77ea49

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

core/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ coreInstance.setPlatform('web');
3333
coreInstance.setUserId('user-321');
3434
coreInstance.setColorDepth(24);
3535
coreInstance.setViewport(600, 400);
36+
coreInstance.setUseragent('Snowplow/0.0.1');
3637

3738
// Track a page view with URL and title
3839
var pageViewPayload = coreInstance.trackPageView('http://www.example.com', 'landing page');

core/lib/core.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,6 +336,15 @@ export function trackerCore(base64: boolean, callback?: (PayloadData) => void) {
336336
addPayloadPair('ip', ip);
337337
},
338338

339+
/**
340+
* Set the Useragent
341+
*
342+
* @param useragent string
343+
*/
344+
setUseragent: function (useragent: string) {
345+
addPayloadPair('ua', useragent);
346+
},
347+
339348
trackUnstructEvent: trackSelfDescribingEvent,
340349

341350
trackSelfDescribingEvent: trackSelfDescribingEvent,

core/tests/unit/core.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,6 +697,7 @@ define([
697697
tracker.setColorDepth(24);
698698
tracker.setTimezone('Europe London');
699699
tracker.setIpAddress('37.151.33.154');
700+
tracker.setUseragent('SnowplowJavascript/0.0.1');
700701
var url = 'http://www.example.com';
701702
var page = 'title page';
702703
var expected = {
@@ -712,7 +713,8 @@ define([
712713
vp: '500x800',
713714
cd: 24,
714715
tz: 'Europe London',
715-
ip: '37.151.33.154'
716+
ip: '37.151.33.154',
717+
ua: 'SnowplowJavascript/0.0.1'
716718
};
717719

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

0 commit comments

Comments
 (0)