Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion component.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"segmentio/json": "1.0.0",
"segmentio/protocol": "0.0.2",
"segmentio/top-domain": "1.0.0",
"segmentio/utm-params": "1.0.2",
"segmentio/utm-params": "1.1.0",
"yields/send-json": "1.1.1",
"yields/store": "1.0.2"
},
Expand Down
2 changes: 1 addition & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ Segment.prototype.normalize = function(msg) {
msg.writeKey = this.options.apiKey;
ctx.userAgent = navigator.userAgent;
if (!ctx.library) ctx.library = { name: 'analytics.js', version: this.analytics.VERSION };
if (query) ctx.campaign = utm(query);
if (query) ctx.campaign = utm.strict(query);
this.referrerId(query, ctx);
msg.userId = msg.userId || user.id();
msg.anonymousId = user.anonymousId();
Expand Down
18 changes: 18 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,24 @@ describe('Segment.io', function() {
Segment.global = window;
});

it('should add only specced fields to .campaign', function() {
Segment.global = { navigator: {}, location: {} };
Segment.global.location.search = '?utm_source=source&utm_medium=medium&utm_term=term&utm_content=content&utm_campaign=name&utm_test=test&utm_fake=fake';
Segment.global.location.hostname = 'localhost';
segment.normalize(object);
analytics.assert(object);
analytics.assert(object.context);
analytics.assert(object.context.campaign);
analytics.assert(object.context.campaign.source === 'source');
analytics.assert(object.context.campaign.medium === 'medium');
analytics.assert(object.context.campaign.term === 'term');
analytics.assert(object.context.campaign.content === 'content');
analytics.assert(object.context.campaign.name === 'name');
analytics.assert(object.context.campaign.test === undefined);
analytics.assert(object.context.campaign.fake === undefined);
Segment.global = window;
});

it('should add .referrer.id and .referrer.type', function() {
Segment.global = { navigator: {}, location: {} };
Segment.global.location.search = '?utm_source=source&urid=medium';
Expand Down