@bidkernel/analytics 0.5.0 → 0.7.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/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,6 +70,32 @@ 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;
@@ -64,11 +132,18 @@ declare class BidkernelPrebidAnalytics {
64
132
  private consecutiveSendFailures;
65
133
  private nextSendAllowedAt;
66
134
  private replayedEventCount;
135
+ private immediateFlushScheduled;
136
+ private persistedBatchKeys;
137
+ private persistedCleanupTimer;
67
138
  private intersectionObserver;
68
139
  private slotViewabilityRecords;
69
140
  private elementToSlotId;
70
141
  private slotRefreshIndices;
142
+ private slotLastAuctionIds;
71
143
  private pendingThresholdListeners;
144
+ private slotEmittedImpressionKeys;
145
+ private cachedWinningBids;
146
+ private videoDetachCleanups;
72
147
  constructor(config: AnalyticsConfig);
73
148
  enable(): void;
74
149
  disable(): void;
@@ -83,6 +158,23 @@ declare class BidkernelPrebidAnalytics {
83
158
  observeSlot(element: HTMLElement | string, slotId?: string, options?: SlotObserveOptions): void;
84
159
  unobserveSlot(slotId: string): void;
85
160
  destroySlot(slotId: string): void;
161
+ hasImpressionEmitted(slotId: string, refreshIndex?: number, auctionId?: string, creativeId?: string): boolean;
162
+ private markImpressionEmitted;
163
+ recordImpression(slotId: string, options?: SlotObserveOptions & {
164
+ bid?: any;
165
+ }): boolean;
166
+ /**
167
+ * Bridges Google IMA SDK AdsManager events to Bidkernel analytics.
168
+ * Defers IMPRESSION emission until AdEvent.STARTED (or IMPRESSION),
169
+ * tracks milestones (FIRST_QUARTILE, MIDPOINT, THIRD_QUARTILE, COMPLETE),
170
+ * and handles AD_ERROR.
171
+ */
172
+ attachImaAdsManager(adsManager: any, options?: VideoPlayerOptions): () => void;
173
+ /**
174
+ * Attaches render hooks and viewability tracking to a video player.
175
+ * Supports HTML5 <video> elements, container elements, or Google IMA AdsManager.
176
+ */
177
+ attachVideoPlayer(target: any, options?: VideoPlayerOptions): () => void;
86
178
  onTimeInViewThreshold(slotId: string, thresholdMs: number, callback: (slotId: string, durationMs: number) => void): () => void;
87
179
  getViewabilityState(slotId: string): SlotViewabilityState | undefined;
88
180
  getRefreshIndex(slotId: string): number;
@@ -109,6 +201,10 @@ declare class BidkernelPrebidAnalytics {
109
201
  private handleSendFailure;
110
202
  private flush;
111
203
  private flushBeacon;
204
+ private persistBatch;
205
+ private removePersistedBatch;
206
+ private schedulePersistedCleanup;
207
+ private resendPersistedBatches;
112
208
  private log;
113
209
  }
114
210
  declare function registerPrebidAnalytics(pbjsGlobalName?: string, defaults?: Partial<AnalyticsConfig>): void;
@@ -163,6 +259,12 @@ interface AdsGlobal {
163
259
  refreshAll?: () => void;
164
260
  /** Notify the SDK that an SPA route transition happened so analytics and tracking reset. */
165
261
  navigate?: (url?: string) => void;
262
+ /** Attach video player hooks (HTML5 <video> or Google IMA AdsManager) for render-triggered telemetry. */
263
+ attachVideoPlayer?: (target: any, options?: any) => () => void;
264
+ /** Attach Google IMA SDK AdsManager event bridge for video render-triggered telemetry. */
265
+ attachImaAdsManager?: (adsManager: any, options?: any) => () => void;
266
+ /** Manually record ad render / impression when using custom rendering pipelines. */
267
+ recordImpression?: (slotId: string, options?: any) => boolean;
166
268
  }
167
269
  /**
168
270
  * Returns the global bidkernel SDK object interface.
@@ -173,4 +275,4 @@ interface AdsGlobal {
173
275
  */
174
276
  declare function getbidkernel(alias?: string): AdsGlobal;
175
277
 
176
- export { type AdsGlobal, type AnalyticsConfig, BidkernelPrebidAnalytics, PrebidEventDeduper, type SizeMapping, type SlotConfig, type SlotObserveOptions, type SlotSize, type SlotSizes, type SlotViewabilityState, getPrebidEventKey, getbidkernel, registerPrebidAnalytics };
278
+ 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, registerPrebidAnalytics };