diff --git a/lib/index.js b/lib/index.js index a823074..42a24c1 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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 diff --git a/test/index.test.js b/test/index.test.js index 81d4e7b..c26e6a5 100644 --- a/test/index.test.js +++ b/test/index.test.js @@ -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];