diff --git a/lib/addons/prebid/analytics.test.ts b/lib/addons/prebid/analytics.test.ts index d519b83b..379ab7b2 100644 --- a/lib/addons/prebid/analytics.test.ts +++ b/lib/addons/prebid/analytics.test.ts @@ -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: [] }; diff --git a/lib/addons/prebid/analytics.ts b/lib/addons/prebid/analytics.ts index 12c1fd8d..fbb617b6 100644 --- a/lib/addons/prebid/analytics.ts +++ b/lib/addons/prebid/analytics.ts @@ -646,7 +646,7 @@ class OptablePrebidAnalytics { userAgent: Bowser.parse(window.navigator.userAgent) as unknown as Record, 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", }; diff --git a/lib/addons/prototypes/analytics.js b/lib/addons/prototypes/analytics.js index 945edd09..b5e8524d 100644 --- a/lib/addons/prototypes/analytics.js +++ b/lib/addons/prototypes/analytics.js @@ -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 }; diff --git a/lib/addons/prototypes/analytics.test.js b/lib/addons/prototypes/analytics.test.js index 8abf5694..056344c2 100644 --- a/lib/addons/prototypes/analytics.test.js +++ b/lib/addons/prototypes/analytics.test.js @@ -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();