Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions lib/addons/prebid/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class OptablePrebidAnalytics {
private readonly maxAuctionDataSize: number = 50;

private auctions = new Map<string, AuctionItem>();
private prebidInstance: any;

/**
* Create a new OptablePrebidAnalytics instance.
Expand All @@ -72,6 +73,8 @@ class OptablePrebidAnalytics {
sessionStorage.removeItem(SESSION_SAMPLE_KEY);
}

sessionStorage.optableSessionDepth = (Number(sessionStorage?.optableSessionDepth) || 0) + 1;

this.isInitialized = true;

// Store auction data
Expand Down Expand Up @@ -186,6 +189,8 @@ class OptablePrebidAnalytics {
*/
hookIntoPrebid(prebidInstance = window.pbjs) {
const pbjs = prebidInstance;
this.prebidInstance = pbjs;

if (typeof pbjs === "undefined") {
this.log("Prebid.js not found");
return false;
Expand Down Expand Up @@ -214,6 +219,9 @@ class OptablePrebidAnalytics {

this.log(`Processing auction ${auctionId} with ${bidderRequests.length} bidder requests`);

(window as any).optable = (window as any).optable || {};
(window as any).optable.pageAuctionsCount = (Number((window as any).optable.pageAuctionsCount) || 0) + 1;

// Build auction object with bidder requests and EID flags
const auction = {
auctionId,
Expand Down Expand Up @@ -510,6 +518,9 @@ class OptablePrebidAnalytics {
optableWrapperVersion: SDK_WRAPPER_VERSION || "unknown",
userAgent: Bowser.parse(window.navigator.userAgent) as unknown as Record<string, any>,
device,
prebidjsVersion: this.prebidInstance?.version || "unknown",
sessionDepth: sessionStorage?.optableSessionDepth || 1,
pageAuctionsCount: (window as any).optable?.pageAuctionsCount || 1,
};

// Log summary with bid counts
Expand Down
14 changes: 10 additions & 4 deletions lib/addons/prototypes/analytics.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/* eslint-disable no-param-reassign */
/* eslint-disable no-console */
const STATUS = {
REQUESTED: "REQUESTED",
RECEIVED: "RECEIVED",
Expand All @@ -24,6 +23,8 @@ class OptablePrebidAnalytics {
this.auctions = {};
this.maxAuctionDataSize = 20;

sessionStorage.optableSessionDepth = (Number(sessionStorage?.optableSessionDepth) || 0) + 1;

this.log("OptablePrebidAnalytics initialized");
}

Expand All @@ -32,7 +33,7 @@ class OptablePrebidAnalytics {
*/
log(...args) {
if (this.config.debug) {
console.log("[OptablePrebidAnalytics]", ...args);
console.log("[OptablePrebidAnalytics]", ...args); /* eslint-disable-line no-console */
}
}

Expand Down Expand Up @@ -84,6 +85,7 @@ class OptablePrebidAnalytics {
*/
hookIntoPrebid(prebidInstance = window.pbjs) {
const pbjs = prebidInstance;
this.prebidInstance = pbjs;
if (typeof pbjs === "undefined") {
this.log("Prebid.js not found");
return false;
Expand All @@ -101,6 +103,8 @@ class OptablePrebidAnalytics {
async trackAuctionEnd(event, missed) {
const { auctionId, timeout, bidderRequests = [], bidsReceived = [], noBids = [], timeoutBids = [] } = event;

window.optable.pageAuctionsCount = (Number(window.optable.pageAuctionsCount) || 0) + 1;

this.log(`Processing auction ${auctionId} with ${bidderRequests.length} bidder requests`);

// Build auction object with bidder requests and EID flags
Expand Down Expand Up @@ -269,8 +273,10 @@ class OptablePrebidAnalytics {
missed,
url: `${window.location.hostname}${window.location.pathname}`,
tenant: this.config.tenant,
// eslint-disable-next-line no-undef
optableWrapperVersion: SDK_WRAPPER_VERSION,
optableWrapperVersion: SDK_WRAPPER_VERSION, // eslint-disable-line no-undef
prebidjsVersion: this.prebidInstance?.version || "unknown",
sessionDepth: sessionStorage?.optableSessionDepth || 1,
pageAuctionsCount: window.optable?.pageAuctionsCount || 1,
};
// Log summary with bid counts
this.log(
Expand Down