@segment/analytics.js-integration-segmentio
Advanced tools
Comparing version 3.8.0 to 3.8.1
3.8.1 / 2018-12-09 | ||
================== | ||
* [Fix](https://github.com/segment-integrations/analytics.js-integration-segmentio/pull/52): Don't send xid when cross domain analytics is disabled. | ||
3.8.0 / 2018-10-05 | ||
@@ -15,3 +20,3 @@ ================== | ||
* [Fix](https://github.com/segment-integrations/analytics.js-integration-segmentio/pull/47): Update localstorage-retry version with fix limiting the inProgress queue | ||
* [Fix](https://github.com/segment-integrations/analytics.js-integration-segmentio/pull/47): Update localstorage-retry version with fix limiting the inProgress queue | ||
@@ -18,0 +23,0 @@ 3.6.4 / 2018-11-07 |
@@ -185,3 +185,3 @@ 'use strict'; | ||
// separately | ||
if (this.options.crossDomainIdServers && this.options.crossDomainIdServers.length > 0) { | ||
if (this.isCrossDomainAnalyticsEnabled()) { | ||
this.retrieveCrossDomainId(); | ||
@@ -286,3 +286,3 @@ } | ||
var crossDomainId = this.cookie('seg_xid'); | ||
if (crossDomainId) { | ||
if (crossDomainId && this.isCrossDomainAnalyticsEnabled()) { | ||
if (!ctx.traits) { | ||
@@ -421,2 +421,16 @@ ctx.traits = { crossDomainId: crossDomainId }; | ||
/** | ||
* isCrossDomainAnalyticsEnabled returns true if cross domain analytics is enabled. | ||
* This field is not directly supplied, so it is inferred by inspecting the | ||
* `crossDomainIdServers` array in settings. If this array is null or empty, | ||
* it is assumed that cross domain analytics is disabled. | ||
* | ||
* @api private | ||
*/ | ||
Segment.prototype.isCrossDomainAnalyticsEnabled = function() { | ||
if (!this.options.crossDomainIdServers) { | ||
return false; | ||
} | ||
return this.options.crossDomainIdServers.length > 0; | ||
}; | ||
@@ -430,3 +444,3 @@ /** | ||
Segment.prototype.retrieveCrossDomainId = function(callback) { | ||
if (!this.options.crossDomainIdServers) { | ||
if (!this.isCrossDomainAnalyticsEnabled()) { | ||
if (callback) { | ||
@@ -433,0 +447,0 @@ callback('crossDomainId not enabled', null); |
{ | ||
"name": "@segment/analytics.js-integration-segmentio", | ||
"description": "The Segmentio analytics.js integration.", | ||
"version": "3.8.0", | ||
"version": "3.8.1", | ||
"keywords": [ | ||
@@ -6,0 +6,0 @@ "analytics.js", |
@@ -319,2 +319,54 @@ 'use strict'; | ||
it('should set xid if available, is enabled, and context.traits is not defined', function() { | ||
segment.cookie('seg_xid', 'test_id'); | ||
segment.options.crossDomainIdServers = [ | ||
'userdata.example1.com', | ||
'xid.domain2.com', | ||
'localhost' | ||
]; | ||
segment.normalize(object); | ||
assert.equal(object.context.traits.crossDomainId, 'test_id'); | ||
}); | ||
it('should set xid if available, is enabled, and context.traits is defined', function() { | ||
segment.cookie('seg_xid', 'test_id'); | ||
segment.options.crossDomainIdServers = [ | ||
'userdata.example1.com', | ||
'xid.domain2.com', | ||
'localhost' | ||
]; | ||
var msg = { context: { traits: { email: 'prateek@segment.com' } } }; | ||
segment.normalize(msg); | ||
assert.equal(msg.context.traits.crossDomainId, 'test_id'); | ||
}); | ||
it('should not set xid if available, and is disabled', function() { | ||
segment.cookie('seg_xid', 'test_id'); | ||
segment.options.crossDomainIdServers = []; | ||
segment.normalize(object); | ||
// context.traits will not be set, which implicitly verifies that | ||
// context.traits.crossDomainId is not set. | ||
assert.equal(object.context.traits, undefined); | ||
}); | ||
it('should not set xid if not available, and context.traits is not defined', function() { | ||
segment.cookie('seg_xid', null); | ||
segment.normalize(object); | ||
// context.traits will not be set, which implicitly verifies that | ||
// context.traits.crossDomainId is not set. | ||
assert.equal(object.context.traits, undefined); | ||
}); | ||
it('should not set xid if not available and context.traits is defined', function() { | ||
segment.cookie('seg_xid', null); | ||
var msg = { context: { traits: { email: 'prateek@segment.com' } } }; | ||
segment.normalize(msg); | ||
assert.equal(msg.context.traits.crossDomainId, undefined); | ||
}); | ||
describe('failed initializations', function() { | ||
@@ -399,5 +451,6 @@ it('should add failedInitializations as part of _metadata object if this.analytics.failedInitilizations is not empty', function() { | ||
for (var scenario in cases) { | ||
if (cases.hasOwnProperty(scenario)) { | ||
if (!cases.hasOwnProperty(scenario)) { | ||
continue; | ||
} | ||
describe('with ' + scenario, function() { | ||
@@ -1007,2 +1060,34 @@ beforeEach(function() { | ||
}); | ||
describe('isCrossDomainAnalyticsEnabled', function() { | ||
it('should return false when crossDomainIdServers is undefined', function() { | ||
segment.options.crossDomainIdServers = undefined; | ||
assert.equal(segment.isCrossDomainAnalyticsEnabled(), false); | ||
}); | ||
it('should return false when crossDomainIdServers is empty', function() { | ||
segment.options.crossDomainIdServers = []; | ||
assert.equal(segment.isCrossDomainAnalyticsEnabled(), false); | ||
}); | ||
it('should return true when crossDomainIdServers is set', function() { | ||
segment.options.crossDomainIdServers = [ | ||
'userdata.example1.com', | ||
'xid.domain2.com', | ||
'localhost' | ||
]; | ||
assert.equal(segment.isCrossDomainAnalyticsEnabled(), true); | ||
}); | ||
it('should return true even when crossDomainIdServers is set with 1 server', function() { | ||
segment.options.crossDomainIdServers = [ | ||
'localhost' | ||
]; | ||
assert.equal(segment.isCrossDomainAnalyticsEnabled(), true); | ||
}); | ||
}); | ||
}); | ||
@@ -1009,0 +1094,0 @@ }); |
75420
1705