Skip to content

Commit 136b074

Browse files
committed
support progress event with exact offset values
1 parent a019a76 commit 136b074

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

src/vast_tracker.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export class VASTTracker extends EventEmitter {
211211
for (let i = this.lastPercentage; i < percent; i++) {
212212
events.push(`progress-${i + 1}%`);
213213
}
214-
events.push(`progress-${Math.round(progress)}`);
214+
events.push(`progress-${progress}`);
215215
for (const quartile in this.quartiles) {
216216
if (
217217
this.isQuartileReached(quartile, this.quartiles[quartile], progress)
@@ -778,6 +778,32 @@ export class VASTTracker extends EventEmitter {
778778
}
779779
}
780780

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+
781807
/**
782808
* Calls the tracking URLs for the given eventName and emits the event.
783809
*
@@ -804,6 +830,10 @@ export class VASTTracker extends EventEmitter {
804830
eventName = 'close';
805831
}
806832

833+
if (eventName.startsWith('progress-')) {
834+
this.trackProgressEvents(eventName, macros, once);
835+
}
836+
807837
const trackingURLTemplates = this.trackingEvents[eventName];
808838
const isAlwaysEmitEvent = this.emitAlwaysEvents.indexOf(eventName) > -1;
809839

0 commit comments

Comments
 (0)