-
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added impression and quartile tracking
- Loading branch information
Showing
5 changed files
with
104 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import type { InterstitialAsset } from "./types"; | ||
|
||
interface SignalingEvent { | ||
type: "impression" | "quartile" | "clickthrough"; | ||
start?: number; | ||
urls: string[]; | ||
} | ||
|
||
const QUARTILE_EVENTS: Record<string, number> = { | ||
start: 0, | ||
firstQuartile: 0.25, | ||
midpoint: 0.5, | ||
thirdQuartile: 0.75, | ||
complete: 1, | ||
}; | ||
|
||
export function getSignalingForAsset( | ||
assets: InterstitialAsset[], | ||
asset: InterstitialAsset, | ||
) { | ||
const { duration, tracking } = asset; | ||
if (!tracking) { | ||
return null; | ||
} | ||
|
||
const assetIndex = assets.indexOf(asset); | ||
const startTime = assets.splice(0, assetIndex).reduce((acc, asset) => { | ||
acc += asset.duration; | ||
return acc; | ||
}, 0); | ||
|
||
const signalingEvents: SignalingEvent[] = []; | ||
|
||
signalingEvents.push({ | ||
type: "impression", | ||
start: 0, | ||
urls: tracking.impression, | ||
}); | ||
|
||
signalingEvents.push({ | ||
type: "clickthrough", | ||
urls: tracking.clickThrough, | ||
}); | ||
|
||
// Map each tracking URL to their corresponding quartile. | ||
Object.entries(tracking).forEach(([name, urls]) => { | ||
const offset = QUARTILE_EVENTS[name]; | ||
if (offset !== undefined) { | ||
signalingEvents.push({ | ||
type: "quartile", | ||
start: duration * offset, | ||
urls, | ||
}); | ||
} | ||
}); | ||
|
||
return { | ||
version: 2, | ||
type: "slot", | ||
payload: [ | ||
{ | ||
type: "linear", | ||
start: startTime, | ||
duration: asset.duration, | ||
tracking: signalingEvents, | ||
}, | ||
], | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters