From a019a76aa68ce2c712aa3f1f7c3c939a377a5249 Mon Sep 17 00:00:00 2001 From: Clarisse Damon Date: Wed, 8 Jan 2025 11:06:31 +0100 Subject: [PATCH 1/2] Preserve offset values in progress tracking events parsing --- src/parser/creative_linear_parser.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/parser/creative_linear_parser.js b/src/parser/creative_linear_parser.js index cba2b20e..816aacba 100644 --- a/src/parser/creative_linear_parser.js +++ b/src/parser/creative_linear_parser.js @@ -105,9 +105,9 @@ export function parseCreativeLinear(creativeElement, creativeAttributes) { if (offset.charAt(offset.length - 1) === '%') { eventName = `progress-${offset}`; } else { - eventName = `progress-${Math.round( + eventName = `progress-${ parserUtils.parseDuration(offset) - )}`; + }`; } } From e5e1ce30c49bf77b93ef54478d39c44857efdd2b Mon Sep 17 00:00:00 2001 From: Clarisse Damon Date: Thu, 9 Jan 2025 15:09:23 +0100 Subject: [PATCH 2/2] support progress event with exact offset values --- spec/samples/inline_trackers.js | 1 + ..._trackers.spec.js => vast_tracker.spec.js} | 2 +- src/vast_tracker.js | 42 ++++++++++++++++++- 3 files changed, 42 insertions(+), 3 deletions(-) rename spec/{vast_trackers.spec.js => vast_tracker.spec.js} (99%) diff --git a/spec/samples/inline_trackers.js b/spec/samples/inline_trackers.js index 144d3385..05f248b3 100644 --- a/spec/samples/inline_trackers.js +++ b/spec/samples/inline_trackers.js @@ -191,6 +191,7 @@ export const inlineTrackersParsed = { close: ['http://example.com/linear-close'], thirdQuartile: ['http://example.com/linear-thirdQuartile'], 'progress-30': ['http://example.com/linear-progress-30sec'], + 'progress-42.333': ['http://example.com/linear-progress-42.333sec'], 'progress-60%': ['http://example.com/linear-progress-60%'], otherAdInteraction: [ 'http://example.com/linear-otherAdInteraction', diff --git a/spec/vast_trackers.spec.js b/spec/vast_tracker.spec.js similarity index 99% rename from spec/vast_trackers.spec.js rename to spec/vast_tracker.spec.js index ff2dd5d0..3eb76db2 100644 --- a/spec/vast_trackers.spec.js +++ b/spec/vast_tracker.spec.js @@ -523,7 +523,7 @@ describe('VASTTracker', function () { expect(spyEmitter).toHaveBeenCalledWith('skip-countdown', 0); }); - it('should track rewind when set to 2', () => { + it('should track rewind when set to 2', () => { vastTracker.setProgress(2); expect(spyTrack).toHaveBeenCalledWith('rewind', expect.any(Object)); }); diff --git a/src/vast_tracker.js b/src/vast_tracker.js index 8f144976..fcf49e9b 100644 --- a/src/vast_tracker.js +++ b/src/vast_tracker.js @@ -38,6 +38,7 @@ export class VASTTracker extends EventEmitter { this.impressed = false; this.skippable = false; this.trackingEvents = {}; + this.trackedProgressEvents = []; // We need to keep the last percentage of the tracker in order to // calculate to trigger the events when the VAST duration is short this.lastPercentage = 0; @@ -211,7 +212,7 @@ export class VASTTracker extends EventEmitter { for (let i = this.lastPercentage; i < percent; i++) { events.push(`progress-${i + 1}%`); } - events.push(`progress-${Math.round(progress)}`); + events.push(`progress-${progress}`); for (const quartile in this.quartiles) { if ( this.isQuartileReached(quartile, this.quartiles[quartile], progress) @@ -228,6 +229,9 @@ export class VASTTracker extends EventEmitter { if (progress < this.progress) { this.track('rewind', { macros }); + if (this.trackedProgressEvents) { + this.trackedProgressEvents.splice(0); + } } } @@ -778,12 +782,42 @@ export class VASTTracker extends EventEmitter { } } + /** + * Calls the tracking URLs for progress events for the given eventName and emits the event. + * + * @param {String} eventName - The name of the event. + * @param macros - An optional Object of parameters (vast macros) to be used in the tracking calls. + * @param once - Boolean to define if the event has to be tracked only once. + */ + trackProgressEvents(eventName, macros, once) { + const eventTime = parseFloat(eventName.split('-')[1]); + + const progressEvents = Object.entries(this.trackingEvents) + .filter(([key]) => key.startsWith('progress-')) + .map(([key, value]) => ({ name: key, time: parseFloat(key.split('-')[1]), urls: value })) + .filter(({ time }) => time <= eventTime && time > this.progress); + + progressEvents.forEach(({ name, urls }) => { + if (!once && this.trackedProgressEvents.includes(name)) { + return; + } + this.emit(name, { trackingURLTemplates: urls }); + this.trackURLs(urls, macros); + + if (once) { + delete this.trackingEvents[name]; + } else { + this.trackedProgressEvents.push(name); + } + }); + } + /** * Calls the tracking URLs for the given eventName and emits the event. * * @param {String} eventName - The name of the event. * @param {Object} options - * @param {Object} [options.macros={}] - An optional Object of parameters(vast macros) to be used in the tracking calls. + * @param {Object} [options.macros={}] - An optional Object of parameters (vast macros) to be used in the tracking calls. * @param {Boolean} [options.once=false] - Boolean to define if the event has to be tracked only once. * */ @@ -804,6 +838,10 @@ export class VASTTracker extends EventEmitter { eventName = 'close'; } + if (eventName.startsWith('progress-') && !eventName.endsWith("%")) { + this.trackProgressEvents(eventName, macros, once); + } + const trackingURLTemplates = this.trackingEvents[eventName]; const isAlwaysEmitEvent = this.emitAlwaysEvents.indexOf(eventName) > -1;