@@ -38,6 +38,7 @@ export class VASTTracker extends EventEmitter {
38
38
this . impressed = false ;
39
39
this . skippable = false ;
40
40
this . trackingEvents = { } ;
41
+ this . trackedProgressEvents = [ ] ;
41
42
// We need to keep the last percentage of the tracker in order to
42
43
// calculate to trigger the events when the VAST duration is short
43
44
this . lastPercentage = 0 ;
@@ -211,7 +212,7 @@ export class VASTTracker extends EventEmitter {
211
212
for ( let i = this . lastPercentage ; i < percent ; i ++ ) {
212
213
events . push ( `progress-${ i + 1 } %` ) ;
213
214
}
214
- events . push ( `progress-${ Math . round ( progress ) } ` ) ;
215
+ events . push ( `progress-${ progress } ` ) ;
215
216
for ( const quartile in this . quartiles ) {
216
217
if (
217
218
this . isQuartileReached ( quartile , this . quartiles [ quartile ] , progress )
@@ -228,6 +229,9 @@ export class VASTTracker extends EventEmitter {
228
229
229
230
if ( progress < this . progress ) {
230
231
this . track ( 'rewind' , { macros } ) ;
232
+ if ( this . trackedProgressEvents ) {
233
+ this . trackedProgressEvents . splice ( 0 ) ;
234
+ }
231
235
}
232
236
}
233
237
@@ -778,12 +782,42 @@ export class VASTTracker extends EventEmitter {
778
782
}
779
783
}
780
784
785
+ /**
786
+ * Calls the tracking URLs for progress events for the given eventName and emits the event.
787
+ *
788
+ * @param {String } eventName - The name of the event.
789
+ * @param macros - An optional Object of parameters (vast macros) to be used in the tracking calls.
790
+ * @param once - Boolean to define if the event has to be tracked only once.
791
+ */
792
+ trackProgressEvents ( eventName , macros , once ) {
793
+ const eventTime = parseFloat ( eventName . split ( '-' ) [ 1 ] ) ;
794
+
795
+ const progressEvents = Object . entries ( this . trackingEvents )
796
+ . filter ( ( [ key ] ) => key . startsWith ( 'progress-' ) )
797
+ . map ( ( [ key , value ] ) => ( { name : key , time : parseFloat ( key . split ( '-' ) [ 1 ] ) , urls : value } ) )
798
+ . filter ( ( { time } ) => time <= eventTime && time > this . progress ) ;
799
+
800
+ progressEvents . forEach ( ( { name, urls } ) => {
801
+ if ( ! once && this . trackedProgressEvents . includes ( name ) ) {
802
+ return ;
803
+ }
804
+ this . emit ( name , { trackingURLTemplates : urls } ) ;
805
+ this . trackURLs ( urls , macros ) ;
806
+
807
+ if ( once ) {
808
+ delete this . trackingEvents [ name ] ;
809
+ } else {
810
+ this . trackedProgressEvents . push ( name ) ;
811
+ }
812
+ } ) ;
813
+ }
814
+
781
815
/**
782
816
* Calls the tracking URLs for the given eventName and emits the event.
783
817
*
784
818
* @param {String } eventName - The name of the event.
785
819
* @param {Object } options
786
- * @param {Object } [options.macros={}] - An optional Object of parameters(vast macros) to be used in the tracking calls.
820
+ * @param {Object } [options.macros={}] - An optional Object of parameters (vast macros) to be used in the tracking calls.
787
821
* @param {Boolean } [options.once=false] - Boolean to define if the event has to be tracked only once.
788
822
*
789
823
*/
@@ -804,6 +838,10 @@ export class VASTTracker extends EventEmitter {
804
838
eventName = 'close' ;
805
839
}
806
840
841
+ if ( eventName . startsWith ( 'progress-' ) && ! eventName . endsWith ( "%" ) ) {
842
+ this . trackProgressEvents ( eventName , macros , once ) ;
843
+ }
844
+
807
845
const trackingURLTemplates = this . trackingEvents [ eventName ] ;
808
846
const isAlwaysEmitEvent = this . emitAlwaysEvents . indexOf ( eventName ) > - 1 ;
809
847
0 commit comments