@streamlayer/feature-advertisement 1.1.0 → 1.1.1-rc.1342
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/classic/package.json +5 -0
- package/lib/cjs/advertisement.d.ts +64 -0
- package/lib/cjs/advertisement.js +307 -0
- package/lib/cjs/index.d.ts +19 -0
- package/lib/cjs/index.js +39 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/units/external-ad.d.ts +58 -0
- package/lib/cjs/units/external-ad.js +390 -0
- package/lib/cjs/units/external-pause-ad.d.ts +50 -0
- package/lib/cjs/units/external-pause-ad.js +253 -0
- package/lib/cjs/units/gam.d.ts +16 -0
- package/lib/cjs/units/gam.js +104 -0
- package/lib/cjs/units/parse-vast-extensions.d.ts +17 -0
- package/lib/cjs/units/parse-vast-extensions.js +52 -0
- package/lib/cjs/units/pause-ad-card.d.ts +49 -0
- package/lib/cjs/units/pause-ad-card.js +136 -0
- package/lib/cjs/units/pause-ad.d.ts +16 -0
- package/lib/cjs/units/pause-ad.js +52 -0
- package/lib/cjs/units/ssai-ad-break.d.ts +21 -0
- package/lib/cjs/units/ssai-ad-break.js +11 -0
- package/lib/cjs/units/ssai-creative.d.ts +89 -0
- package/lib/cjs/units/ssai-creative.js +136 -0
- package/lib/cjs/units/ssai-detector.d.ts +180 -0
- package/lib/cjs/units/ssai-detector.js +1156 -0
- package/lib/cjs/units/ssai-preload.d.ts +20 -0
- package/lib/cjs/units/ssai-preload.js +62 -0
- package/lib/cjs/units/ssai-providers.d.ts +117 -0
- package/lib/cjs/units/ssai-providers.js +263 -0
- package/lib/cjs/units/vast-tracker.d.ts +45 -0
- package/lib/cjs/units/vast-tracker.js +64 -0
- package/lib/classic/_virtual/_rollupPluginBabelHelpers.js +71 -0
- package/lib/classic/advertisement.js +331 -0
- package/lib/classic/cjs/_virtual/_rollupPluginBabelHelpers.js +77 -0
- package/lib/classic/cjs/advertisement.js +333 -0
- package/lib/classic/cjs/index.js +47 -0
- package/lib/classic/cjs/package.json +1 -0
- package/lib/classic/cjs/units/external-ad.js +453 -0
- package/lib/classic/cjs/units/external-pause-ad.js +274 -0
- package/lib/classic/cjs/units/gam.js +110 -0
- package/lib/classic/cjs/units/parse-vast-extensions.js +56 -0
- package/lib/classic/cjs/units/pause-ad-card.js +134 -0
- package/lib/classic/cjs/units/pause-ad.js +72 -0
- package/lib/classic/cjs/units/ssai-ad-break.js +11 -0
- package/lib/classic/cjs/units/ssai-creative.js +142 -0
- package/lib/classic/cjs/units/ssai-detector.js +1170 -0
- package/lib/classic/cjs/units/ssai-preload.js +72 -0
- package/lib/classic/cjs/units/ssai-providers.js +299 -0
- package/lib/classic/cjs/units/vast-tracker.js +81 -0
- package/lib/classic/index.js +28 -0
- package/lib/classic/units/external-ad.js +447 -0
- package/lib/classic/units/external-pause-ad.js +271 -0
- package/lib/classic/units/gam.js +108 -0
- package/lib/classic/units/parse-vast-extensions.js +54 -0
- package/lib/classic/units/pause-ad-card.js +131 -0
- package/lib/classic/units/pause-ad.js +70 -0
- package/lib/classic/units/ssai-ad-break.js +9 -0
- package/lib/classic/units/ssai-creative.js +140 -0
- package/lib/classic/units/ssai-detector.js +1167 -0
- package/lib/classic/units/ssai-preload.js +68 -0
- package/lib/classic/units/ssai-providers.js +289 -0
- package/lib/classic/units/vast-tracker.js +77 -0
- package/package.json +41 -8
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { SsaiCreative } from './ssai-creative';
|
|
2
|
+
/**
|
|
3
|
+
* How long the overlay is willing to wait for artwork. A slow or dead image host
|
|
4
|
+
* must never hold the bar back — the ad is already playing, and a bar that shows
|
|
5
|
+
* late is worse than one that shows without its logo (the logo is hidden on error
|
|
6
|
+
* anyway). Warming the browser cache is the goal; blocking is not.
|
|
7
|
+
*/
|
|
8
|
+
export declare const DEFAULT_PRELOAD_TIMEOUT_MS = 2000;
|
|
9
|
+
/**
|
|
10
|
+
* Fetch images into the browser cache and resolve once they are all settled, or
|
|
11
|
+
* once `timeoutMs` elapses — whichever comes first. Never rejects: a creative
|
|
12
|
+
* whose artwork fails is still a creative worth showing.
|
|
13
|
+
*/
|
|
14
|
+
export declare const preloadImages: (urls: (string | undefined | null)[], timeoutMs?: number) => Promise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* Warm every image the creative carries — the overlay's brand logo, and the
|
|
17
|
+
* companion banner for hosts that render one — so the bar fades in complete
|
|
18
|
+
* rather than popping its artwork in a beat later.
|
|
19
|
+
*/
|
|
20
|
+
export declare const preloadCreativeAssets: (creative: SsaiCreative, timeoutMs?: number) => Promise<void>;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sdkWebLogger = require('@streamlayer/sdk-web-logger');
|
|
4
|
+
|
|
5
|
+
const log = sdkWebLogger.createLogger('ssai:preload');
|
|
6
|
+
/**
|
|
7
|
+
* How long the overlay is willing to wait for artwork. A slow or dead image host
|
|
8
|
+
* must never hold the bar back — the ad is already playing, and a bar that shows
|
|
9
|
+
* late is worse than one that shows without its logo (the logo is hidden on error
|
|
10
|
+
* anyway). Warming the browser cache is the goal; blocking is not.
|
|
11
|
+
*/
|
|
12
|
+
const DEFAULT_PRELOAD_TIMEOUT_MS = 2000;
|
|
13
|
+
/**
|
|
14
|
+
* Fetch images into the browser cache and resolve once they are all settled, or
|
|
15
|
+
* once `timeoutMs` elapses — whichever comes first. Never rejects: a creative
|
|
16
|
+
* whose artwork fails is still a creative worth showing.
|
|
17
|
+
*/
|
|
18
|
+
const preloadImages = (urls, timeoutMs = DEFAULT_PRELOAD_TIMEOUT_MS) => {
|
|
19
|
+
const targets = urls.filter((url) => !!url);
|
|
20
|
+
// `Image` is absent in SSR/worker contexts; there is nothing to warm there.
|
|
21
|
+
if (targets.length === 0 || typeof Image === 'undefined') {
|
|
22
|
+
return Promise.resolve();
|
|
23
|
+
}
|
|
24
|
+
return new Promise((resolve) => {
|
|
25
|
+
let settled = false;
|
|
26
|
+
let remaining = targets.length;
|
|
27
|
+
const finish = () => {
|
|
28
|
+
if (settled) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
settled = true;
|
|
32
|
+
clearTimeout(timer);
|
|
33
|
+
resolve();
|
|
34
|
+
};
|
|
35
|
+
const timer = setTimeout(() => {
|
|
36
|
+
log.debug({ remaining }, 'ssai preload timed out, showing anyway');
|
|
37
|
+
finish();
|
|
38
|
+
}, timeoutMs);
|
|
39
|
+
const one = () => {
|
|
40
|
+
remaining -= 1;
|
|
41
|
+
if (remaining <= 0) {
|
|
42
|
+
finish();
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
for (const url of targets) {
|
|
46
|
+
const image = new Image();
|
|
47
|
+
image.onload = one;
|
|
48
|
+
image.onerror = one;
|
|
49
|
+
image.src = url;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Warm every image the creative carries — the overlay's brand logo, and the
|
|
55
|
+
* companion banner for hosts that render one — so the bar fades in complete
|
|
56
|
+
* rather than popping its artwork in a beat later.
|
|
57
|
+
*/
|
|
58
|
+
const preloadCreativeAssets = (creative, timeoutMs) => preloadImages([creative.iconUrl, creative.companion?.staticResource], timeoutMs);
|
|
59
|
+
|
|
60
|
+
exports.DEFAULT_PRELOAD_TIMEOUT_MS = DEFAULT_PRELOAD_TIMEOUT_MS;
|
|
61
|
+
exports.preloadCreativeAssets = preloadCreativeAssets;
|
|
62
|
+
exports.preloadImages = preloadImages;
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import type { SsaiCreative } from './ssai-creative';
|
|
2
|
+
export declare const DEFAULT_CREATIVE_API_BASE = "https://hls.next.streamlayer.io/api/creatives/";
|
|
3
|
+
/**
|
|
4
|
+
* A creative provider encapsulates everything that differs between ad sources:
|
|
5
|
+
* how a creativeId resolves to the normalized {@link SsaiCreative}, and how
|
|
6
|
+
* impressions (and, in the future, other tracking events) are fired. The overlay
|
|
7
|
+
* UI only ever sees the normalized shape, so it never learns about providers.
|
|
8
|
+
*/
|
|
9
|
+
export interface SsaiCreativeProvider {
|
|
10
|
+
/** Stable id for logging/diagnostics, e.g. 'streamlayer' | 'vast'. */
|
|
11
|
+
readonly id: string;
|
|
12
|
+
/** Resolve a creativeId (from EXT-X-DATERANGE) to the normalized SsaiCreative. */
|
|
13
|
+
resolve(creativeId: string, signal: AbortSignal): Promise<SsaiCreative>;
|
|
14
|
+
/**
|
|
15
|
+
* Fire an impression for a resolved creative. Provider-specific (URL shape,
|
|
16
|
+
* beacon vs pixel vs SDK call). Optional — falls back to the shared default
|
|
17
|
+
* (first trackingEvent named 'impression' via sendBeacon/fetch) when omitted.
|
|
18
|
+
*/
|
|
19
|
+
fireImpression?(creative: SsaiCreative): void;
|
|
20
|
+
/** Optional hook for other tracking events (click, quartiles) — future-facing, no-op default. */
|
|
21
|
+
fireTracking?(creative: SsaiCreative, event: string): void;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Shared low-level beacon helper. Prefers `navigator.sendBeacon` and falls back
|
|
25
|
+
* to a no-cors `fetch`. Used by the default impression path and available to
|
|
26
|
+
* providers that fire URL-based tracking pixels.
|
|
27
|
+
*/
|
|
28
|
+
export declare const fireBeacon: (url: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Fire every tracking event with the given name, and report how many went out.
|
|
31
|
+
*
|
|
32
|
+
* ALL matches, not the first: the creative contract states that a creative may
|
|
33
|
+
* repeat an `event` value to carry several URLs, and that consumers must not
|
|
34
|
+
* assume uniqueness. Today's payloads carry one URL per event, so this is not a
|
|
35
|
+
* change in what goes on the wire — it just stops being wrong the day a server
|
|
36
|
+
* sends two.
|
|
37
|
+
*/
|
|
38
|
+
export declare const fireTrackingEvents: (creative: SsaiCreative, event: string) => number;
|
|
39
|
+
/**
|
|
40
|
+
* Shared default impression behavior: fire the `impression` tracking events.
|
|
41
|
+
* Used by the StreamLayer provider and as the fallback in
|
|
42
|
+
* {@link SsaiCreativeCache} when a provider doesn't override `fireImpression`.
|
|
43
|
+
* Exported so both call sites share one definition.
|
|
44
|
+
*/
|
|
45
|
+
export declare const fireDefaultImpression: (creative: SsaiCreative) => void;
|
|
46
|
+
export type StreamLayerProviderConfig = {
|
|
47
|
+
/** Base URL of the StreamLayer JSON creative metadata API. */
|
|
48
|
+
creativeApiBase?: string;
|
|
49
|
+
};
|
|
50
|
+
/**
|
|
51
|
+
* StreamLayer's internal creative provider. Resolves creatives from the JSON
|
|
52
|
+
* creative API (`GET {creativeApiBase}{encodeURIComponent(creativeId)}`) and
|
|
53
|
+
* fires impressions from the `'impression'` tracking event via `sendBeacon`.
|
|
54
|
+
*/
|
|
55
|
+
export declare const createStreamLayerProvider: (config?: StreamLayerProviderConfig) => SsaiCreativeProvider;
|
|
56
|
+
export type QuortexProviderConfig = {
|
|
57
|
+
/**
|
|
58
|
+
* Full URL of the tenant's ad metadata endpoint, e.g.
|
|
59
|
+
* `https://ads.example.com/get_ad` or, with the tenant baked in,
|
|
60
|
+
* `https://ads.example.com/get_ad?TenantName=acme`. Required — this is
|
|
61
|
+
* customer infrastructure, so there is no sensible SDK-level default.
|
|
62
|
+
*/
|
|
63
|
+
adApiBase?: string;
|
|
64
|
+
/**
|
|
65
|
+
* Tenant the ad ids belong to, appended as the `TenantName` query parameter.
|
|
66
|
+
* Optional: omit it when `adApiBase` already carries the tenant.
|
|
67
|
+
*/
|
|
68
|
+
tenantName?: string;
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Quortex / Synamedia DAI ad metadata provider.
|
|
72
|
+
*
|
|
73
|
+
* `GET {adApiBase}?TenantName={tenantName}&adID={adId}&info=1` (the `TenantName`
|
|
74
|
+
* part omitted when `adApiBase` already carries it) — the ad id comes
|
|
75
|
+
* from the manifest's `X-AD-ID` DATERANGE attribute (see `ssai-detector.ts`, which
|
|
76
|
+
* reconstructs the ad window from the tracking-marker burst those tags form).
|
|
77
|
+
*
|
|
78
|
+
* The response is byte-compatible with the StreamLayer creative API, so the same
|
|
79
|
+
* `mapApiResponse` normalizes both.
|
|
80
|
+
*
|
|
81
|
+
* Known limitation: impressions fire the `impression` tracking event from the API
|
|
82
|
+
* response, not the per-session beacon the manifest carries in `X-AD-URL`. The two
|
|
83
|
+
* differ in `trackingid`/`USERID`, so Quortex-side attribution will see the
|
|
84
|
+
* generic id rather than the viewer's session until the manifest beacons are
|
|
85
|
+
* plumbed through to the provider.
|
|
86
|
+
*/
|
|
87
|
+
export declare const createQuortexProvider: (config?: QuortexProviderConfig) => SsaiCreativeProvider;
|
|
88
|
+
export type VastProviderConfig = Record<string, never>;
|
|
89
|
+
/**
|
|
90
|
+
* Maps a VAST tag into the normalized SsaiCreative shape.
|
|
91
|
+
*
|
|
92
|
+
* Note: `fireImpression` is intentionally left to the shared default for now.
|
|
93
|
+
* Proper VAST impression/tracking wiring through `VASTTracker` is a documented
|
|
94
|
+
* follow-up; it requires retaining the parsed ad/tracker per creative.
|
|
95
|
+
*/
|
|
96
|
+
export declare const createVastProvider: (_config?: VastProviderConfig) => SsaiCreativeProvider;
|
|
97
|
+
export type SsaiProviderName = 'streamlayer' | 'quortex' | 'vast';
|
|
98
|
+
/** Union of every built-in provider's config; each factory reads its own keys. */
|
|
99
|
+
export type SsaiProviderConfig = StreamLayerProviderConfig & QuortexProviderConfig;
|
|
100
|
+
/** Built-in provider factories keyed by name. */
|
|
101
|
+
export declare const BUILTIN_PROVIDERS: Record<SsaiProviderName, (config?: SsaiProviderConfig) => SsaiCreativeProvider>;
|
|
102
|
+
export type SsaiProviderOption =
|
|
103
|
+
/** A ready provider instance (built-in or fully custom). */
|
|
104
|
+
SsaiCreativeProvider
|
|
105
|
+
/** A built-in provider selected by name. */
|
|
106
|
+
| SsaiProviderName
|
|
107
|
+
/** A built-in provider selected by name with optional config. */
|
|
108
|
+
| {
|
|
109
|
+
name: SsaiProviderName;
|
|
110
|
+
config?: SsaiProviderConfig;
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Resolve a {@link SsaiProviderOption} into a concrete {@link SsaiCreativeProvider}.
|
|
114
|
+
* Defaults to the StreamLayer provider (using `fallbackConfig`) when no option is
|
|
115
|
+
* supplied.
|
|
116
|
+
*/
|
|
117
|
+
export declare const resolveProvider: (option?: SsaiProviderOption, fallbackConfig?: SsaiProviderConfig) => SsaiCreativeProvider;
|
|
@@ -0,0 +1,263 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var sdkWebLogger = require('@streamlayer/sdk-web-logger');
|
|
4
|
+
var vastClient = require('@dailymotion/vast-client');
|
|
5
|
+
|
|
6
|
+
const log = sdkWebLogger.createLogger('ssai:provider');
|
|
7
|
+
const DEFAULT_CREATIVE_API_BASE = 'https://hls.next.streamlayer.io/api/creatives/';
|
|
8
|
+
/**
|
|
9
|
+
* Shared low-level beacon helper. Prefers `navigator.sendBeacon` and falls back
|
|
10
|
+
* to a no-cors `fetch`. Used by the default impression path and available to
|
|
11
|
+
* providers that fire URL-based tracking pixels.
|
|
12
|
+
*/
|
|
13
|
+
const fireBeacon = (url) => {
|
|
14
|
+
try {
|
|
15
|
+
if (typeof navigator !== 'undefined' && typeof navigator.sendBeacon === 'function') {
|
|
16
|
+
navigator.sendBeacon(url);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
void fetch(url, { mode: 'no-cors' }).catch((error) => {
|
|
20
|
+
log.warn(error, 'ssai beacon failed');
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
catch (error) {
|
|
25
|
+
log.warn(error, 'ssai beacon failed');
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const resolveAdvertiser = (advertiser, title) => {
|
|
29
|
+
if (advertiser) {
|
|
30
|
+
return advertiser;
|
|
31
|
+
}
|
|
32
|
+
if (title) {
|
|
33
|
+
return title;
|
|
34
|
+
}
|
|
35
|
+
return 'Ad';
|
|
36
|
+
};
|
|
37
|
+
const buildCreativeUrl = (base, creativeId) => {
|
|
38
|
+
const normalizedBase = base.endsWith('/') ? base : `${base}/`;
|
|
39
|
+
return `${normalizedBase}${encodeURIComponent(creativeId)}`;
|
|
40
|
+
};
|
|
41
|
+
const mapApiResponse = (raw) => {
|
|
42
|
+
const trackingEvents = Array.isArray(raw.trackingEvents)
|
|
43
|
+
? raw.trackingEvents
|
|
44
|
+
.filter((entry) => Boolean(entry?.event && entry?.url))
|
|
45
|
+
.map((entry) => ({ event: entry.event, url: entry.url }))
|
|
46
|
+
: [];
|
|
47
|
+
const rawCompanion = Array.isArray(raw.companions)
|
|
48
|
+
? raw.companions.find((entry) => !!entry?.staticResource)
|
|
49
|
+
: undefined;
|
|
50
|
+
const companion = rawCompanion?.staticResource
|
|
51
|
+
? {
|
|
52
|
+
staticResource: rawCompanion.staticResource,
|
|
53
|
+
width: Number(rawCompanion.width) || 0,
|
|
54
|
+
height: Number(rawCompanion.height) || 0,
|
|
55
|
+
clickThrough: rawCompanion.clickThrough,
|
|
56
|
+
clickTracking: Array.isArray(rawCompanion.clickTracking)
|
|
57
|
+
? rawCompanion.clickTracking.filter((url) => typeof url === 'string' && !!url)
|
|
58
|
+
: [],
|
|
59
|
+
}
|
|
60
|
+
: undefined;
|
|
61
|
+
return {
|
|
62
|
+
creativeId: raw.creativeId,
|
|
63
|
+
advertiser: resolveAdvertiser(raw.advertiser, raw.title),
|
|
64
|
+
title: raw.title || resolveAdvertiser(raw.advertiser, raw.title),
|
|
65
|
+
iconUrl: raw.iconUrl || undefined,
|
|
66
|
+
clickThroughUrl: raw.clickThroughUrl || undefined,
|
|
67
|
+
trackingEvents,
|
|
68
|
+
companion,
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Fire every tracking event with the given name, and report how many went out.
|
|
73
|
+
*
|
|
74
|
+
* ALL matches, not the first: the creative contract states that a creative may
|
|
75
|
+
* repeat an `event` value to carry several URLs, and that consumers must not
|
|
76
|
+
* assume uniqueness. Today's payloads carry one URL per event, so this is not a
|
|
77
|
+
* change in what goes on the wire — it just stops being wrong the day a server
|
|
78
|
+
* sends two.
|
|
79
|
+
*/
|
|
80
|
+
const fireTrackingEvents = (creative, event) => {
|
|
81
|
+
const matches = creative.trackingEvents.filter((entry) => entry.event === event);
|
|
82
|
+
for (const match of matches) {
|
|
83
|
+
fireBeacon(match.url);
|
|
84
|
+
}
|
|
85
|
+
return matches.length;
|
|
86
|
+
};
|
|
87
|
+
/**
|
|
88
|
+
* Shared default impression behavior: fire the `impression` tracking events.
|
|
89
|
+
* Used by the StreamLayer provider and as the fallback in
|
|
90
|
+
* {@link SsaiCreativeCache} when a provider doesn't override `fireImpression`.
|
|
91
|
+
* Exported so both call sites share one definition.
|
|
92
|
+
*/
|
|
93
|
+
const fireDefaultImpression = (creative) => {
|
|
94
|
+
fireTrackingEvents(creative, 'impression');
|
|
95
|
+
};
|
|
96
|
+
/**
|
|
97
|
+
* StreamLayer's internal creative provider. Resolves creatives from the JSON
|
|
98
|
+
* creative API (`GET {creativeApiBase}{encodeURIComponent(creativeId)}`) and
|
|
99
|
+
* fires impressions from the `'impression'` tracking event via `sendBeacon`.
|
|
100
|
+
*/
|
|
101
|
+
const createStreamLayerProvider = (config = {}) => {
|
|
102
|
+
const creativeApiBase = config.creativeApiBase ?? DEFAULT_CREATIVE_API_BASE;
|
|
103
|
+
return {
|
|
104
|
+
id: 'streamlayer',
|
|
105
|
+
resolve: async (creativeId, signal) => {
|
|
106
|
+
const url = buildCreativeUrl(creativeApiBase, creativeId);
|
|
107
|
+
const response = await fetch(url, { signal });
|
|
108
|
+
if (!response.ok) {
|
|
109
|
+
throw new Error(`creative request failed: ${response.status}`);
|
|
110
|
+
}
|
|
111
|
+
const raw = (await response.json());
|
|
112
|
+
return mapApiResponse({ ...raw, creativeId: raw.creativeId || creativeId });
|
|
113
|
+
},
|
|
114
|
+
fireImpression: fireDefaultImpression,
|
|
115
|
+
};
|
|
116
|
+
};
|
|
117
|
+
const buildQuortexUrl = (base, tenantName, adId) => {
|
|
118
|
+
// Deliberately string concatenation rather than `URL`/`URLSearchParams`: this
|
|
119
|
+
// package ships to 2016-era TV engines (see the chrome-32 classic build).
|
|
120
|
+
const separator = base.indexOf('?') === -1 ? '?' : '&';
|
|
121
|
+
const tenant = tenantName ? `TenantName=${encodeURIComponent(tenantName)}&` : '';
|
|
122
|
+
return `${base}${separator}${tenant}adID=${encodeURIComponent(adId)}&info=1`;
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* Quortex / Synamedia DAI ad metadata provider.
|
|
126
|
+
*
|
|
127
|
+
* `GET {adApiBase}?TenantName={tenantName}&adID={adId}&info=1` (the `TenantName`
|
|
128
|
+
* part omitted when `adApiBase` already carries it) — the ad id comes
|
|
129
|
+
* from the manifest's `X-AD-ID` DATERANGE attribute (see `ssai-detector.ts`, which
|
|
130
|
+
* reconstructs the ad window from the tracking-marker burst those tags form).
|
|
131
|
+
*
|
|
132
|
+
* The response is byte-compatible with the StreamLayer creative API, so the same
|
|
133
|
+
* `mapApiResponse` normalizes both.
|
|
134
|
+
*
|
|
135
|
+
* Known limitation: impressions fire the `impression` tracking event from the API
|
|
136
|
+
* response, not the per-session beacon the manifest carries in `X-AD-URL`. The two
|
|
137
|
+
* differ in `trackingid`/`USERID`, so Quortex-side attribution will see the
|
|
138
|
+
* generic id rather than the viewer's session until the manifest beacons are
|
|
139
|
+
* plumbed through to the provider.
|
|
140
|
+
*/
|
|
141
|
+
const createQuortexProvider = (config = {}) => {
|
|
142
|
+
const { adApiBase, tenantName } = config;
|
|
143
|
+
if (!adApiBase) {
|
|
144
|
+
// Loud, but not thrown: this runs inside the host's render effect via
|
|
145
|
+
// `startSsaiMonitoring`, and taking the app down over a config typo is worse
|
|
146
|
+
// than an overlay that never appears and says why.
|
|
147
|
+
log.error({ adApiBase, tenantName }, 'quortex provider requires `adApiBase`');
|
|
148
|
+
}
|
|
149
|
+
return {
|
|
150
|
+
id: 'quortex',
|
|
151
|
+
resolve: async (adId, signal) => {
|
|
152
|
+
if (!adApiBase) {
|
|
153
|
+
throw new Error('quortex provider is missing `adApiBase`');
|
|
154
|
+
}
|
|
155
|
+
const response = await fetch(buildQuortexUrl(adApiBase, tenantName, adId), { signal });
|
|
156
|
+
if (!response.ok) {
|
|
157
|
+
throw new Error(`quortex creative request failed: ${response.status}`);
|
|
158
|
+
}
|
|
159
|
+
const raw = (await response.json());
|
|
160
|
+
return mapApiResponse({ ...raw, creativeId: raw.creativeId || adId });
|
|
161
|
+
},
|
|
162
|
+
fireImpression: fireDefaultImpression,
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
// --- VAST provider ---------------------------------------------------------
|
|
166
|
+
const mapVastResponse = async (creativeId, signal) => {
|
|
167
|
+
const vastClient$1 = new vastClient.VASTClient();
|
|
168
|
+
const parsedVAST = await vastClient$1.get(creativeId, { timeout: 8000 });
|
|
169
|
+
if (signal.aborted) {
|
|
170
|
+
throw new DOMException('aborted', 'AbortError');
|
|
171
|
+
}
|
|
172
|
+
const validAd = parsedVAST.ads.find((ad) => ad.creatives.length > 0);
|
|
173
|
+
if (!validAd) {
|
|
174
|
+
throw new Error('no_valid_ad');
|
|
175
|
+
}
|
|
176
|
+
const advertiserValue = Array.isArray(validAd.advertiser)
|
|
177
|
+
? validAd.advertiser.find((entry) => !!entry?.value)?.value
|
|
178
|
+
: undefined;
|
|
179
|
+
const advertiser = resolveAdvertiser(advertiserValue, validAd.title || undefined);
|
|
180
|
+
let iconUrl;
|
|
181
|
+
let clickThroughUrl;
|
|
182
|
+
let companion;
|
|
183
|
+
for (const creative of validAd.creatives) {
|
|
184
|
+
if (creative.type === 'linear') {
|
|
185
|
+
const linear = creative;
|
|
186
|
+
iconUrl = iconUrl || linear.icons?.find((icon) => !!icon?.staticResource)?.staticResource || undefined;
|
|
187
|
+
clickThroughUrl = clickThroughUrl || linear.videoClickThroughURLTemplate?.url;
|
|
188
|
+
}
|
|
189
|
+
if (creative.type === 'companion') {
|
|
190
|
+
const variation = creative.variations?.[0];
|
|
191
|
+
const staticResource = variation?.staticResources?.[0]?.url;
|
|
192
|
+
if (staticResource && !companion) {
|
|
193
|
+
companion = {
|
|
194
|
+
staticResource,
|
|
195
|
+
width: Number(variation?.width) || 0,
|
|
196
|
+
height: Number(variation?.height) || 0,
|
|
197
|
+
clickThrough: variation?.companionClickThroughURLTemplate?.url,
|
|
198
|
+
clickTracking: (variation?.companionClickTrackingURLTemplates ?? [])
|
|
199
|
+
.map((entry) => entry?.url)
|
|
200
|
+
.filter((url) => !!url),
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return {
|
|
206
|
+
creativeId,
|
|
207
|
+
advertiser,
|
|
208
|
+
title: validAd.title || advertiser,
|
|
209
|
+
iconUrl,
|
|
210
|
+
clickThroughUrl,
|
|
211
|
+
trackingEvents: [],
|
|
212
|
+
companion,
|
|
213
|
+
};
|
|
214
|
+
};
|
|
215
|
+
/**
|
|
216
|
+
* Maps a VAST tag into the normalized SsaiCreative shape.
|
|
217
|
+
*
|
|
218
|
+
* Note: `fireImpression` is intentionally left to the shared default for now.
|
|
219
|
+
* Proper VAST impression/tracking wiring through `VASTTracker` is a documented
|
|
220
|
+
* follow-up; it requires retaining the parsed ad/tracker per creative.
|
|
221
|
+
*/
|
|
222
|
+
const createVastProvider = (_config = {}) => {
|
|
223
|
+
return {
|
|
224
|
+
id: 'vast',
|
|
225
|
+
resolve: mapVastResponse,
|
|
226
|
+
};
|
|
227
|
+
};
|
|
228
|
+
/** Built-in provider factories keyed by name. */
|
|
229
|
+
const BUILTIN_PROVIDERS = {
|
|
230
|
+
streamlayer: (config) => createStreamLayerProvider(config),
|
|
231
|
+
quortex: (config) => createQuortexProvider(config),
|
|
232
|
+
vast: () => createVastProvider(),
|
|
233
|
+
};
|
|
234
|
+
const isProviderInstance = (option) => {
|
|
235
|
+
return typeof option === 'object' && typeof option.resolve === 'function';
|
|
236
|
+
};
|
|
237
|
+
/**
|
|
238
|
+
* Resolve a {@link SsaiProviderOption} into a concrete {@link SsaiCreativeProvider}.
|
|
239
|
+
* Defaults to the StreamLayer provider (using `fallbackConfig`) when no option is
|
|
240
|
+
* supplied.
|
|
241
|
+
*/
|
|
242
|
+
const resolveProvider = (option, fallbackConfig) => {
|
|
243
|
+
if (!option) {
|
|
244
|
+
return createStreamLayerProvider(fallbackConfig);
|
|
245
|
+
}
|
|
246
|
+
if (typeof option === 'string') {
|
|
247
|
+
return BUILTIN_PROVIDERS[option](fallbackConfig);
|
|
248
|
+
}
|
|
249
|
+
if (isProviderInstance(option)) {
|
|
250
|
+
return option;
|
|
251
|
+
}
|
|
252
|
+
return BUILTIN_PROVIDERS[option.name](option.config ?? fallbackConfig);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
exports.BUILTIN_PROVIDERS = BUILTIN_PROVIDERS;
|
|
256
|
+
exports.DEFAULT_CREATIVE_API_BASE = DEFAULT_CREATIVE_API_BASE;
|
|
257
|
+
exports.createQuortexProvider = createQuortexProvider;
|
|
258
|
+
exports.createStreamLayerProvider = createStreamLayerProvider;
|
|
259
|
+
exports.createVastProvider = createVastProvider;
|
|
260
|
+
exports.fireBeacon = fireBeacon;
|
|
261
|
+
exports.fireDefaultImpression = fireDefaultImpression;
|
|
262
|
+
exports.fireTrackingEvents = fireTrackingEvents;
|
|
263
|
+
exports.resolveProvider = resolveProvider;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One place that constructs a `VASTTracker`.
|
|
3
|
+
*
|
|
4
|
+
* Every StreamLayer surface that reports VAST beacons — the GAM video player, both pause-ad
|
|
5
|
+
* renderers and the Standard Ad sidebar — needs the same `(ad, creative, variation)` triple, and
|
|
6
|
+
* each was assembling it by hand behind its own `@ts-ignore`. The parsed shapes those triples
|
|
7
|
+
* come from (`AdData` / `AdCompanion` / `AdNonLinear`) are defined in this package, so the
|
|
8
|
+
* mapping belongs here too.
|
|
9
|
+
*
|
|
10
|
+
* Deliberately *only* construction: when a beacon may fire, and how a surface de-duplicates its
|
|
11
|
+
* impression, stays with that surface. Those policies differ on purpose (per-ad-id in module
|
|
12
|
+
* scope for the sidebar, per component instance for the pause ads, per tracker identity for the
|
|
13
|
+
* player) and they are billing-visible, so collapsing them here would silently change counts.
|
|
14
|
+
*/
|
|
15
|
+
import { VASTTracker, VastAd, VastCompanionAd, VastCreativeCompanion, VastCreativeLinear, VastCreativeNonLinear, VastNonLinearAd } from '@dailymotion/vast-client';
|
|
16
|
+
import type { AdCompanion, AdData } from './external-ad';
|
|
17
|
+
/** The creative (and, for non-linear creatives, the variation) a tracker reports through. */
|
|
18
|
+
export type VastTrackerTarget = {
|
|
19
|
+
ad: VastAd;
|
|
20
|
+
/** `<Linear>`, `<NonLinearAds>` or `<CompanionAds>` — whichever owns the `<TrackingEvents>`. */
|
|
21
|
+
creative: VastCreativeLinear | VastCreativeNonLinear | VastCreativeCompanion;
|
|
22
|
+
/**
|
|
23
|
+
* The `<NonLinear>` / `<Companion>` variation. Omitted for a linear creative; required for the
|
|
24
|
+
* others, since the variation is what owns their `creativeView`, click-through and click
|
|
25
|
+
* trackers.
|
|
26
|
+
*/
|
|
27
|
+
variation?: VastNonLinearAd | VastCompanionAd;
|
|
28
|
+
};
|
|
29
|
+
export declare const createVastTracker: ({ ad, creative, variation }: VastTrackerTarget) => VASTTracker;
|
|
30
|
+
/**
|
|
31
|
+
* A tracker for a single `<Companion>`. A `<CompanionAds>` creative has no creative-level
|
|
32
|
+
* `<TrackingEvents>` — each variation owns its own `creativeView` — so a companion is reported
|
|
33
|
+
* through its own tracker. `undefined` when the companion was parsed without them (nothing to
|
|
34
|
+
* report against).
|
|
35
|
+
*/
|
|
36
|
+
export declare const createCompanionTracker: (ad: VastAd, companion: AdCompanion) => VASTTracker | undefined;
|
|
37
|
+
/**
|
|
38
|
+
* The creative a parsed ad reports its impression / playback beacons through, in the order the
|
|
39
|
+
* shells draw them: the `<Linear>` creative first, then the `<NonLinear>` still, then — for a tag
|
|
40
|
+
* whose only creative is `<CompanionAds>` — the companion that was actually drawn.
|
|
41
|
+
*
|
|
42
|
+
* `drawnCompanion` is a parameter rather than `adData.companion` because only the rendering shell
|
|
43
|
+
* knows which companion reached the screen, and reporting one that did not is a false view.
|
|
44
|
+
*/
|
|
45
|
+
export declare const resolveVastTrackerTarget: (adData: AdData, drawnCompanion?: AdCompanion) => VastTrackerTarget | undefined;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var vastClient = require('@dailymotion/vast-client');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One place that constructs a `VASTTracker`.
|
|
7
|
+
*
|
|
8
|
+
* Every StreamLayer surface that reports VAST beacons — the GAM video player, both pause-ad
|
|
9
|
+
* renderers and the Standard Ad sidebar — needs the same `(ad, creative, variation)` triple, and
|
|
10
|
+
* each was assembling it by hand behind its own `@ts-ignore`. The parsed shapes those triples
|
|
11
|
+
* come from (`AdData` / `AdCompanion` / `AdNonLinear`) are defined in this package, so the
|
|
12
|
+
* mapping belongs here too.
|
|
13
|
+
*
|
|
14
|
+
* Deliberately *only* construction: when a beacon may fire, and how a surface de-duplicates its
|
|
15
|
+
* impression, stays with that surface. Those policies differ on purpose (per-ad-id in module
|
|
16
|
+
* scope for the sidebar, per component instance for the pause ads, per tracker identity for the
|
|
17
|
+
* player) and they are billing-visible, so collapsing them here would silently change counts.
|
|
18
|
+
*/
|
|
19
|
+
// eslint-disable-next-line @typescript-eslint/triple-slash-reference
|
|
20
|
+
/// <reference path="../module.d.ts" />
|
|
21
|
+
const createVastTracker = ({ ad, creative, variation }) =>
|
|
22
|
+
// The first argument is the `VASTClient` the tracker may update; every surface here drives
|
|
23
|
+
// playback itself and only wants the beacons, so it is always `null`.
|
|
24
|
+
//
|
|
25
|
+
// The type shim declares the 3rd argument as `VastCreativeLinear` and the 4th as another
|
|
26
|
+
// *creative*. At runtime `vast-client` accepts any creative in the 3rd and expects the
|
|
27
|
+
// `<Companion>` / `<NonLinear>` *variation* in the 4th. The casts encode that runtime contract
|
|
28
|
+
// once here rather than at every call site.
|
|
29
|
+
new vastClient.VASTTracker(null, ad, creative, variation);
|
|
30
|
+
/**
|
|
31
|
+
* A tracker for a single `<Companion>`. A `<CompanionAds>` creative has no creative-level
|
|
32
|
+
* `<TrackingEvents>` — each variation owns its own `creativeView` — so a companion is reported
|
|
33
|
+
* through its own tracker. `undefined` when the companion was parsed without them (nothing to
|
|
34
|
+
* report against).
|
|
35
|
+
*/
|
|
36
|
+
const createCompanionTracker = (ad, companion) => companion.creative && companion.variation
|
|
37
|
+
? createVastTracker({ ad, creative: companion.creative, variation: companion.variation })
|
|
38
|
+
: undefined;
|
|
39
|
+
/**
|
|
40
|
+
* The creative a parsed ad reports its impression / playback beacons through, in the order the
|
|
41
|
+
* shells draw them: the `<Linear>` creative first, then the `<NonLinear>` still, then — for a tag
|
|
42
|
+
* whose only creative is `<CompanionAds>` — the companion that was actually drawn.
|
|
43
|
+
*
|
|
44
|
+
* `drawnCompanion` is a parameter rather than `adData.companion` because only the rendering shell
|
|
45
|
+
* knows which companion reached the screen, and reporting one that did not is a false view.
|
|
46
|
+
*/
|
|
47
|
+
const resolveVastTrackerTarget = (adData, drawnCompanion) => {
|
|
48
|
+
// `AdData.creative` is not optional in the type but `getCreative` can return nothing: a
|
|
49
|
+
// programmatic tag does not have to carry a `<Linear>` creative.
|
|
50
|
+
if (adData.creative) {
|
|
51
|
+
return { ad: adData.ad, creative: adData.creative };
|
|
52
|
+
}
|
|
53
|
+
if (adData.nonLinear) {
|
|
54
|
+
return { ad: adData.ad, creative: adData.nonLinear.creative, variation: adData.nonLinear.variation };
|
|
55
|
+
}
|
|
56
|
+
if (drawnCompanion?.creative && drawnCompanion.variation) {
|
|
57
|
+
return { ad: adData.ad, creative: drawnCompanion.creative, variation: drawnCompanion.variation };
|
|
58
|
+
}
|
|
59
|
+
return undefined;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
exports.createCompanionTracker = createCompanionTracker;
|
|
63
|
+
exports.createVastTracker = createVastTracker;
|
|
64
|
+
exports.resolveVastTrackerTarget = resolveVastTrackerTarget;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
function asyncGeneratorStep(n, t, e, r, o, a, c) {
|
|
2
|
+
try {
|
|
3
|
+
var i = n[a](c),
|
|
4
|
+
u = i.value;
|
|
5
|
+
} catch (n) {
|
|
6
|
+
return void e(n);
|
|
7
|
+
}
|
|
8
|
+
i.done ? t(u) : Promise.resolve(u).then(r, o);
|
|
9
|
+
}
|
|
10
|
+
function _asyncToGenerator(n) {
|
|
11
|
+
return function () {
|
|
12
|
+
var t = this,
|
|
13
|
+
e = arguments;
|
|
14
|
+
return new Promise(function (r, o) {
|
|
15
|
+
var a = n.apply(t, e);
|
|
16
|
+
function _next(n) {
|
|
17
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "next", n);
|
|
18
|
+
}
|
|
19
|
+
function _throw(n) {
|
|
20
|
+
asyncGeneratorStep(a, r, o, _next, _throw, "throw", n);
|
|
21
|
+
}
|
|
22
|
+
_next(void 0);
|
|
23
|
+
});
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
function _defineProperty(e, r, t) {
|
|
27
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
28
|
+
value: t,
|
|
29
|
+
enumerable: true,
|
|
30
|
+
configurable: true,
|
|
31
|
+
writable: true
|
|
32
|
+
}) : e[r] = t, e;
|
|
33
|
+
}
|
|
34
|
+
function ownKeys(e, r) {
|
|
35
|
+
var t = Object.keys(e);
|
|
36
|
+
if (Object.getOwnPropertySymbols) {
|
|
37
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
38
|
+
r && (o = o.filter(function (r) {
|
|
39
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
40
|
+
})), t.push.apply(t, o);
|
|
41
|
+
}
|
|
42
|
+
return t;
|
|
43
|
+
}
|
|
44
|
+
function _objectSpread2(e) {
|
|
45
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
46
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
47
|
+
r % 2 ? ownKeys(Object(t), true).forEach(function (r) {
|
|
48
|
+
_defineProperty(e, r, t[r]);
|
|
49
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
50
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
return e;
|
|
54
|
+
}
|
|
55
|
+
function _toPrimitive(t, r) {
|
|
56
|
+
if ("object" != typeof t || !t) return t;
|
|
57
|
+
if (typeof Symbol === "function" && t instanceof Symbol) return t;
|
|
58
|
+
var e = t[Symbol.toPrimitive];
|
|
59
|
+
if (void 0 !== e) {
|
|
60
|
+
var i = e.call(t, r);
|
|
61
|
+
if ("object" != typeof i) return i;
|
|
62
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
63
|
+
}
|
|
64
|
+
return ("string" === r ? String : Number)(t);
|
|
65
|
+
}
|
|
66
|
+
function _toPropertyKey(t) {
|
|
67
|
+
var i = _toPrimitive(t, "string");
|
|
68
|
+
return "symbol" == typeof i ? i : i + "";
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { _asyncToGenerator as asyncToGenerator, _defineProperty as defineProperty, _objectSpread2 as objectSpread2, _toPrimitive as toPrimitive, _toPropertyKey as toPropertyKey };
|