segment-integrations / analytics.js-integration-segmentio

The Segmentio analytics.js integration.
MIT License
8 stars 28 forks source link

Don't send xid when cross domain analytics is disabled. #52

Closed f2prateek closed 5 years ago

f2prateek commented 5 years ago

This adds an additional check in the normalize function to only attach the XID to events if cross domain analytics is enabled. The logic to determine if cross domain analytics is enabled is copied from an existing check - it is assumed to be disabled if no crossDomainIdServers were provided. This is also refactored into a shared function so we can avoid duplicating this logic.

Additionally this is written in a way that new check isCrossDomainAnalyticsEnabled() is only consulted if a xid cookie exists. This should prevent it from having unintended consequences on customers who have never used cross domain analytics.

Previously this check was skipped, and the xid would be sent as long as it exists in the cookie. To see this in action, you can go to any Segment source (without cross domain analytics enabled), create a cookie named seg_xid, and see that subsequent events from that site will send context.traits.crossDomainId in the event.

This code path was missing tests, so I added tests as well (there wasn't any test that needed to be updated).

f2prateek commented 5 years ago

Corresponding JIRA Ticket: https://segment.atlassian.net/browse/LIB-722

f2prateek commented 5 years ago

@fathyb yep! updated PR and commit to fix that