@@ -66,6 +66,23 @@ export class VASTTracker extends EventEmitter {
66
66
this . trackingEvents [ eventName ] = events . slice ( 0 ) ;
67
67
}
68
68
69
+ // ViewableImpression node can contain notViewable, viewUndetermined, viewable traking urls
70
+ // to benefit the 'once' tracking feature we need to merge them into other trackingEvents
71
+ this . viewableImpressionTrackers =
72
+ this . ad . viewableImpression ?. reduce (
73
+ ( accumulator , trackers ) => {
74
+ accumulator . notViewable . push ( ...trackers . notViewable ) ;
75
+ accumulator . viewUndetermined . push ( ...trackers . viewUndetermined ) ;
76
+ accumulator . viewable . push ( ...trackers . viewable ) ;
77
+ return accumulator ;
78
+ } ,
79
+ { notViewable : [ ] , viewUndetermined : [ ] , viewable : [ ] }
80
+ ) || [ ] ;
81
+
82
+ Object . entries ( this . viewableImpressionTrackers ) . forEach ( ( [ key , value ] ) => {
83
+ if ( value . length ) this . trackingEvents [ key ] = value ;
84
+ } ) ;
85
+
69
86
// Nonlinear and companion creatives provide some tracking information at a variation level
70
87
// While linear creatives provided that at a creative level. That's why we need to
71
88
// differentiate how we retrieve some tracking information.
@@ -394,51 +411,44 @@ export class VASTTracker extends EventEmitter {
394
411
* Tracks Viewable impression
395
412
* @param {Object } [macros = {}] An optional Object containing macros and their values to be used and replaced in the tracking calls.
396
413
*/
397
- trackViewableImpression ( macros = { } ) {
414
+ trackViewableImpression ( macros = { } , once = false ) {
398
415
if ( typeof macros !== 'object' ) {
399
416
this . emit ( 'TRACKER-error' , {
400
417
message : `trackViewableImpression given macros has the wrong type. macros: ${ macros } ` ,
401
418
} ) ;
402
419
return ;
403
420
}
404
- this . ad . viewableImpression . forEach ( ( impression ) => {
405
- this . trackURLs ( impression . viewable , macros ) ;
406
- } ) ;
421
+
422
+ this . track ( 'viewable' , { macros, once } ) ;
407
423
}
408
424
409
425
/**
410
426
* Tracks NotViewable impression
411
427
* @param {Object } [macros = {}] An optional Object containing macros and their values to be used and replaced in the tracking calls.
412
428
*/
413
429
414
- trackNotViewableImpression ( macros = { } ) {
430
+ trackNotViewableImpression ( macros = { } , once = false ) {
415
431
if ( typeof macros !== 'object' ) {
416
432
this . emit ( 'TRACKER-error' , {
417
433
message : `trackNotViewableImpression given macros has the wrong type. macros: ${ macros } ` ,
418
434
} ) ;
419
435
return ;
420
436
}
421
-
422
- this . ad . viewableImpression . forEach ( ( impression ) => {
423
- this . trackURLs ( impression . notViewable , macros ) ;
424
- } ) ;
437
+ this . track ( 'notViewable' , { macros, once } ) ;
425
438
}
426
439
427
440
/**
428
441
* Tracks ViewUndetermined impression
429
442
* @param {Object } [macros = {}] An optional Object containing macros and their values to be used and replaced in the tracking calls.
430
443
*/
431
- trackUndeterminedImpression ( macros = { } ) {
444
+ trackUndeterminedImpression ( macros = { } , once = false ) {
432
445
if ( typeof macros !== 'object' ) {
433
446
this . emit ( 'TRACKER-error' , {
434
447
message : `trackUndeterminedImpression given macros has the wrong type. macros: ${ macros } ` ,
435
448
} ) ;
436
449
return ;
437
450
}
438
-
439
- this . ad . viewableImpression . forEach ( ( impression ) => {
440
- this . trackURLs ( impression . viewUndetermined , macros ) ;
441
- } ) ;
451
+ this . track ( 'viewUndetermined' , { macros, once } ) ;
442
452
}
443
453
444
454
/**
@@ -794,7 +804,11 @@ export class VASTTracker extends EventEmitter {
794
804
795
805
const progressEvents = Object . entries ( this . trackingEvents )
796
806
. filter ( ( [ key ] ) => key . startsWith ( 'progress-' ) )
797
- . map ( ( [ key , value ] ) => ( { name : key , time : parseFloat ( key . split ( '-' ) [ 1 ] ) , urls : value } ) )
807
+ . map ( ( [ key , value ] ) => ( {
808
+ name : key ,
809
+ time : parseFloat ( key . split ( '-' ) [ 1 ] ) ,
810
+ urls : value ,
811
+ } ) )
798
812
. filter ( ( { time } ) => time <= eventTime && time > this . progress ) ;
799
813
800
814
progressEvents . forEach ( ( { name, urls } ) => {
@@ -838,7 +852,7 @@ export class VASTTracker extends EventEmitter {
838
852
eventName = 'close' ;
839
853
}
840
854
841
- if ( eventName . startsWith ( 'progress-' ) && ! eventName . endsWith ( "%" ) ) {
855
+ if ( eventName . startsWith ( 'progress-' ) && ! eventName . endsWith ( '%' ) ) {
842
856
this . trackProgressEvents ( eventName , macros , once ) ;
843
857
}
844
858
0 commit comments