Skip to content

Conversation

@jlee9595
Copy link
Contributor

@jlee9595 jlee9595 commented Oct 5, 2018

Customers have been writing in saying that they’ve been seeing inconsistent Amplitude ‘device id’s attached to their events when using the setting ‘Prefer Anonymous ID for Device ID’. While they would expect to see their Segment anonymous IDs as the attached device ID for all events sent to Amplitude via Segment, they’re seeing the first event going to Amplitude using the default Amplitude-generated value, while all subsequent calls use the anonymous ID as expected. This is only happening when the page is opened via a referrer like Google and in all other cases the integration behaves as it should.

It turns out that all those customers were also using the setting ‘Track Referrer’, which is just a proxy setting for us to know whether or not to pass Amplitude their native setting ‘includeReferrer’, a boolean indicating whether or not to send Amplitude referrer information when the page loads. What happens when both this setting and ‘Prefer Anonymous ID for Device ID’ are enabled is as follows.

  1. Segment loads on page, initializes Amplitude integration which in turn initializes Amplitude instance
  2. Upon reading ‘includeReferrer’ as true, the Amplitude instance fires a native Amplitude identify call with that referrer information (this is that first Amplitude call that uses the default Amplitude-generated device ID)
  3. Customer calls a Segment method (track, page, identify, etc), which in turn fires the Amplitude setDeviceId to switch the device ID to the Segment anonymous ID. All subsequent calls will now use the Segment anonymous ID.

To summarize, the inconsistency is stemming from the fact that Amplitude fires a tracking call with referrer information as part of their initialize logic when trackReferrer is switched on, but we don’t change device ID to anonymous ID until after initialization, causing the first Amplitude call to send with the default Amplitude device ID while all other Amplitude calls send with the Segment anonymous ID as the device ID.

This PR solves this issue by sending the referrer information ourselves instead of delegating that responsibility to the Amplitude initialization logic via a configuration option. This way we can make sure we're sending this information after the device ID is changed to anonymous ID.

Note: This is a breaking change for any customers that don't fire page on their Segment enabled webpages.

@jlee9595 jlee9595 requested a review from a team October 5, 2018 01:33
@jlee9595 jlee9595 changed the title Send Referrer Information Inside Integration [Amplitude] Send Referrer Information Inside Integration Oct 5, 2018
};

// equivalent of sending includeReferrer=true in the amplitude config object when we initialize
Amplitude.prototype.sendReferrer = function() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This aims to capture the exact same logic as the native Amplitude logic here


window.amplitude.getInstance().init(this.options.apiKey, null, {
includeUtm: this.options.trackUtmProperties,
includeReferrer: this.options.trackReferrer,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This tells Amplitude never to send the referrer information themselves

Amplitude.prototype.page = function(page) {
this.setDeviceIdFromAnonymousId(page);

if (this.options.trackReferrer) this.sendReferrer();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note this occurs right after setDeviceIdFromAnonymousId so that the correct DeviceId is used.

@jlee9595 jlee9595 merged commit 3cf3434 into master Oct 8, 2018
@jlee9595 jlee9595 deleted the referrer branch October 8, 2018 20:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants