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
16 changes: 16 additions & 0 deletions lib/addons/prebid/analytics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,22 @@ describe("OptablePrebidAnalytics", () => {
analytics = new OptablePrebidAnalytics(mockOptableInstance);
});

describe("sessionDepth", () => {
const emptyAuction = { auctionId: "depth-auction", bidderRequests: [] };

// sessionStorage stringifies on write, so the stored depth reads back as
// a string while the fallback is a number. Consumers see one field.
it("is a number whether or not the session has a stored depth", async () => {
sessionStorage.removeItem("optableSessionDepth");
const unset = await analytics.toWitness(emptyAuction, []);
expect(unset.sessionDepth).toBe(1);

sessionStorage.optableSessionDepth = "4";
const stored = await analytics.toWitness(emptyAuction, []);
expect(stored.sessionDepth).toBe(4);
});
});

describe("page config", () => {
const emptyAuction = { auctionId: "page-auction", bidderRequests: [] };

Expand Down
2 changes: 1 addition & 1 deletion lib/addons/prebid/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ class OptablePrebidAnalytics {
userAgent: Bowser.parse(window.navigator.userAgent) as unknown as Record<string, any>,
device,
prebidjsVersion: this.prebidInstance?.version || "unknown",
sessionDepth: sessionStorage?.optableSessionDepth || 1,
sessionDepth: Number(sessionStorage?.optableSessionDepth) || 1,
pageAuctionsCount: (window as any).optable?.pageAuctionsCount || 1,
originSlug: this.optableInstance?.dcn?.site || (window as any).optable?.site || "unknown",
};
Expand Down
2 changes: 1 addition & 1 deletion lib/addons/prototypes/analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ class OptablePrebidAnalytics {
tenant: this.config.tenant,
optableWrapperVersion: SDK_WRAPPER_VERSION, // eslint-disable-line no-undef
prebidjsVersion: this.prebidInstance?.version || "unknown",
sessionDepth: sessionStorage?.optableSessionDepthIndex || 1,
sessionDepth: Number(sessionStorage?.optableSessionDepthIndex) || 1,
pageAuctionsCount: window.optable?.pageAuctionIndex || 1,
originSlug: window.optable?.site || this.optableInstance?.dcn?.site || "unknown", // optable.site first since dcn is analytics always
};
Expand Down
15 changes: 15 additions & 0 deletions lib/addons/prototypes/analytics.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,21 @@ describe("cache state", () => {
});
});

describe("sessionDepth", () => {
// sessionStorage stringifies on write, so the stored depth reads back as a
// string while the fallback is a number. Consumers see one field.
test("is a number whether or not the session has a stored depth", async () => {
const { analytics, witness } = makeAnalytics();
sessionStorage.removeItem("optableSessionDepthIndex");
const unset = await run(analytics, witness, { bidderRequests: [bidderRequest("a", [])] });
expect(unset.sessionDepth).toBe(1);

sessionStorage.optableSessionDepthIndex = "4";
const stored = await run(analytics, witness, { bidderRequests: [bidderRequest("a", [])] });
expect(stored.sessionDepth).toBe(4);
});
});

describe("page config", () => {
test("sent on the first auction of the page only", async () => {
const { analytics, witness } = makeAnalytics();
Expand Down