-
Notifications
You must be signed in to change notification settings - Fork 140
[Amplitude] Send Referrer Information Inside Integration #73
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,7 +69,6 @@ Amplitude.prototype.initialize = function() { | |
|
|
||
| window.amplitude.getInstance().init(this.options.apiKey, null, { | ||
| includeUtm: this.options.trackUtmProperties, | ||
| includeReferrer: this.options.trackReferrer, | ||
| batchEvents: this.options.batchEvents, | ||
| eventUploadThreshold: this.options.eventUploadThreshold, | ||
| eventUploadPeriodMillis: this.options.eventUploadPeriodMillis, | ||
|
|
@@ -126,6 +125,8 @@ Amplitude.prototype.loaded = function() { | |
| Amplitude.prototype.page = function(page) { | ||
| this.setDeviceIdFromAnonymousId(page); | ||
|
|
||
| if (this.options.trackReferrer) this.sendReferrer(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note this occurs right after |
||
|
|
||
| var category = page.category(); | ||
| var name = page.fullName(); | ||
| var opts = this.options; | ||
|
|
@@ -392,6 +393,31 @@ Amplitude.prototype.setRevenue = function(properties) { | |
| } | ||
| }; | ||
|
|
||
| // equivalent of sending includeReferrer=true in the amplitude config object when we initialize | ||
| Amplitude.prototype.sendReferrer = function() { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
| var identify = new window.amplitude.Identify(); | ||
|
|
||
| var referrer = this.getReferrer(); | ||
| if (!referrer || referrer.length === 0) return; | ||
|
|
||
| identify.setOnce('initial_referrer', referrer); | ||
| identify.set('referrer', referrer); | ||
|
|
||
| var parts = referrer.split('/'); | ||
| if (parts.length >= 3) { | ||
| var referring_domain = parts[2]; | ||
| identify.setOnce('initial_referring_domain', referring_domain); | ||
| identify.set('referring_domain', referring_domain); | ||
| } | ||
|
|
||
| window.amplitude.getInstance().identify(identify); | ||
| }; | ||
|
|
||
| // wrapper for testing purposes | ||
| Amplitude.prototype.getReferrer = function() { | ||
| return document.referrer; | ||
| }; | ||
|
|
||
| function mapRevenueAttributes(track) { | ||
| // Revenue type can be anything such as Refund, Tax, etc. | ||
| // Using mapper here to support future ecomm event => revenue mappings (Order Refund, etc.) | ||
|
|
||
There was a problem hiding this comment.
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