@@ -243,6 +243,8 @@ public void testAddItem() throws Exception {
243
243
ClickstreamEvent event = ClickstreamEvent .builder ()
244
244
.name ("testItem" )
245
245
.add (ClickstreamAnalytics .Item .ITEM_ID , 123 )
246
+ .add (ClickstreamAnalytics .Attr .VALUE , 11000 )
247
+ .add (ClickstreamAnalytics .Attr .CURRENCY , "USD" )
246
248
.setItems (new ClickstreamItem [] {item1 , item2 })
247
249
.build ();
248
250
ClickstreamAnalytics .recordEvent (event );
@@ -274,7 +276,7 @@ public void testAddItem() throws Exception {
274
276
public void testAddGlobalAttribute () throws Exception {
275
277
long timestamp = System .currentTimeMillis ();
276
278
ClickstreamAttribute globalAttribute = ClickstreamAttribute .builder ()
277
- .add ("channel" , "HUAWEI " )
279
+ .add (ClickstreamAnalytics . Attr . APP_INSTALL_CHANNEL , "Amazon Store " )
278
280
.add ("level" , 5.1 )
279
281
.add ("class" , 6 )
280
282
.add ("timestamp" , timestamp )
@@ -296,7 +298,8 @@ public void testAddGlobalAttribute() throws Exception {
296
298
JSONObject jsonObject = new JSONObject (eventString );
297
299
JSONObject attribute = jsonObject .getJSONObject ("attributes" );
298
300
299
- Assert .assertEquals ("HUAWEI" , attribute .getString ("channel" ));
301
+ Assert .assertEquals ("Amazon Store" ,
302
+ attribute .getString (ClickstreamAnalytics .Attr .APP_INSTALL_CHANNEL ));
300
303
Assert .assertEquals (5.1 , attribute .getDouble ("level" ), 0.01 );
301
304
Assert .assertEquals (6 , attribute .getInt ("class" ));
302
305
Assert .assertTrue (attribute .getBoolean ("isOpenNotification" ));
@@ -309,6 +312,46 @@ public void testAddGlobalAttribute() throws Exception {
309
312
}
310
313
}
311
314
315
+ /**
316
+ * test add traffic source attribute.
317
+ *
318
+ * @throws Exception exception
319
+ */
320
+ @ Test
321
+ public void testAddGlobalAttributeForTrafficSource () throws Exception {
322
+ ClickstreamAttribute globalAttribute = ClickstreamAttribute .builder ()
323
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_SOURCE , "amazon" )
324
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_MEDIUM , "cpc" )
325
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CAMPAIGN , "summer_promotion" )
326
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CAMPAIGN_ID , "summer_promotion_01" )
327
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_TERM , "running_shoes" )
328
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CONTENT , "banner_ad_1" )
329
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CLID , "amazon_ad_123" )
330
+ .add (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CLID_PLATFORM , "amazon_ads" )
331
+ .add (ClickstreamAnalytics .Attr .APP_INSTALL_CHANNEL , "amazon_store" )
332
+ .build ();
333
+ ClickstreamAnalytics .addGlobalAttributes (globalAttribute );
334
+ ClickstreamAnalytics .recordEvent ("testEvent" );
335
+ assertEquals (1 , dbUtil .getTotalNumber ());
336
+ try (Cursor cursor = dbUtil .queryAllEvents ()) {
337
+ cursor .moveToFirst ();
338
+ String eventString = cursor .getString (2 );
339
+ JSONObject jsonObject = new JSONObject (eventString );
340
+ JSONObject attribute = jsonObject .getJSONObject ("attributes" );
341
+ Assert .assertEquals ("amazon" , attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_SOURCE ));
342
+ Assert .assertEquals ("cpc" , attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_MEDIUM ));
343
+ Assert .assertEquals ("summer_promotion" ,
344
+ attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CAMPAIGN ));
345
+ Assert .assertEquals ("summer_promotion_01" ,
346
+ attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CAMPAIGN_ID ));
347
+ Assert .assertEquals ("running_shoes" , attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_TERM ));
348
+ Assert .assertEquals ("banner_ad_1" , attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CONTENT ));
349
+ Assert .assertEquals ("amazon_ad_123" , attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CLID ));
350
+ Assert .assertEquals ("amazon_ads" ,
351
+ attribute .getString (ClickstreamAnalytics .Attr .TRAFFIC_SOURCE_CLID_PLATFORM ));
352
+ Assert .assertEquals ("amazon_store" , attribute .getString (ClickstreamAnalytics .Attr .APP_INSTALL_CHANNEL ));
353
+ }
354
+ }
312
355
313
356
/**
314
357
* test add delete global attribute.
@@ -318,7 +361,7 @@ public void testAddGlobalAttribute() throws Exception {
318
361
@ Test
319
362
public void testDeleteGlobalAttribute () throws Exception {
320
363
ClickstreamAttribute globalAttribute = ClickstreamAttribute .builder ()
321
- .add ("channel" , "HUAWEI " )
364
+ .add (ClickstreamAnalytics . Attr . APP_INSTALL_CHANNEL , "Amazon Store " )
322
365
.add ("level" , 5.1 )
323
366
.add ("class" , 6 )
324
367
.add ("isOpenNotification" , true )
@@ -340,7 +383,8 @@ public void testDeleteGlobalAttribute() throws Exception {
340
383
JSONObject jsonObject = new JSONObject (eventString );
341
384
JSONObject attribute = jsonObject .getJSONObject ("attributes" );
342
385
343
- Assert .assertEquals ("HUAWEI" , attribute .getString ("channel" ));
386
+ Assert .assertEquals ("Amazon Store" ,
387
+ attribute .getString (ClickstreamAnalytics .Attr .APP_INSTALL_CHANNEL ));
344
388
Assert .assertFalse (attribute .has ("level" ));
345
389
Assert .assertTrue (attribute .getBoolean ("isOpenNotification" ));
346
390
}
0 commit comments