Skip to content

Commit

Permalink
Revert "Updated adCreativeSignalingPlugin to new Signal event definit…
Browse files Browse the repository at this point in the history
…ion ignoring non supported events"

This reverts commit f5ccf63.
  • Loading branch information
jaram-qualabs committed Feb 4, 2025
1 parent f5ccf63 commit 93a85b7
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 62 deletions.
16 changes: 6 additions & 10 deletions hls.js/adCreativeSignalingPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const SUPPORTED_TRACKING_EVENTS = ["start", "firstQuartile", "midpoint", "thirdQuartile", "complete", "progress", "impression"];

class AdSignalingManager {
constructor(hls) {
console.log("Initializing AdSignalingManager");
Expand Down Expand Up @@ -39,14 +37,12 @@ class AdSignalingManager {
const currentTime = this.assetPlayer.currentTime;

this.trackingEventsQueue.forEach((event, index) => {
if (SUPPORTED_TRACKING_EVENTS.includes(event.type)) {
const tolerance = 0.75; // time difference tolerance in seconds
if (
(event?.offset === undefined || (Math.abs(currentTime - event.offset) <= tolerance))
) {
Promise.all(event.urls.map((url) => this.sendTrackingEvent(url)));
this.trackingEventsQueue.splice(index, 1);
}
const tolerance = 0.75; // time difference tolerance in seconds
if (
((Math.abs(currentTime - event.start) <= tolerance) || event?.start === undefined)
) {
Promise.all(event.urls.map((url) => this.sendTrackingEvent(url)));
this.trackingEventsQueue.splice(index, 1);
}
});
};
Expand Down
16 changes: 6 additions & 10 deletions public/hls.js/adCreativeSignalingPlugin.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const SUPPORTED_TRACKING_EVENTS = ["start", "firstQuartile", "midpoint", "thirdQuartile", "complete", "progress", "impression"];

class AdSignalingManager {
constructor(hls) {
console.log("Initializing AdSignalingManager");
Expand Down Expand Up @@ -39,14 +37,12 @@ class AdSignalingManager {
const currentTime = this.assetPlayer.currentTime;

this.trackingEventsQueue.forEach((event, index) => {
if (SUPPORTED_TRACKING_EVENTS.includes(event.type)) {
const tolerance = 0.75; // time difference tolerance in seconds
if (
(event?.offset === undefined || (Math.abs(currentTime - event.offset) <= tolerance))
) {
Promise.all(event.urls.map((url) => this.sendTrackingEvent(url)));
this.trackingEventsQueue.splice(index, 1);
}
const tolerance = 0.75; // time difference tolerance in seconds
if (
((Math.abs(currentTime - event.start) <= tolerance) || event?.start === undefined)
) {
Promise.all(event.urls.map((url) => this.sendTrackingEvent(url)));
this.trackingEventsQueue.splice(index, 1);
}
});
};
Expand Down
86 changes: 44 additions & 42 deletions src/trackingEvents/tracking-events.js
Original file line number Diff line number Diff line change
@@ -1,85 +1,87 @@
const { logger } = require("../utils/logger.js");

const IMPRESSION = "impression";
const PROGRESS = "progress";

class TrackingEvent {
constructor(type, duration, urls) {
// console.log(">>>TRACKING EVT: ", type)
// console.log(">>>TRACKING EVT: ", type)
this.type = type;
//this.duration = duration;
this.urls = urls;
//this.start = start;

if (this.type.startsWith(PROGRESS)) {
if (this.type.startsWith("progress")) {

const offsetValue = this.type.split("-")[1];
if (offsetValue !== null) {
this.offset =
this.offset =
typeof offsetValue === "string" && offsetValue.includes("%")
? (duration * parseFloat(offsetValue.replace("%", ""))) / 100
: parseFloat(offsetValue);
? (duration * parseFloat(offsetValue.replace("%", ""))) / 100
: parseFloat(offsetValue);

this.type = "progress";

this.type = PROGRESS;

if (
isNaN(this.offset) ||
this.offset < 0 ||
this.offset > this.duration
) {
throw new Error(`Invalid start value: ${offset}`);
if (isNaN(this.offset) || this.offset < 0 || this.offset > this.duration) {
throw new Error(`Invalid start value: ${offset}`);
}
}
} else {
switch (type) {
case "start":
this.offset = 0;
break;

case "firstQuartile":
this.offset = duration * 0.25;
break;

case "midpoint":
this.offset = duration * 0.5;
break;

case "thirdQuartile":
this.offset = duration * 0.75;
}
else
{
switch(type)
{
case "start":
this.offset = 0;
break;

case "firstQuartile":
this.offset = duration * 0.25;
break;

case "midpoint":
this.offset = duration * 0.5;
break;

case "thirdQuartile":
this.offset = duration * 0.75;
break;

case "complete":
this.offset = duration;
break;

case "complete":
this.offset = duration;
break;
}
}


}
}



class AdCreativeSignalingMapper {
constructor(ad) {
this.ad = ad;
console.log(">>>> Ad Tracking", this.ad.trackingEvents);
}

map() {
const newTrackingEvents = this.ad.trackingEvents;

if (this.ad?.impressions.length > 0)
newTrackingEvents[IMPRESSION] = this.ad.impressions.map(
(impression) => impression.url
);

if(this.ad?.impressions.length > 0)
newTrackingEvents[IMPRESSION] = this.ad.impressions.map((impression) => impression.url);

const trackingEvents = Object.entries(this.ad.trackingEvents)
.map(([eventType, urls]) => {
try {
const event = new TrackingEvent(eventType, this.ad.duration, urls);
const event = new TrackingEvent( eventType, this.ad.duration, urls );
//console.log(">>> track evt: ", event)
return event;
} catch (error) {
logger.warn(
`Skipping invalid event: ${eventType}, Error: ${error.message}`
);

return null;
}
})
Expand All @@ -91,5 +93,5 @@ class AdCreativeSignalingMapper {

module.exports = {
AdCreativeSignalingMapper,
TrackingEvent,
TrackingEvent
};

0 comments on commit 93a85b7

Please sign in to comment.