@@ -69,7 +69,6 @@ Amplitude.prototype.initialize = function() {
6969
7070 window . amplitude . getInstance ( ) . init ( this . options . apiKey , null , {
7171 includeUtm : this . options . trackUtmProperties ,
72- includeReferrer : this . options . trackReferrer ,
7372 batchEvents : this . options . batchEvents ,
7473 eventUploadThreshold : this . options . eventUploadThreshold ,
7574 eventUploadPeriodMillis : this . options . eventUploadPeriodMillis ,
@@ -126,6 +125,8 @@ Amplitude.prototype.loaded = function() {
126125Amplitude . prototype . page = function ( page ) {
127126 this . setDeviceIdFromAnonymousId ( page ) ;
128127
128+ if ( this . options . trackReferrer ) this . sendReferrer ( ) ;
129+
129130 var category = page . category ( ) ;
130131 var name = page . fullName ( ) ;
131132 var opts = this . options ;
@@ -392,6 +393,31 @@ Amplitude.prototype.setRevenue = function(properties) {
392393 }
393394} ;
394395
396+ // equivalent of sending includeReferrer=true in the amplitude config object when we initialize
397+ Amplitude . prototype . sendReferrer = function ( ) {
398+ var identify = new window . amplitude . Identify ( ) ;
399+
400+ var referrer = this . getReferrer ( ) ;
401+ if ( ! referrer || referrer . length === 0 ) return ;
402+
403+ identify . setOnce ( 'initial_referrer' , referrer ) ;
404+ identify . set ( 'referrer' , referrer ) ;
405+
406+ var parts = referrer . split ( '/' ) ;
407+ if ( parts . length >= 3 ) {
408+ var referring_domain = parts [ 2 ] ;
409+ identify . setOnce ( 'initial_referring_domain' , referring_domain ) ;
410+ identify . set ( 'referring_domain' , referring_domain ) ;
411+ }
412+
413+ window . amplitude . getInstance ( ) . identify ( identify ) ;
414+ } ;
415+
416+ // wrapper for testing purposes
417+ Amplitude . prototype . getReferrer = function ( ) {
418+ return document . referrer ;
419+ } ;
420+
395421function mapRevenueAttributes ( track ) {
396422 // Revenue type can be anything such as Refund, Tax, etc.
397423 // Using mapper here to support future ecomm event => revenue mappings (Order Refund, etc.)
0 commit comments