@@ -9,6 +9,7 @@ describe('Facebook Pixel', function() {
9
9
var analytics ;
10
10
var facebookPixel ;
11
11
var options = {
12
+ automaticConfiguration : true ,
12
13
legacyEvents : {
13
14
legacyEvent : 'asdFrkj'
14
15
} ,
@@ -17,6 +18,9 @@ describe('Facebook Pixel', function() {
17
18
'booking completed' : 'Purchase' ,
18
19
search : 'Search'
19
20
} ,
21
+ contentTypes : {
22
+ Cars : "vehicle"
23
+ } ,
20
24
pixelId : '123123123' ,
21
25
agent : 'test' ,
22
26
initWithExistingTraits : false
@@ -86,6 +90,20 @@ describe('Facebook Pixel', function() {
86
90
analytics . assert ( window . fbq instanceof Function ) ;
87
91
} ) ;
88
92
93
+ before ( function ( ) {
94
+ options . automaticConfiguration = false ;
95
+ } ) ;
96
+
97
+ after ( function ( ) {
98
+ options . automaticConfiguration = true ;
99
+ } ) ;
100
+
101
+ it ( 'should call set autoConfig if option disableAutoConfig is enabled' , function ( ) {
102
+ analytics . stub ( window , 'fbq' ) ;
103
+ analytics . initialize ( ) ;
104
+ analytics . called ( window . fbq , 'set' , 'autoConfig' , false , options . pixelId ) ;
105
+ } ) ;
106
+
89
107
before ( function ( ) {
90
108
options . initWithExistingTraits = true ;
91
109
} ) ;
@@ -225,7 +243,6 @@ describe('Facebook Pixel', function() {
225
243
property : true
226
244
} ) ;
227
245
} ) ;
228
-
229
246
describe ( 'Dyanmic Ads for Travel date parsing' , function ( ) {
230
247
it ( 'should correctly pass in iso8601 formatted date objects' , function ( ) {
231
248
analytics . track ( 'search' , {
@@ -260,7 +277,7 @@ describe('Facebook Pixel', function() {
260
277
name : 'Monopoly: 3rd Edition' ,
261
278
price : 19 ,
262
279
position : 1 ,
263
- category : 'Games ' ,
280
+ category : 'Cars ' ,
264
281
url : 'https://www.example.com/product/path' ,
265
282
image_url : 'https://www.example.com/product/path.jpg'
266
283
} ,
@@ -270,23 +287,52 @@ describe('Facebook Pixel', function() {
270
287
name : 'Uno Card Game' ,
271
288
price : 3 ,
272
289
position : 2 ,
273
- category : 'Games '
290
+ category : 'Cars '
274
291
}
275
292
]
276
293
} ) ;
277
294
analytics . called ( window . fbq , 'track' , 'ViewContent' , {
278
295
content_ids : [ '507f1f77bcf86cd799439011' , '505bd76785ebb509fc183733' ] ,
279
- content_type : 'product'
296
+ content_type : [ 'product' ]
280
297
} ) ;
281
298
} ) ;
282
299
283
300
it ( 'Should fallback on mapping content_ids to the product category and content_type to "product_group"' , function ( ) {
284
301
analytics . track ( 'Product List Viewed' , { category : 'Games' } ) ;
285
302
analytics . called ( window . fbq , 'track' , 'ViewContent' , {
286
303
content_ids : [ 'Games' ] ,
287
- content_type : 'product_group'
304
+ content_type : [ 'product_group' ]
288
305
} ) ;
289
306
} ) ;
307
+
308
+ it ( 'should send the custom content type if mapped' , function ( ) {
309
+ analytics . track ( 'Product List Viewed' , {
310
+ category : 'Cars' , products : [
311
+ {
312
+ product_id : '507f1f77bcf86cd799439011' ,
313
+ sku : '45790-32' ,
314
+ name : 'Monopoly: 3rd Edition' ,
315
+ price : 19 ,
316
+ position : 1 ,
317
+ category : 'Games' ,
318
+ url : 'https://www.example.com/product/path' ,
319
+ image_url : 'https://www.example.com/product/path.jpg'
320
+ } ,
321
+ {
322
+ product_id : '505bd76785ebb509fc183733' ,
323
+ sku : '46493-32' ,
324
+ name : 'Uno Card Game' ,
325
+ price : 3 ,
326
+ position : 2 ,
327
+ category : 'Games'
328
+ }
329
+ ]
330
+ } ) ;
331
+ analytics . called ( window . fbq , 'track' , 'ViewContent' , {
332
+ content_ids : [ '507f1f77bcf86cd799439011' , '505bd76785ebb509fc183733' ] ,
333
+ content_type : [ 'vehicle' ]
334
+ } ) ;
335
+ } )
290
336
} ) ;
291
337
292
338
it ( 'Product Viewed' , function ( ) {
@@ -302,7 +348,7 @@ describe('Facebook Pixel', function() {
302
348
} ) ;
303
349
analytics . called ( window . fbq , 'track' , 'ViewContent' , {
304
350
content_ids : [ '507f1f77bcf86cd799439011' ] ,
305
- content_type : 'product' ,
351
+ content_type : [ 'product' ] ,
306
352
content_name : 'my product' ,
307
353
content_category : 'cat 1' ,
308
354
currency : 'USD' ,
@@ -324,14 +370,35 @@ describe('Facebook Pixel', function() {
324
370
} ) ;
325
371
analytics . called ( window . fbq , 'track' , 'ViewContent' , {
326
372
content_ids : [ '507f1f77bcf86cd799439011' ] ,
327
- content_type : 'product' ,
373
+ content_type : [ 'product' ] ,
328
374
content_name : 'my product' ,
329
375
content_category : 'cat 1' ,
330
376
currency : 'USD' ,
331
377
value : '44.33'
332
378
} ) ;
333
379
} ) ;
334
380
381
+ it ( 'should send the custom content type if mapped' , function ( ) {
382
+ analytics . track ( 'Product Viewed' , {
383
+ product_id : '507f1f77bcf86cd799439011' ,
384
+ currency : 'USD' ,
385
+ quantity : 1 ,
386
+ price : 44.33 ,
387
+ name : 'my product' ,
388
+ category : 'Cars' ,
389
+ sku : 'p-298' ,
390
+ value : 24.75 ,
391
+ } ) ;
392
+ analytics . called ( window . fbq , 'track' , 'ViewContent' , {
393
+ content_ids : [ '507f1f77bcf86cd799439011' ] ,
394
+ content_type : [ 'vehicle' ] ,
395
+ content_name : 'my product' ,
396
+ content_category : 'Cars' ,
397
+ currency : 'USD' ,
398
+ value : '24.75'
399
+ } ) ;
400
+ } )
401
+
335
402
it ( 'Adding to Cart' , function ( ) {
336
403
analytics . track ( 'Product Added' , {
337
404
product_id : '507f1f77bcf86cd799439011' ,
@@ -345,7 +412,7 @@ describe('Facebook Pixel', function() {
345
412
} ) ;
346
413
analytics . called ( window . fbq , 'track' , 'AddToCart' , {
347
414
content_ids : [ '507f1f77bcf86cd799439011' ] ,
348
- content_type : 'product' ,
415
+ content_type : [ 'product' ] ,
349
416
content_name : 'my product' ,
350
417
content_category : 'cat 1' ,
351
418
currency : 'USD' ,
@@ -367,14 +434,36 @@ describe('Facebook Pixel', function() {
367
434
} ) ;
368
435
analytics . called ( window . fbq , 'track' , 'AddToCart' , {
369
436
content_ids : [ '507f1f77bcf86cd799439011' ] ,
370
- content_type : 'product' ,
437
+ content_type : [ 'product' ] ,
371
438
content_name : 'my product' ,
372
439
content_category : 'cat 1' ,
373
440
currency : 'USD' ,
374
441
value : '44.33'
375
442
} ) ;
376
443
} ) ;
377
444
445
+ it ( 'should send the custom content type if mapped' , function ( ) {
446
+ analytics . track ( 'Product Added' , {
447
+ product_id : '507f1f77bcf86cd799439011' ,
448
+ currency : 'USD' ,
449
+ quantity : 1 ,
450
+ price : 44.33 ,
451
+ name : 'my product' ,
452
+ category : 'Cars' ,
453
+ sku : 'p-298' ,
454
+ value : 24.75 ,
455
+ content_type : "stuff"
456
+ } ) ;
457
+ analytics . called ( window . fbq , 'track' , 'AddToCart' , {
458
+ content_ids : [ '507f1f77bcf86cd799439011' ] ,
459
+ content_type : [ 'vehicle' ] ,
460
+ content_name : 'my product' ,
461
+ content_category : 'Cars' ,
462
+ currency : 'USD' ,
463
+ value : '24.75'
464
+ } ) ;
465
+ } )
466
+
378
467
it ( 'Completing an Order' , function ( ) {
379
468
analytics . track ( 'Order Completed' , {
380
469
products : [
@@ -386,7 +475,7 @@ describe('Facebook Pixel', function() {
386
475
} ) ;
387
476
analytics . called ( window . fbq , 'track' , 'Purchase' , {
388
477
content_ids : [ '507f1f77bcf86cd799439011' , '505bd76785ebb509fc183733' ] ,
389
- content_type : 'product' ,
478
+ content_type : [ 'product_group' ] ,
390
479
currency : 'USD' ,
391
480
value : '0.50'
392
481
} ) ;
@@ -404,7 +493,7 @@ describe('Facebook Pixel', function() {
404
493
} ) ;
405
494
analytics . called ( window . fbq , 'track' , 'Purchase' , {
406
495
content_ids : [ '507f1f77bcf86cd799439011' , '505bd76785ebb509fc183733' ] ,
407
- content_type : 'product' ,
496
+ content_type : [ 'product_group' ] ,
408
497
currency : 'USD' ,
409
498
value : '0.50'
410
499
} ) ;
@@ -413,6 +502,23 @@ describe('Facebook Pixel', function() {
413
502
value : '0.50'
414
503
} ) ;
415
504
} ) ;
505
+
506
+ it ( 'should send the custom content type if mapped' , function ( ) {
507
+ analytics . track ( 'Order Completed' , {
508
+ products : [
509
+ { product_id : '507f1f77bcf86cd799439011' , category : 'Cars' } ,
510
+ { product_id : '505bd76785ebb509fc183733' , category : 'Cars' }
511
+ ] ,
512
+ currency : 'USD' ,
513
+ total : 0.50 ,
514
+ } ) ;
515
+ analytics . called ( window . fbq , 'track' , 'Purchase' , {
516
+ content_ids : [ '507f1f77bcf86cd799439011' , '505bd76785ebb509fc183733' ] ,
517
+ content_type : [ 'vehicle' ] ,
518
+ currency : 'USD' ,
519
+ value : '0.50'
520
+ } ) ;
521
+ } )
416
522
} ) ;
417
523
} ) ;
418
524
} ) ;
0 commit comments