@@ -211,7 +211,7 @@ export class VASTTracker extends EventEmitter {
211
211
for ( let i = this . lastPercentage ; i < percent ; i ++ ) {
212
212
events . push ( `progress-${ i + 1 } %` ) ;
213
213
}
214
- events . push ( `progress-${ Math . round ( progress ) } ` ) ;
214
+ events . push ( `progress-${ progress } ` ) ;
215
215
for ( const quartile in this . quartiles ) {
216
216
if (
217
217
this . isQuartileReached ( quartile , this . quartiles [ quartile ] , progress )
@@ -778,6 +778,32 @@ export class VASTTracker extends EventEmitter {
778
778
}
779
779
}
780
780
781
+ /**
782
+ * Calls the tracking URLs for progress events for the given eventName and emits the event.
783
+ *
784
+ * @param {String } eventName - The name of the event.
785
+ * @param macros - An optional Object of parameters(vast macros) to be used in the tracking calls.
786
+ * @param once - Boolean to define if the event has to be tracked only once.
787
+ */
788
+ trackProgressEvents ( eventName , macros , once ) {
789
+ const eventTime = parseFloat ( eventName . split ( '-' ) [ 1 ] ) ;
790
+
791
+ Object . keys ( this . trackingEvents )
792
+ . filter ( trackingEvent => trackingEvent . startsWith ( 'progress-' ) )
793
+ . map ( trackingEvent => ( {
794
+ name : trackingEvent ,
795
+ time : parseFloat ( trackingEvent . split ( '-' ) [ 1 ] )
796
+ } ) )
797
+ . filter ( ( { time } ) => time <= eventTime )
798
+ . forEach ( ( { name } ) => {
799
+ this . emit ( name , { trackingURLTemplates : this . trackingEvents [ name ] } ) ;
800
+ this . trackURLs ( this . trackingEvents [ name ] , macros ) ;
801
+ if ( once ) {
802
+ delete this . trackingEvents [ name ] ;
803
+ }
804
+ } ) ;
805
+ }
806
+
781
807
/**
782
808
* Calls the tracking URLs for the given eventName and emits the event.
783
809
*
@@ -804,6 +830,10 @@ export class VASTTracker extends EventEmitter {
804
830
eventName = 'close' ;
805
831
}
806
832
833
+ if ( eventName . startsWith ( 'progress-' ) ) {
834
+ this . trackProgressEvents ( eventName , macros , once ) ;
835
+ }
836
+
807
837
const trackingURLTemplates = this . trackingEvents [ eventName ] ;
808
838
const isAlwaysEmitEvent = this . emitAlwaysEvents . indexOf ( eventName ) > - 1 ;
809
839
0 commit comments