diff --git a/lib/addons/prebid/analytics.test.ts b/lib/addons/prebid/analytics.test.ts index 64bba2c6..09f8c63a 100644 --- a/lib/addons/prebid/analytics.test.ts +++ b/lib/addons/prebid/analytics.test.ts @@ -431,6 +431,41 @@ describe("OptablePrebidAnalytics", () => { expect(result.optableSources).toEqual(["uidapi.com", "id5-sync.com"]); expect(result.liveintentEIDs).toEqual(["uidapi.com"]); }); + + it("keeps an Optable EID when a later non-Optable EID shares its source", async () => { + const result = await analytics.toWitness( + { + auctionId: "auction-shared-source", + bidderRequests: [ + { + bidderCode: "bidder1", + bidderRequestId: "req-1", + ortb2: { + site: { domain: "example.com" }, + user: { + ext: { eids: [{ inserter: "optable.co", matcher: "uid2", source: "uidapi.com" }] }, + eids: [{ source: "uidapi.com", uids: [{ id: "li", ext: { provider: "liveintent.com" } }] }], + }, + }, + bids: [], + }, + ], + bidsReceived: [], + noBids: [], + timeoutBids: [], + }, + [] + ); + + expect(result.bidderRequests[0]).toMatchObject({ + optableTargetingDone: true, + optableMatchers: ["uid2"], + optableSources: ["uidapi.com"], + }); + expect(result.optableMatchers).toEqual(["uid2"]); + expect(result.optableSources).toEqual(["uidapi.com"]); + expect(result.optableTargetingDone).toBe("1"); + }); }); describe("trackAuctionEnd", () => { diff --git a/lib/addons/prebid/analytics.ts b/lib/addons/prebid/analytics.ts index 490e3bd1..97f1b86f 100644 --- a/lib/addons/prebid/analytics.ts +++ b/lib/addons/prebid/analytics.ts @@ -393,8 +393,8 @@ class OptablePrebidAnalytics { const { bidderCode, bidderRequestId, bids = [] } = br; const domain = br.ortb2.site?.domain ?? "unknown"; const allEids = [...(br.ortb2.user?.ext?.eids ?? []), ...(br.ortb2.user?.eids ?? [])]; - // Deduplicate EIDs by source - const eids = Array.from(new Map(allEids.map((eid: any) => [eid.source, eid])).values()); + // Deduplicate EIDs by source and inserter, so another inserter's EID can't hide Optable's + const eids = Array.from(new Map(allEids.map((eid: any) => [`${eid.source}|${eid.inserter}`, eid])).values()); // Optable EIDs const optableEIDS = eids.filter((e: { inserter: string }) => e.inserter === "optable.co");