@@ -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,58 @@ describe('setVersionName', function() {
2993
3019
}
2994
3020
} ) ;
2995
3021
} ) ;
3022
+
3023
+ it ( 'should log attribution event when 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
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3031
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3032
+ '$setOnce' : {
3033
+ initial_utm_campaign : 'new' ,
3034
+ initial_utm_content : 'top'
3035
+ } ,
3036
+ '$set' : {
3037
+ utm_campaign : 'new' ,
3038
+ utm_content : 'top'
3039
+ }
3040
+ } ) ;
3041
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3042
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3043
+ utm_campaign : 'new' ,
3044
+ utm_content : 'top'
3045
+ } ) ;
3046
+ } ) ;
3047
+
3048
+ it ( 'should log attribution event more than once per session if configured and attribution data changes' , function ( ) {
3049
+ reset ( ) ;
3050
+ cookie . set ( '__utmz' , '133232535.1424926227.1.1.utmcct=top&utmccn=new' ) ;
3051
+ amplitude . init ( apiKey , undefined , {
3052
+ includeUtm : true , logAttributionCapturedEvent : true , saveParamsReferrerOncePerSession : false , batchEvents : true , eventUploadThreshold : 2
3053
+ } ) ;
3054
+ // even though same session, utm params are sent again
3055
+ assert . lengthOf ( server . requests , 1 ) ;
3056
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
3057
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3058
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3059
+ '$setOnce' : {
3060
+ initial_utm_campaign : 'new' ,
3061
+ initial_utm_content : 'top'
3062
+ } ,
3063
+ '$set' : {
3064
+ utm_campaign : 'new' ,
3065
+ utm_content : 'top'
3066
+ }
3067
+ } ) ;
3068
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3069
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3070
+ utm_campaign : 'new' ,
3071
+ utm_content : 'top'
3072
+ } ) ;
3073
+ } ) ;
2996
3074
} ) ;
2997
3075
2998
3076
describe ( 'gatherGclid' , function ( ) {
@@ -3050,6 +3128,27 @@ describe('setVersionName', function() {
3050
3128
'$setOnce' : { 'initial_gclid' : '12345' }
3051
3129
} ) ;
3052
3130
} ) ;
3131
+
3132
+ it ( 'should log attribution event when gclid is captured if configured' , ( ) => {
3133
+ clock . tick ( 30 * 60 * 1000 + 1 ) ;
3134
+ amplitude . init ( apiKey , undefined , { includeGclid : true , logAttributionCapturedEvent : true , batchEvents : true , eventUploadThreshold : 2 } ) ;
3135
+
3136
+ assert . lengthOf ( server . requests , 1 ) ;
3137
+ var events = JSON . parse ( queryString . parse ( server . requests [ 0 ] . requestBody ) . e ) ;
3138
+ assert . lengthOf ( events , 2 ) ;
3139
+
3140
+ // first event should be identify with gclid
3141
+ assert . equal ( events [ 0 ] . event_type , '$identify' ) ;
3142
+ assert . deepEqual ( events [ 0 ] . user_properties , {
3143
+ '$set' : { 'gclid' : '12345' } ,
3144
+ '$setOnce' : { 'initial_gclid' : '12345' }
3145
+ } ) ;
3146
+
3147
+ assert . equal ( events [ 1 ] . event_type , constants . ATTRIBUTION_EVENT ) ;
3148
+ assert . deepEqual ( events [ 1 ] . event_properties , {
3149
+ 'gclid' : '12345'
3150
+ } )
3151
+ } ) ;
3053
3152
} ) ;
3054
3153
3055
3154
describe ( 'logRevenue' , function ( ) {
0 commit comments