@bidkernel/analytics 0.6.0 → 0.9.0
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/README.md +17 -17
- package/dist/analytics.global.js +1 -1
- package/dist/index.d.mts +137 -1
- package/dist/index.d.ts +137 -1
- package/dist/index.js +1096 -195
- package/dist/index.mjs +1095 -195
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,45 @@
|
|
|
1
|
+
import { BinaryWriter, BinaryReader } from '@bufbuild/protobuf/wire';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* BidTrace captures per-bid metrics for the reporting warehouse.
|
|
5
|
+
* CPM is the raw gross value as reported by the bidder.
|
|
6
|
+
*/
|
|
7
|
+
interface BidTrace {
|
|
8
|
+
bidder?: string | undefined;
|
|
9
|
+
/** raw bidder CPM, falling back to converted CPM if original is absent */
|
|
10
|
+
cpm?: number | undefined;
|
|
11
|
+
/** raw bidder currency, falling back to converted currency if original is absent (default USD) */
|
|
12
|
+
currency?: string | undefined;
|
|
13
|
+
width?: number | undefined;
|
|
14
|
+
height?: number | undefined;
|
|
15
|
+
dealId?: string | undefined;
|
|
16
|
+
/** "banner" | "video" | "native" */
|
|
17
|
+
mediaType?: string | undefined;
|
|
18
|
+
/** time from bid request to response */
|
|
19
|
+
latencyMs?: number | undefined;
|
|
20
|
+
/** primary adomain from bid.meta.advertiserDomains */
|
|
21
|
+
advertiserDomain?: string | undefined;
|
|
22
|
+
/** from bid.creativeId (Prebid) or bid.crid (oRTB) */
|
|
23
|
+
creativeId?: string | undefined;
|
|
24
|
+
}
|
|
25
|
+
declare const BidTrace: MessageFns<BidTrace>;
|
|
26
|
+
type Builtin = Date | Function | Uint8Array | string | number | boolean | undefined;
|
|
27
|
+
type DeepPartial<T> = T extends Builtin ? T : T extends globalThis.Array<infer U> ? globalThis.Array<DeepPartial<U>> : T extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : T extends {} ? {
|
|
28
|
+
[K in keyof T]?: DeepPartial<T[K]>;
|
|
29
|
+
} : Partial<T>;
|
|
30
|
+
type KeysOfUnion<T> = T extends T ? keyof T : never;
|
|
31
|
+
type Exact<P, I extends P> = P extends Builtin ? P : P & {
|
|
32
|
+
[K in keyof P]: Exact<P[K], I[K]>;
|
|
33
|
+
} & {
|
|
34
|
+
[K in Exclude<keyof I, KeysOfUnion<P>>]: never;
|
|
35
|
+
};
|
|
36
|
+
interface MessageFns<T> {
|
|
37
|
+
encode(message: T, writer?: BinaryWriter): BinaryWriter;
|
|
38
|
+
decode(input: BinaryReader | Uint8Array, length?: number): T;
|
|
39
|
+
create<I extends Exact<DeepPartial<T>, I>>(base?: I): T;
|
|
40
|
+
fromPartial<I extends Exact<DeepPartial<T>, I>>(object: I): T;
|
|
41
|
+
}
|
|
42
|
+
|
|
1
43
|
interface AnalyticsConfig {
|
|
2
44
|
endpoint: string;
|
|
3
45
|
propertyId: string;
|
|
@@ -28,12 +70,53 @@ interface SlotObserveOptions {
|
|
|
28
70
|
refreshIndex?: number;
|
|
29
71
|
emitRefreshEvent?: boolean;
|
|
30
72
|
}
|
|
73
|
+
interface VideoPlayerOptions {
|
|
74
|
+
/** The ad unit code / slot identifier for analytics reporting */
|
|
75
|
+
adUnitCode?: string;
|
|
76
|
+
slotId?: string;
|
|
77
|
+
auctionId?: string;
|
|
78
|
+
transactionId?: string;
|
|
79
|
+
bid?: any;
|
|
80
|
+
metadata?: Record<string, string>;
|
|
81
|
+
refreshIndex?: number;
|
|
82
|
+
/** Whether to automatically track IAB video viewability (2s continuous >=50% in-view) and Time-in-View. Defaults to true. */
|
|
83
|
+
trackViewability?: boolean;
|
|
84
|
+
/** Custom callback when impression is triggered */
|
|
85
|
+
onImpression?: (slotId: string, details: any) => void;
|
|
86
|
+
/** Custom callback when playback milestone reached (25%, 50%, 75%, 100%) */
|
|
87
|
+
onMilestone?: (milestone: "firstQuartile" | "midpoint" | "thirdQuartile" | "complete", slotId: string) => void;
|
|
88
|
+
/** Custom callback when render / playback error occurs */
|
|
89
|
+
onError?: (error: any) => void;
|
|
90
|
+
}
|
|
91
|
+
interface CachedWinningBid {
|
|
92
|
+
bidTrace: BidTrace;
|
|
93
|
+
auctionId: string;
|
|
94
|
+
transactionId: string;
|
|
95
|
+
adUnitCode: string;
|
|
96
|
+
rawBid?: any;
|
|
97
|
+
timestamp: number;
|
|
98
|
+
}
|
|
31
99
|
interface SlotViewabilityState {
|
|
32
100
|
inView: boolean;
|
|
33
101
|
viewable: boolean;
|
|
34
102
|
timeInViewMs: number;
|
|
35
103
|
refreshIndex: number;
|
|
36
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* The ingest endpoint decides where auction telemetry -- CPMs, deal IDs,
|
|
107
|
+
* advertiser domains, user and session IDs -- is shipped, and it arrives from
|
|
108
|
+
* page context (enableAnalytics options, or the _bidkernelAnalyticsConfig
|
|
109
|
+
* global). Anything running in the page can reach that, including a banner
|
|
110
|
+
* creative rendered into a same-origin Prebid friendly iframe, so the value is
|
|
111
|
+
* validated rather than trusted: HTTPS only, absolute, no credentials in the
|
|
112
|
+
* URL. Plain HTTP is allowed only for loopback so local development works.
|
|
113
|
+
*
|
|
114
|
+
* This deliberately does not allowlist hosts: properties on branded ingest
|
|
115
|
+
* domains legitimately point at their own. Hijacking a live instance to a
|
|
116
|
+
* different origin is prevented separately, by pinning in
|
|
117
|
+
* registerPrebidAnalytics.
|
|
118
|
+
*/
|
|
119
|
+
declare function isTrustedEndpoint(raw: string): boolean;
|
|
37
120
|
/**
|
|
38
121
|
* Canonical duplicate-detection key for a Prebid event. Shared by the adapter
|
|
39
122
|
* and the diagnostic extension so the two can never drift apart. Covers the
|
|
@@ -71,7 +154,12 @@ declare class BidkernelPrebidAnalytics {
|
|
|
71
154
|
private slotViewabilityRecords;
|
|
72
155
|
private elementToSlotId;
|
|
73
156
|
private slotRefreshIndices;
|
|
157
|
+
private slotLastAuctionIds;
|
|
74
158
|
private pendingThresholdListeners;
|
|
159
|
+
private slotEmittedImpressionKeys;
|
|
160
|
+
private cachedWinningBids;
|
|
161
|
+
private videoDetachCleanups;
|
|
162
|
+
private auctionBidderOutcomes;
|
|
75
163
|
constructor(config: AnalyticsConfig);
|
|
76
164
|
enable(): void;
|
|
77
165
|
disable(): void;
|
|
@@ -86,8 +174,49 @@ declare class BidkernelPrebidAnalytics {
|
|
|
86
174
|
observeSlot(element: HTMLElement | string, slotId?: string, options?: SlotObserveOptions): void;
|
|
87
175
|
unobserveSlot(slotId: string): void;
|
|
88
176
|
destroySlot(slotId: string): void;
|
|
177
|
+
/**
|
|
178
|
+
* Reads a cached winning bid, treating an entry past CACHED_BID_TTL_MS as
|
|
179
|
+
* absent and dropping it. Every read goes through here so a stale bid can
|
|
180
|
+
* never be married to a much later render.
|
|
181
|
+
*/
|
|
182
|
+
private getCachedBid;
|
|
183
|
+
/** Removes every alias pointing at one entry. Aliases are stored by identity. */
|
|
184
|
+
private deleteCachedBidEntry;
|
|
185
|
+
/**
|
|
186
|
+
* Drops expired entries, then evicts oldest-first until the key cap holds.
|
|
187
|
+
* Map iterates in insertion order and one win's aliases are written
|
|
188
|
+
* consecutively, so eviction takes a whole bid's aliases together.
|
|
189
|
+
*/
|
|
190
|
+
private pruneCachedWinningBids;
|
|
191
|
+
/** Records a dedup key, evicting oldest-first at the cap. */
|
|
192
|
+
private addImpressionKey;
|
|
193
|
+
/**
|
|
194
|
+
* The bidder-outcome map for an auction, creating it if absent. Evicts the
|
|
195
|
+
* oldest auction at the cap: without this, any auction whose auctionEnd never
|
|
196
|
+
* fires (abandoned, navigated away from mid-flight) leaks its map forever.
|
|
197
|
+
*/
|
|
198
|
+
private getOrCreateAuctionOutcomes;
|
|
199
|
+
hasImpressionEmitted(slotId: string, refreshIndex?: number, auctionId?: string, creativeId?: string): boolean;
|
|
200
|
+
private markImpressionEmitted;
|
|
201
|
+
recordImpression(slotId: string, options?: SlotObserveOptions & {
|
|
202
|
+
bid?: any;
|
|
203
|
+
}): boolean;
|
|
204
|
+
/**
|
|
205
|
+
* Bridges Google IMA SDK AdsManager events to Bidkernel analytics.
|
|
206
|
+
* Defers IMPRESSION emission until AdEvent.STARTED (or IMPRESSION),
|
|
207
|
+
* tracks milestones (FIRST_QUARTILE, MIDPOINT, THIRD_QUARTILE, COMPLETE),
|
|
208
|
+
* and handles AD_ERROR.
|
|
209
|
+
*/
|
|
210
|
+
attachImaAdsManager(adsManager: any, options?: VideoPlayerOptions): () => void;
|
|
211
|
+
/**
|
|
212
|
+
* Attaches render hooks and viewability tracking to a video player.
|
|
213
|
+
* Supports HTML5 <video> elements, container elements, or Google IMA AdsManager.
|
|
214
|
+
*/
|
|
215
|
+
attachVideoPlayer(target: any, options?: VideoPlayerOptions): () => void;
|
|
89
216
|
onTimeInViewThreshold(slotId: string, thresholdMs: number, callback: (slotId: string, durationMs: number) => void): () => void;
|
|
90
217
|
getViewabilityState(slotId: string): SlotViewabilityState | undefined;
|
|
218
|
+
/** The validated ingest endpoint in use, or "" when none passed validation. */
|
|
219
|
+
getEndpoint(): string;
|
|
91
220
|
getRefreshIndex(slotId: string): number;
|
|
92
221
|
triggerSlotRefresh(slotId: string, options?: SlotObserveOptions): void;
|
|
93
222
|
trackRawEvent(level: string, eventName: string, data: any): void;
|
|
@@ -112,6 +241,7 @@ declare class BidkernelPrebidAnalytics {
|
|
|
112
241
|
private handleSendFailure;
|
|
113
242
|
private flush;
|
|
114
243
|
private flushBeacon;
|
|
244
|
+
private pendingKeyPrefix;
|
|
115
245
|
private persistBatch;
|
|
116
246
|
private removePersistedBatch;
|
|
117
247
|
private schedulePersistedCleanup;
|
|
@@ -170,6 +300,12 @@ interface AdsGlobal {
|
|
|
170
300
|
refreshAll?: () => void;
|
|
171
301
|
/** Notify the SDK that an SPA route transition happened so analytics and tracking reset. */
|
|
172
302
|
navigate?: (url?: string) => void;
|
|
303
|
+
/** Attach video player hooks (HTML5 <video> or Google IMA AdsManager) for render-triggered telemetry. */
|
|
304
|
+
attachVideoPlayer?: (target: any, options?: any) => () => void;
|
|
305
|
+
/** Attach Google IMA SDK AdsManager event bridge for video render-triggered telemetry. */
|
|
306
|
+
attachImaAdsManager?: (adsManager: any, options?: any) => () => void;
|
|
307
|
+
/** Manually record ad render / impression when using custom rendering pipelines. */
|
|
308
|
+
recordImpression?: (slotId: string, options?: any) => boolean;
|
|
173
309
|
}
|
|
174
310
|
/**
|
|
175
311
|
* Returns the global bidkernel SDK object interface.
|
|
@@ -180,4 +316,4 @@ interface AdsGlobal {
|
|
|
180
316
|
*/
|
|
181
317
|
declare function getbidkernel(alias?: string): AdsGlobal;
|
|
182
318
|
|
|
183
|
-
export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };
|
|
319
|
+
export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, type CachedWinningBid, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, type VideoPlayerOptions, getPrebidEventKey, getbidkernel, isTrustedEndpoint, registerPrebidAnalytics };
|