10
10
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
11
11
* and limitations under the License.
12
12
*/
13
- import { setUpBrowserPerformance } from " ./browser/BrowserUtil" ;
14
- import { ClickstreamAnalytics , Item , SendMode } from '../src' ;
13
+ import { setUpBrowserPerformance } from ' ./browser/BrowserUtil' ;
14
+ import { ClickstreamAnalytics , Item , SendMode , Attr } from '../src' ;
15
15
import { NetRequest } from '../src/network/NetRequest' ;
16
16
import { Event } from '../src/provider' ;
17
17
import { StorageUtil } from '../src/util/StorageUtil' ;
@@ -66,17 +66,72 @@ describe('ClickstreamAnalytics test', () => {
66
66
) ;
67
67
const firstEvent = eventList [ 0 ] ;
68
68
expect ( firstEvent . event_type ) . toBe ( Event . PresetEvent . FIRST_OPEN ) ;
69
- expect ( firstEvent . user [ Event . ReservedAttribute . USER_FIRST_TOUCH_TIMESTAMP ] ) . not . toBeUndefined ( )
69
+ expect (
70
+ firstEvent . user [ Event . ReservedAttribute . USER_FIRST_TOUCH_TIMESTAMP ]
71
+ ) . not . toBeUndefined ( ) ;
70
72
expect ( firstEvent . attributes . brand ) . toBe ( 'Samsung' ) ;
71
73
expect ( firstEvent . attributes . level ) . toBe ( 10 ) ;
72
- expect ( firstEvent . attributes [ Event . ReservedAttribute . SESSION_ID ] ) . not . toBeUndefined ( ) ;
73
- expect ( firstEvent . attributes [ Event . ReservedAttribute . SESSION_NUMBER ] ) . not . toBeUndefined ( ) ;
74
- expect ( firstEvent . attributes [ Event . ReservedAttribute . SESSION_START_TIMESTAMP ] ) . not . toBeUndefined ( ) ;
75
- expect ( firstEvent . attributes [ Event . ReservedAttribute . SESSION_DURATION ] ) . not . toBeUndefined ( ) ;
74
+ expect (
75
+ firstEvent . attributes [ Event . ReservedAttribute . SESSION_ID ]
76
+ ) . not . toBeUndefined ( ) ;
77
+ expect (
78
+ firstEvent . attributes [ Event . ReservedAttribute . SESSION_NUMBER ]
79
+ ) . not . toBeUndefined ( ) ;
80
+ expect (
81
+ firstEvent . attributes [ Event . ReservedAttribute . SESSION_START_TIMESTAMP ]
82
+ ) . not . toBeUndefined ( ) ;
83
+ expect (
84
+ firstEvent . attributes [ Event . ReservedAttribute . SESSION_DURATION ]
85
+ ) . not . toBeUndefined ( ) ;
76
86
const testEvent = eventList [ eventList . length - 1 ] ;
77
87
expect ( testEvent . attributes . brand ) . toBeUndefined ( ) ;
78
88
} ) ;
79
89
90
+ test ( 'test init sdk with traffic source global attributes' , async ( ) => {
91
+ const result = ClickstreamAnalytics . init ( {
92
+ appId : 'testApp' ,
93
+ endpoint : 'https://example.com/collect' ,
94
+ sendMode : SendMode . Batch ,
95
+ globalAttributes : {
96
+ [ Attr . TRAFFIC_SOURCE_SOURCE ] : 'amazon' ,
97
+ [ Attr . TRAFFIC_SOURCE_MEDIUM ] : 'cpc' ,
98
+ [ Attr . TRAFFIC_SOURCE_CAMPAIGN ] : 'summer_promotion' ,
99
+ [ Attr . TRAFFIC_SOURCE_CAMPAIGN_ID ] : 'summer_promotion_01' ,
100
+ [ Attr . TRAFFIC_SOURCE_TERM ] : 'running_shoes' ,
101
+ [ Attr . TRAFFIC_SOURCE_CONTENT ] : 'banner_ad_1' ,
102
+ [ Attr . TRAFFIC_SOURCE_CLID ] : 'amazon_ad_123' ,
103
+ [ Attr . TRAFFIC_SOURCE_CLID_PLATFORM ] : 'amazon_ads' ,
104
+ } ,
105
+ } ) ;
106
+ expect ( result ) . toBeTruthy ( ) ;
107
+ await sleep ( 100 ) ;
108
+ const eventList = JSON . parse (
109
+ StorageUtil . getAllEvents ( ) + Event . Constants . SUFFIX
110
+ ) ;
111
+ const firstEvent = eventList [ 0 ] ;
112
+ expect ( firstEvent . event_type ) . toBe ( Event . PresetEvent . FIRST_OPEN ) ;
113
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_SOURCE ] ) . toBe ( 'amazon' ) ;
114
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_MEDIUM ] ) . toBe ( 'cpc' ) ;
115
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_CAMPAIGN ] ) . toBe (
116
+ 'summer_promotion'
117
+ ) ;
118
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_CAMPAIGN_ID ] ) . toBe (
119
+ 'summer_promotion_01'
120
+ ) ;
121
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_TERM ] ) . toBe (
122
+ 'running_shoes'
123
+ ) ;
124
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_CONTENT ] ) . toBe (
125
+ 'banner_ad_1'
126
+ ) ;
127
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_CLID ] ) . toBe (
128
+ 'amazon_ad_123'
129
+ ) ;
130
+ expect ( firstEvent . attributes [ Attr . TRAFFIC_SOURCE_CLID_PLATFORM ] ) . toBe (
131
+ 'amazon_ads'
132
+ ) ;
133
+ } ) ;
134
+
80
135
test ( 'test record event with name success' , async ( ) => {
81
136
const sendRequestMock = jest . spyOn ( NetRequest , 'sendRequest' ) ;
82
137
ClickstreamAnalytics . init ( {
@@ -111,7 +166,7 @@ describe('ClickstreamAnalytics test', () => {
111
166
name : 'Nature' ,
112
167
category : 'book' ,
113
168
price : 56.5 ,
114
- customKey : " customValue" ,
169
+ customKey : ' customValue' ,
115
170
} ;
116
171
ClickstreamAnalytics . record ( {
117
172
name : 'testEvent' ,
@@ -120,6 +175,8 @@ describe('ClickstreamAnalytics test', () => {
120
175
longValue : 4232032890992380000 ,
121
176
isNew : true ,
122
177
score : 85.22 ,
178
+ [ Attr . VALUE ] : 56.5 ,
179
+ [ Attr . CURRENCY ] : 'USD' ,
123
180
} ,
124
181
items : [ item ] ,
125
182
} ) ;
0 commit comments