From 0c777a0dbe81501147f61333ada05641e8c4163e Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Fri, 1 May 2020 14:13:48 -0700 Subject: [PATCH 1/6] fix subdomain xid cookies --- integrations/segmentio/lib/index.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index d701199f4..d50d5667d 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -470,14 +470,10 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { var self = this; var writeKey = this.options.apiKey; - // Exclude the current domain from the list of servers we're querying - var currentTld = getTld(window.location.hostname); var domains = []; for (var i = 0; i < this.options.crossDomainIdServers.length; i++) { var domain = this.options.crossDomainIdServers[i]; - if (getTld(domain) !== currentTld) { - domains.push(domain); - } + domains.push(domain); } getCrossDomainIdFromServerList(domains, writeKey, function(err, res) { From 60596bba11f568b85bca532219ba622687ae72a5 Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Mon, 4 May 2020 10:08:56 -0700 Subject: [PATCH 2/6] update version --- integrations/segmentio/package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/integrations/segmentio/package.json b/integrations/segmentio/package.json index 098ad42fa..207487fce 100644 --- a/integrations/segmentio/package.json +++ b/integrations/segmentio/package.json @@ -1,7 +1,7 @@ { "name": "@segment/analytics.js-integration-segmentio", "description": "The Segmentio analytics.js integration.", - "version": "4.2.3", + "version": "4.2.5", "keywords": [ "analytics.js", "analytics.js-integration", From fdaf58bca9480e5000bdaf9827bb9ddb4420cd1e Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Mon, 4 May 2020 10:43:51 -0700 Subject: [PATCH 3/6] update fix --- integrations/segmentio/lib/index.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index d50d5667d..97fe707bd 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -470,10 +470,14 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { var self = this; var writeKey = this.options.apiKey; + // Exclude the current domain from the list of servers we're querying + var currentTld = getTld(window.location.hostname); var domains = []; for (var i = 0; i < this.options.crossDomainIdServers.length; i++) { var domain = this.options.crossDomainIdServers[i]; - domains.push(domain); + if (getTld(domain) !== currentTld) { + domains.push(domain); + } } getCrossDomainIdFromServerList(domains, writeKey, function(err, res) { @@ -521,7 +525,9 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { */ Segment.prototype.getCachedCrossDomainId = function() { if (this.options.saveCrossDomainIdInLocalStorage) { - return localstorage('seg_xid'); + if (localstorage('seg_xid') !== null) { + return localstorage('seg_xid'); + } } return this.cookie('seg_xid'); }; From cd66d66c81a3fee2e5217eeb371ef3be36df45b0 Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Wed, 6 May 2020 11:33:22 -0700 Subject: [PATCH 4/6] update --- integrations/segmentio/lib/index.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index 97fe707bd..380666d75 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -471,13 +471,14 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { var writeKey = this.options.apiKey; // Exclude the current domain from the list of servers we're querying - var currentTld = getTld(window.location.hostname); + // var currentTld = getTld(window.location.hostname); var domains = []; for (var i = 0; i < this.options.crossDomainIdServers.length; i++) { var domain = this.options.crossDomainIdServers[i]; - if (getTld(domain) !== currentTld) { - domains.push(domain); - } + domains.push(domain); + // if (getTld(domain) !== currentTld) { + // domains.push(domain); + // } } getCrossDomainIdFromServerList(domains, writeKey, function(err, res) { @@ -525,9 +526,7 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { */ Segment.prototype.getCachedCrossDomainId = function() { if (this.options.saveCrossDomainIdInLocalStorage) { - if (localstorage('seg_xid') !== null) { - return localstorage('seg_xid'); - } + return localstorage('seg_xid'); } return this.cookie('seg_xid'); }; From 5e56b450ecdd745e7a5ef7712bc3547adeaae798 Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Wed, 6 May 2020 12:23:29 -0700 Subject: [PATCH 5/6] fix up unit tests --- integrations/segmentio/test/index.test.js | 45 ++++++++++++----------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/integrations/segmentio/test/index.test.js b/integrations/segmentio/test/index.test.js index 6c66bfeae..e3e898228 100644 --- a/integrations/segmentio/test/index.test.js +++ b/integrations/segmentio/test/index.test.js @@ -1117,26 +1117,6 @@ describe('Segment.io', function() { } describe('with ' + scenario, function() { - it('should generate xid locally if there is only one (current hostname) server', function() { - segment.options.crossDomainIdServers = ['localhost']; - segment.options.saveCrossDomainIdInLocalStorage = - cases[scenario]; - - var res = null; - segment.retrieveCrossDomainId(function(err, response) { - res = response; - }); - - var identify = segment.onidentify.args[0]; - var crossDomainId = identify[0].traits().crossDomainId; - analytics.assert(crossDomainId); - - analytics.assert(res.crossDomainId === crossDomainId); - analytics.assert(res.fromDomain === 'localhost'); - - assert.equal(segment.getCachedCrossDomainId(), crossDomainId); - }); - it('should obtain crossDomainId', function() { server.respondWith( 'GET', @@ -1194,6 +1174,15 @@ describe('Segment.io', function() { '{ "id": null }' ] ); + server.respondWith( + 'GET', + 'https://localhost/v1/id/' + segment.options.apiKey, + [ + 200, + { 'Content-Type': 'application/json' }, + '{ "id": null }' + ] + ); if (segment.options.saveCrossDomainIdInLocalStorage) { server.respondWith('GET', /https:\/\/localhost\/v1\/saveId/, [ 200, @@ -1237,12 +1226,17 @@ describe('Segment.io', function() { segment.options.apiKey, [500, { 'Content-Type': 'application/json' }, ''] ); + server.respondWith( + 'GET', + 'https://localhost/v1/id/' + segment.options.apiKey, + [500, { 'Content-Type': 'application/json' }, ''] + ); server.respond(); var identify = segment.onidentify.args[0]; analytics.assert(!identify); analytics.assert(!res); - analytics.assert(err === 'Internal Server Error'); + analytics.assert.equal(err, 'Internal Server Error'); assert.equal(segment.getCachedCrossDomainId(), null); }); @@ -1270,6 +1264,15 @@ describe('Segment.io', function() { '{ "id": null }' ] ); + server.respondWith( + 'GET', + 'https://localhost/v1/id/' + segment.options.apiKey, + [ + 200, + { 'Content-Type': 'application/json' }, + '{ "id": null }' + ] + ); server.respond(); var identify = segment.onidentify.args[0]; From a6a9d5f9fbbb38b51e1928d03e33b4e6f40c42f9 Mon Sep 17 00:00:00 2001 From: Daniel Jackins Date: Wed, 6 May 2020 12:25:26 -0700 Subject: [PATCH 6/6] remove outdated comments --- integrations/segmentio/lib/index.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/integrations/segmentio/lib/index.js b/integrations/segmentio/lib/index.js index 380666d75..d50d5667d 100644 --- a/integrations/segmentio/lib/index.js +++ b/integrations/segmentio/lib/index.js @@ -470,15 +470,10 @@ Segment.prototype.retrieveCrossDomainId = function(callback) { var self = this; var writeKey = this.options.apiKey; - // Exclude the current domain from the list of servers we're querying - // var currentTld = getTld(window.location.hostname); var domains = []; for (var i = 0; i < this.options.crossDomainIdServers.length; i++) { var domain = this.options.crossDomainIdServers[i]; domains.push(domain); - // if (getTld(domain) !== currentTld) { - // domains.push(domain); - // } } getCrossDomainIdFromServerList(domains, writeKey, function(err, res) {