@@ -2952,6 +2952,32 @@ describe('setVersionName', function() {
2952
2952
} ) ;
2953
2953
} ) ;
2954
2954
2955
+ it ( 'should log attribution event when referrer is updated if configured' , function ( ) {
2956
+ clock . tick ( 30 * 60 * 1000 + 1 ) ; // force new session
2957
+ amplitude . init ( apiKey , undefined , { includeReferrer : true , logAttributionCapturedEvent : true , batchEvents : true , eventUploadThreshold : 2 } ) ;
2958
+ assert . lengthOf ( server . requests , 1 ) ;
2959
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
2960
+ assert . lengthOf ( events , 2 ) ;
2961
+ // first event should be identify with initial_referrer and referrer
2962
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
2963
+ assert . deepEqual ( events [ 0 ] . user_properties , {
2964
+ '$set' : {
2965
+ 'referrer' : 'https://amplitude.com/contact' ,
2966
+ 'referring_domain' : 'amplitude.com'
2967
+ } ,
2968
+ '$setOnce' : {
2969
+ 'initial_referrer' : 'https://amplitude.com/contact' ,
2970
+ 'initial_referring_domain' : 'amplitude.com'
2971
+ }
2972
+ } ) ;
2973
+ // second event should be the attribution captured event with referrer information
2974
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
2975
+ assert . deepEqual ( events [ 1 ] . event_properties , {
2976
+ 'referrer' : 'https://amplitude.com/contact' ,
2977
+ 'referring_domain' : 'amplitude.com'
2978
+ } ) ;
2979
+ } ) ;
2980
+
2955
2981
it ( 'should not delete unsent events saved to localStorage' , function ( ) {
2956
2982
var existingEvent = '[{"device_id":"test_device_id","user_id":"test_user_id","timestamp":1453769146589,' +
2957
2983
'"event_id":49,"session_id":1453763315544,"event_type":"clicked","version_name":"Web","platform":"Web"' +
@@ -2993,6 +3019,62 @@ describe('setVersionName', function() {
2993
3019
}
2994
3020
} ) ;
2995
3021
} ) ;
3022
+
3023
+ it ( 'should log attribution event when UTMs are captured if configured' , function ( ) {
3024
+ reset ( ) ;
3025
+ cookie . set ( '__utmz' , '133232535.1424926227.1.1.utmcct=top&utmccn=new' ) ;
3026
+ clock . tick ( 30 * 60 * 1000 + 1 ) ;
3027
+ amplitude . init ( apiKey , undefined , { includeUtm : true , logAttributionCapturedEvent : true , batchEvents : true , eventUploadThreshold : 2 } ) ;
3028
+ assert . lengthOf ( server . requests , 1 ) ;
3029
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
3030
+ // first event should be identify with UTM state
3031
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3032
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3033
+ '$setOnce' : {
3034
+ initial_utm_campaign : 'new' ,
3035
+ initial_utm_content : 'top'
3036
+ } ,
3037
+ '$set' : {
3038
+ utm_campaign : 'new' ,
3039
+ utm_content : 'top'
3040
+ }
3041
+ } ) ;
3042
+ // second event should be the attribution captured event with UTMs populated
3043
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3044
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3045
+ utm_campaign : 'new' ,
3046
+ utm_content : 'top'
3047
+ } ) ;
3048
+ } ) ;
3049
+
3050
+ it ( 'should log attribution event more than once per session if configured and UTMs changes' , function ( ) {
3051
+ reset ( ) ;
3052
+ cookie . set ( '__utmz' , '133232535.1424926227.1.1.utmcct=top&utmccn=new' ) ;
3053
+ amplitude . init ( apiKey , undefined , {
3054
+ includeUtm : true , logAttributionCapturedEvent : true , saveParamsReferrerOncePerSession : false , batchEvents : true , eventUploadThreshold : 2
3055
+ } ) ;
3056
+ // even though same session, utm params are sent again
3057
+ assert . lengthOf ( server . requests , 1 ) ;
3058
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
3059
+ // first event should be identify with UTM state
3060
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3061
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3062
+ '$setOnce' : {
3063
+ initial_utm_campaign : 'new' ,
3064
+ initial_utm_content : 'top'
3065
+ } ,
3066
+ '$set' : {
3067
+ utm_campaign : 'new' ,
3068
+ utm_content : 'top'
3069
+ }
3070
+ } ) ;
3071
+ // second event should be the attribution captured event with UTMs populated
3072
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3073
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3074
+ utm_campaign : 'new' ,
3075
+ utm_content : 'top'
3076
+ } ) ;
3077
+ } ) ;
2996
3078
} ) ;
2997
3079
2998
3080
describe ( 'gatherGclid' , function ( ) {
@@ -3050,6 +3132,27 @@ describe('setVersionName', function() {
3050
3132
'$setOnce' : { 'initial_gclid' : '12345' }
3051
3133
} ) ;
3052
3134
} ) ;
3135
+
3136
+ it ( 'should log attribution event when gclid is captured if configured' , ( ) => {
3137
+ clock . tick ( 30 * 60 * 1000 + 1 ) ;
3138
+ amplitude . init ( apiKey , undefined , { includeGclid : true , logAttributionCapturedEvent : true , batchEvents : true , eventUploadThreshold : 2 } ) ;
3139
+
3140
+ assert . lengthOf ( server . requests , 1 ) ;
3141
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
3142
+ assert . lengthOf ( events , 2 ) ;
3143
+
3144
+ // first event should be identify with gclid
3145
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3146
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3147
+ '$set' : { 'gclid' : '12345' } ,
3148
+ '$setOnce' : { 'initial_gclid' : '12345' }
3149
+ } ) ;
3150
+ // second event should be the attribution captured event with gclid populated
3151
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3152
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3153
+ 'gclid' : '12345'
3154
+ } )
3155
+ } ) ;
3053
3156
} ) ;
3054
3157
3055
3158
describe ( 'logRevenue' , function ( ) {
0 commit comments