Skip to content

Commit 299f01e

Browse files
Fix xid changing when navigating subdomains. (segmentio#469)
* fix subdomain xid cookies
1 parent 140006a commit 299f01e

File tree

3 files changed

+26
-27
lines changed

3 files changed

+26
-27
lines changed

integrations/segmentio/lib/index.js

+1-5
Original file line numberDiff line numberDiff line change
@@ -470,14 +470,10 @@ Segment.prototype.retrieveCrossDomainId = function(callback) {
470470
var self = this;
471471
var writeKey = this.options.apiKey;
472472

473-
// Exclude the current domain from the list of servers we're querying
474-
var currentTld = getTld(window.location.hostname);
475473
var domains = [];
476474
for (var i = 0; i < this.options.crossDomainIdServers.length; i++) {
477475
var domain = this.options.crossDomainIdServers[i];
478-
if (getTld(domain) !== currentTld) {
479-
domains.push(domain);
480-
}
476+
domains.push(domain);
481477
}
482478

483479
getCrossDomainIdFromServerList(domains, writeKey, function(err, res) {

integrations/segmentio/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "@segment/analytics.js-integration-segmentio",
33
"description": "The Segmentio analytics.js integration.",
4-
"version": "4.2.3",
4+
"version": "4.2.5",
55
"keywords": [
66
"analytics.js",
77
"analytics.js-integration",

integrations/segmentio/test/index.test.js

+24-21
Original file line numberDiff line numberDiff line change
@@ -1117,26 +1117,6 @@ describe('Segment.io', function() {
11171117
}
11181118

11191119
describe('with ' + scenario, function() {
1120-
it('should generate xid locally if there is only one (current hostname) server', function() {
1121-
segment.options.crossDomainIdServers = ['localhost'];
1122-
segment.options.saveCrossDomainIdInLocalStorage =
1123-
cases[scenario];
1124-
1125-
var res = null;
1126-
segment.retrieveCrossDomainId(function(err, response) {
1127-
res = response;
1128-
});
1129-
1130-
var identify = segment.onidentify.args[0];
1131-
var crossDomainId = identify[0].traits().crossDomainId;
1132-
analytics.assert(crossDomainId);
1133-
1134-
analytics.assert(res.crossDomainId === crossDomainId);
1135-
analytics.assert(res.fromDomain === 'localhost');
1136-
1137-
assert.equal(segment.getCachedCrossDomainId(), crossDomainId);
1138-
});
1139-
11401120
it('should obtain crossDomainId', function() {
11411121
server.respondWith(
11421122
'GET',
@@ -1194,6 +1174,15 @@ describe('Segment.io', function() {
11941174
'{ "id": null }'
11951175
]
11961176
);
1177+
server.respondWith(
1178+
'GET',
1179+
'https://localhost/v1/id/' + segment.options.apiKey,
1180+
[
1181+
200,
1182+
{ 'Content-Type': 'application/json' },
1183+
'{ "id": null }'
1184+
]
1185+
);
11971186
if (segment.options.saveCrossDomainIdInLocalStorage) {
11981187
server.respondWith('GET', /https:\/\/localhost\/v1\/saveId/, [
11991188
200,
@@ -1237,12 +1226,17 @@ describe('Segment.io', function() {
12371226
segment.options.apiKey,
12381227
[500, { 'Content-Type': 'application/json' }, '']
12391228
);
1229+
server.respondWith(
1230+
'GET',
1231+
'https://localhost/v1/id/' + segment.options.apiKey,
1232+
[500, { 'Content-Type': 'application/json' }, '']
1233+
);
12401234
server.respond();
12411235

12421236
var identify = segment.onidentify.args[0];
12431237
analytics.assert(!identify);
12441238
analytics.assert(!res);
1245-
analytics.assert(err === 'Internal Server Error');
1239+
analytics.assert.equal(err, 'Internal Server Error');
12461240

12471241
assert.equal(segment.getCachedCrossDomainId(), null);
12481242
});
@@ -1270,6 +1264,15 @@ describe('Segment.io', function() {
12701264
'{ "id": null }'
12711265
]
12721266
);
1267+
server.respondWith(
1268+
'GET',
1269+
'https://localhost/v1/id/' + segment.options.apiKey,
1270+
[
1271+
200,
1272+
{ 'Content-Type': 'application/json' },
1273+
'{ "id": null }'
1274+
]
1275+
);
12731276
server.respond();
12741277

12751278
var identify = segment.onidentify.args[0];

0 commit comments

Comments
 (0)