[Amplitude] Send Referrer Information Inside Integration #73
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
identifycall with that referrer information (this is that first Amplitude call that uses the default Amplitude-generated device ID)setDeviceIdto 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
trackReferreris 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
pageon their Segment enabled webpages.