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

Fixes error that occurs when local storage is enabled. #62

Merged
merged 3 commits into from
Aug 8, 2019
Merged
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
14 changes: 8 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,12 +275,14 @@ 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 };
var crossDomainId = this.getCachedCrossDomainId();
if (crossDomainId && this.isCrossDomainAnalyticsEnabled()) {
if (!ctx.traits) {
ctx.traits = { crossDomainId: crossDomainId };
} else if (!ctx.traits.crossDomainId) {
ctx.traits.crossDomainId = crossDomainId;
if (this.isCrossDomainAnalyticsEnabled()) {
var crossDomainId = this.getCachedCrossDomainId();
if (crossDomainId) {
if (!ctx.traits) {
ctx.traits = { crossDomainId: crossDomainId };
} else if (!ctx.traits.crossDomainId) {
ctx.traits.crossDomainId = crossDomainId;
}
}
}
// if user provides campaign via context, do not overwrite with UTM qs param
Expand Down
8 changes: 8 additions & 0 deletions test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -505,6 +505,14 @@ describe('Segment.io', function() {
analytics.stub(segment, 'enqueue');
});

it('identify should not ultimately call getCachedCrossDomainId if crossDomainAnalytics is not enabled', function() {
segment.options.crossDomainIdServers = [];
var getCachedCrossDomainIdSpy = sinon.spy(segment, 'getCachedCrossDomainId');
segment.normalize({});
sinon.assert.notCalled(getCachedCrossDomainIdSpy);
segment.getCachedCrossDomainId.restore();
});

it('should enqueue an id and traits', function() {
analytics.identify('id', { trait: true }, { opt: true });
var args = segment.enqueue.args[0];
Expand Down