From 208b501e6f20c8bc56608fcf1af18868d28e60b6 Mon Sep 17 00:00:00 2001 From: tej656 Date: Wed, 24 Jul 2024 22:58:19 +0530 Subject: [PATCH 01/10] send BidRejected Events to capture floored bids --- modules/pubxaiAnalyticsAdapter.js | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index afa8b01bfca..c967578a919 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -157,15 +157,19 @@ const track = ({ eventType, args }) => { // handle invalid bids, and remove them from the adUnit cache case EVENTS.BID_TIMEOUT: args.map(extractBid).forEach((bid) => { - bid.renderStatus = 3; + bid.bidType = 3; auctionCache[bid.auctionId].bids.push(bid); }); break; // handle valid bid responses and record them as part of an auction case EVENTS.BID_RESPONSE: - const bid = Object.assign(extractBid(args), { renderStatus: 2 }); + const bid = Object.assign(extractBid(args), { bidType: 2 }); auctionCache[bid.auctionId].bids.push(bid); break; + case EVENTS.BID_REJECTED: + const rejectedBid = Object.assign(extractBid(args), { bidType: 1 }); + auctionCache[rejectedBid.auctionId].bids.push(rejectedBid); + break; // capture extra information from the auction, and if there were no bids // (and so no chance of a win) send the auction case EVENTS.AUCTION_END: @@ -183,7 +187,7 @@ const track = ({ eventType, args }) => { timestamp: args.timestamp, }); if ( - auctionCache[args.auctionId].bids.every((bid) => bid.renderStatus === 3) + auctionCache[args.auctionId].bids.every((bid) => bid.bidType === 3) ) { prepareSend(args.auctionId); } @@ -201,7 +205,7 @@ const track = ({ eventType, args }) => { isFloorSkipped: floorDetail?.skipped || false, isWinningBid: true, renderedSize: args.size, - renderStatus: 4, + bidType: 4, }); winningBid.adServerData = getAdServerDataForBid(winningBid); auctionCache[winningBid.auctionId].winningBid = winningBid; From 4c0b581a7b996a2166085c02ce28ade688dfba0b Mon Sep 17 00:00:00 2001 From: tej656 Date: Tue, 30 Jul 2024 23:11:46 +0530 Subject: [PATCH 02/10] fix tests --- modules/pubxaiAnalyticsAdapter.js | 7 +++---- .../spec/modules/pubxaiAnalyticsAdapter_spec.js | 17 +++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index c967578a919..e831526be5e 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -20,8 +20,6 @@ const analyticsType = 'endpoint'; const adapterCode = 'pubxai'; const pubxaiAnalyticsVersion = 'v2.0.0'; const defaultHost = 'api.pbxai.com'; -const auctionPath = '/analytics/auction'; -const winningBidPath = '/analytics/bidwon'; const storage = getStorageManager({ moduleType: MODULE_TYPE_ANALYTICS, moduleName: adapterCode }) /** @@ -236,9 +234,10 @@ const prepareSend = (auctionId) => { if (!shouldFireEventRequest(auctionId, initOptions.samplingRate)) { return; } + const pubxID = initOptions.pubxId; [ { - path: winningBidPath, + path: `/analytics/${pubxID}/bidwon`, requiredKeys: [ 'winningBid', 'pageDetail', @@ -253,7 +252,7 @@ const prepareSend = (auctionId) => { eventType: 'win', }, { - path: auctionPath, + path: `/analytics/${pubxID}/auction`, requiredKeys: [ 'bids', 'pageDetail', diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index 237a2d32d54..a27400af46f 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -31,9 +31,10 @@ describe('pubxai analytics adapter', () => { }); describe('track', () => { + const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625' let initOptions = { samplingRate: '1', - pubxId: '6c415fc0-8b0e-4cf5-be73-01526a4db625', + pubxId: pubxId, }; let originalVS; @@ -148,7 +149,7 @@ describe('pubxai analytics adapter', () => { timeout: 1000, config: { samplingRate: '1', - pubxId: '6c415fc0-8b0e-4cf5-be73-01526a4db625', + pubxId: pubxId, }, }, bidRequested: { @@ -529,7 +530,7 @@ describe('pubxai analytics adapter', () => { null, auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', sizes: '300x250', - renderStatus: 2, + bidType: 2, requestTimestamp: 1616654312804, creativeId: 96846035, currency: 'USD', @@ -651,7 +652,7 @@ describe('pubxai analytics adapter', () => { placementId: 13144370, renderedSize: '300x250', sizes: '300x250', - renderStatus: 4, + bidType: 4, responseTimestamp: 1616654313071, requestTimestamp: 1616654312804, status: 'rendered', @@ -758,7 +759,7 @@ describe('pubxai analytics adapter', () => { const [expectedUrl, expectedData] = arg; const parsedUrl = new URL(expectedUrl); expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index] + [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', @@ -800,7 +801,7 @@ describe('pubxai analytics adapter', () => { // Step 7: check the pathname of the calls is correct (sent only to the auction endpoint) const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal('/analytics/auction'); + expect(parsedUrl.pathname).to.equal(`/analytics/${pubxId}/auction`); // Step 8: check that the meta information in the call is correct expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ @@ -926,7 +927,7 @@ describe('pubxai analytics adapter', () => { const parsedUrl = new URL(expectedUrl); const auctionIdMapFn = index < 2 ? (i, _) => i : replaceProperty; expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index % 2] + [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index % 2] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', @@ -1042,7 +1043,7 @@ describe('pubxai analytics adapter', () => { const [expectedUrl, expectedData] = arg; const parsedUrl = new URL(expectedUrl); expect(parsedUrl.pathname).to.equal( - ['/analytics/bidwon', '/analytics/auction'][index] + [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', From 5bfc26029baf8aeff4a989e32613f2d386462bc7 Mon Sep 17 00:00:00 2001 From: tej656 Date: Wed, 31 Jul 2024 12:17:48 +0530 Subject: [PATCH 03/10] send pubx_id as query param --- modules/pubxaiAnalyticsAdapter.js | 8 +++++--- test/spec/modules/pubxaiAnalyticsAdapter_spec.js | 14 +++++++++----- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index e831526be5e..f8ec72cde75 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -20,6 +20,8 @@ const analyticsType = 'endpoint'; const adapterCode = 'pubxai'; const pubxaiAnalyticsVersion = 'v2.0.0'; const defaultHost = 'api.pbxai.com'; +const auctionPath = '/analytics/auction'; +const winningBidPath = '/analytics/bidwon'; const storage = getStorageManager({ moduleType: MODULE_TYPE_ANALYTICS, moduleName: adapterCode }) /** @@ -234,10 +236,9 @@ const prepareSend = (auctionId) => { if (!shouldFireEventRequest(auctionId, initOptions.samplingRate)) { return; } - const pubxID = initOptions.pubxId; [ { - path: `/analytics/${pubxID}/bidwon`, + path: winningBidPath, requiredKeys: [ 'winningBid', 'pageDetail', @@ -252,7 +253,7 @@ const prepareSend = (auctionId) => { eventType: 'win', }, { - path: `/analytics/${pubxID}/auction`, + path: auctionPath, requiredKeys: [ 'bids', 'pageDetail', @@ -286,6 +287,7 @@ const prepareSend = (auctionId) => { auctionTimestamp: auctionData.auctionDetail.timestamp, pubxaiAnalyticsVersion: pubxaiAnalyticsVersion, prebidVersion: '$prebid.version$', + pubxId: initOptions.pubxId, }, }); sendCache[pubxaiAnalyticsRequestUrl].push(data); diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index a27400af46f..abc52b00439 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -31,7 +31,7 @@ describe('pubxai analytics adapter', () => { }); describe('track', () => { - const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625' + const pubxId = '6c415fc0-8b0e-4cf5-be73-01526a4db625'; let initOptions = { samplingRate: '1', pubxId: pubxId, @@ -759,12 +759,13 @@ describe('pubxai analytics adapter', () => { const [expectedUrl, expectedData] = arg; const parsedUrl = new URL(expectedUrl); expect(parsedUrl.pathname).to.equal( - [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index] + ['/analytics/bidwon', '/analytics/auction'][index] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', pubxaiAnalyticsVersion: 'v2.0.0', prebidVersion: '$prebid.version$', + pubxId: pubxId, }); expect(expectedData.type).to.equal('text/json'); expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ @@ -801,13 +802,14 @@ describe('pubxai analytics adapter', () => { // Step 7: check the pathname of the calls is correct (sent only to the auction endpoint) const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; const parsedUrl = new URL(expectedUrl); - expect(parsedUrl.pathname).to.equal(`/analytics/${pubxId}/auction`); + expect(parsedUrl.pathname).to.equal('/analytics/auction'); // Step 8: check that the meta information in the call is correct expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', pubxaiAnalyticsVersion: 'v2.0.0', prebidVersion: '$prebid.version$', + pubxId: pubxId, }); // Step 9: check that the data sent in the request is correct @@ -927,12 +929,13 @@ describe('pubxai analytics adapter', () => { const parsedUrl = new URL(expectedUrl); const auctionIdMapFn = index < 2 ? (i, _) => i : replaceProperty; expect(parsedUrl.pathname).to.equal( - [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index % 2] + ['/analytics/bidwon', '/analytics/auction'][index % 2] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', pubxaiAnalyticsVersion: 'v2.0.0', prebidVersion: '$prebid.version$', + pubxId: pubxId, }); expect(expectedData.type).to.equal('text/json'); expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ @@ -1043,12 +1046,13 @@ describe('pubxai analytics adapter', () => { const [expectedUrl, expectedData] = arg; const parsedUrl = new URL(expectedUrl); expect(parsedUrl.pathname).to.equal( - [`/analytics/${pubxId}/bidwon`, `/analytics/${pubxId}/auction`][index] + ['/analytics/bidwon', '/analytics/auction'][index] ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', pubxaiAnalyticsVersion: 'v2.0.0', prebidVersion: '$prebid.version$', + pubxId: pubxId, }); expect(expectedData.type).to.equal('text/json'); expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ From 5559fdf192a58de78ac22941ccbbe422fe2ab63b Mon Sep 17 00:00:00 2001 From: NikhilX Date: Mon, 19 Aug 2024 11:38:38 +0530 Subject: [PATCH 04/10] added extraData in analytics adapter to be sent in beacon data --- modules/pubxaiAnalyticsAdapter.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index f8ec72cde75..ad682a8adf8 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -77,6 +77,7 @@ export const auctionCache = new Proxy( consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, pmacDetail: JSON.parse(storage.getDataFromLocalStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} + extraData: JSON.parse(storage.getDataFromLocalStorage('pubx:extraData')) || {}, initOptions: { ...initOptions, auctionId: name, // back-compat @@ -248,6 +249,7 @@ const prepareSend = (auctionId) => { 'userDetail', 'consentDetail', 'pmacDetail', + 'extraData', 'initOptions', ], eventType: 'win', @@ -263,6 +265,7 @@ const prepareSend = (auctionId) => { 'userDetail', 'consentDetail', 'pmacDetail', + 'extraData', 'initOptions', ], eventType: 'auction', From bcf5981883e3dfcdd0ab0499545588ded3026a59 Mon Sep 17 00:00:00 2001 From: NikhilX Date: Mon, 19 Aug 2024 11:38:38 +0530 Subject: [PATCH 05/10] added extraData in analytics adapter to be sent in beacon data --- modules/pubxaiAnalyticsAdapter.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index f8ec72cde75..ad682a8adf8 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -77,6 +77,7 @@ export const auctionCache = new Proxy( consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, pmacDetail: JSON.parse(storage.getDataFromLocalStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} + extraData: JSON.parse(storage.getDataFromLocalStorage('pubx:extraData')) || {}, initOptions: { ...initOptions, auctionId: name, // back-compat @@ -248,6 +249,7 @@ const prepareSend = (auctionId) => { 'userDetail', 'consentDetail', 'pmacDetail', + 'extraData', 'initOptions', ], eventType: 'win', @@ -263,6 +265,7 @@ const prepareSend = (auctionId) => { 'userDetail', 'consentDetail', 'pmacDetail', + 'extraData', 'initOptions', ], eventType: 'auction', From 8d913653705428a5adbd07cc2dfabadcba72652f Mon Sep 17 00:00:00 2001 From: NikhilX Date: Mon, 19 Aug 2024 13:04:14 +0530 Subject: [PATCH 06/10] moved data read to session storage --- modules/pubxaiAnalyticsAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index ad682a8adf8..3672fd65bf6 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -76,8 +76,8 @@ export const auctionCache = new Proxy( consentDetail: { consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, - pmacDetail: JSON.parse(storage.getDataFromLocalStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} - extraData: JSON.parse(storage.getDataFromLocalStorage('pubx:extraData')) || {}, + pmacDetail: JSON.parse(storage.getDataFromSessionStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} + extraData: JSON.parse(storage.getDataFromSessionStorage('pubx:extraData')) || {}, initOptions: { ...initOptions, auctionId: name, // back-compat From b5bf2863f3b9ec3969f8b3ba1c8c7051df0fc4d0 Mon Sep 17 00:00:00 2001 From: NikhilX Date: Mon, 19 Aug 2024 14:10:34 +0530 Subject: [PATCH 07/10] bumped version --- modules/pubxaiAnalyticsAdapter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index 3672fd65bf6..bb24ece5f0b 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -18,7 +18,7 @@ let initOptions; const emptyUrl = ''; const analyticsType = 'endpoint'; const adapterCode = 'pubxai'; -const pubxaiAnalyticsVersion = 'v2.0.0'; +const pubxaiAnalyticsVersion = 'v2.1.0'; const defaultHost = 'api.pbxai.com'; const auctionPath = '/analytics/auction'; const winningBidPath = '/analytics/bidwon'; From 91941a426cb609ebb58085976618af49041caa8f Mon Sep 17 00:00:00 2001 From: NikhilX Date: Tue, 20 Aug 2024 11:10:13 +0530 Subject: [PATCH 08/10] moving all data to localStorage again --- modules/pubxaiAnalyticsAdapter.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index bb24ece5f0b..cd93b9bd3f6 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -76,8 +76,8 @@ export const auctionCache = new Proxy( consentDetail: { consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, - pmacDetail: JSON.parse(storage.getDataFromSessionStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} - extraData: JSON.parse(storage.getDataFromSessionStorage('pubx:extraData')) || {}, + pmacDetail: JSON.parse(storage.getDataFromLocalStorage('pubx:pmac')) || {}, // {auction_1: {floor:0.23,maxBid:0.34,bidCount:3},auction_2:{floor:0.13,maxBid:0.14,bidCount:2} + extraData: JSON.parse(storage.getDataFromLocalStorage('pubx:extraData')) || {}, initOptions: { ...initOptions, auctionId: name, // back-compat From 3f1f53738495aab44aabcaf062eafd6ed399ab06 Mon Sep 17 00:00:00 2001 From: NikhilX Date: Tue, 20 Aug 2024 12:54:30 +0530 Subject: [PATCH 09/10] updated test cases for pubxaiAA.js --- test/spec/modules/pubxaiAnalyticsAdapter_spec.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index abc52b00439..6b2fbef6c06 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -599,6 +599,7 @@ describe('pubxai analytics adapter', () => { consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, pmacDetail: {}, + extraData: {}, initOptions: { ...initOptions, auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', @@ -693,6 +694,7 @@ describe('pubxai analytics adapter', () => { consentTypes: Object.keys(getGlobal().getConsentMetadata?.() || {}), }, pmacDetail: {}, + extraData: {}, initOptions: { ...initOptions, auctionId: 'bc3806e4-873e-453c-8ae5-204f35e923b4', @@ -763,7 +765,7 @@ describe('pubxai analytics adapter', () => { ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.0.0', + pubxaiAnalyticsVersion: 'v2.1.0', prebidVersion: '$prebid.version$', pubxId: pubxId, }); @@ -807,7 +809,7 @@ describe('pubxai analytics adapter', () => { // Step 8: check that the meta information in the call is correct expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.0.0', + pubxaiAnalyticsVersion: 'v2.1.0', prebidVersion: '$prebid.version$', pubxId: pubxId, }); @@ -933,7 +935,7 @@ describe('pubxai analytics adapter', () => { ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.0.0', + pubxaiAnalyticsVersion: 'v2.1.0', prebidVersion: '$prebid.version$', pubxId: pubxId, }); @@ -1050,7 +1052,7 @@ describe('pubxai analytics adapter', () => { ); expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ auctionTimestamp: '1616654312804', - pubxaiAnalyticsVersion: 'v2.0.0', + pubxaiAnalyticsVersion: 'v2.1.0', prebidVersion: '$prebid.version$', pubxId: pubxId, }); From e3ef74fa77b2026f829216e4faae7a6ec6770cf3 Mon Sep 17 00:00:00 2001 From: Nathan Oliver Date: Fri, 13 Sep 2024 11:46:22 +0100 Subject: [PATCH 10/10] fixing the missing logging of invalid bids --- modules/pubxaiAnalyticsAdapter.js | 2 +- .../modules/pubxaiAnalyticsAdapter_spec.js | 107 +++++++++++++++++- 2 files changed, 104 insertions(+), 5 deletions(-) diff --git a/modules/pubxaiAnalyticsAdapter.js b/modules/pubxaiAnalyticsAdapter.js index cd93b9bd3f6..b2f9af247f6 100644 --- a/modules/pubxaiAnalyticsAdapter.js +++ b/modules/pubxaiAnalyticsAdapter.js @@ -188,7 +188,7 @@ const track = ({ eventType, args }) => { timestamp: args.timestamp, }); if ( - auctionCache[args.auctionId].bids.every((bid) => bid.bidType === 3) + auctionCache[args.auctionId].bids.every((bid) => [1, 3].includes(bid.bidType)) ) { prepareSend(args.auctionId); } diff --git a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js index 6b2fbef6c06..05b32dae434 100644 --- a/test/spec/modules/pubxaiAnalyticsAdapter_spec.js +++ b/test/spec/modules/pubxaiAnalyticsAdapter_spec.js @@ -22,8 +22,8 @@ const readBlobSafariCompat = (blob) => { describe('pubxai analytics adapter', () => { beforeEach(() => { - getGlobal().refreshUserIds() sinon.stub(events, 'getEvents').returns([]); + getGlobal().refreshUserIds?.() }); afterEach(() => { @@ -776,15 +776,66 @@ describe('pubxai analytics adapter', () => { } }); - it('auction with no bids', async () => { + it('auction data with only rejected bids', async () => { // Step 1: Send auction init event events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); // Step 2: Send bid requested event events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); - // Step 3: Send bid time out event - events.emit(EVENTS.BID_TIMEOUT, prebidEvent['bidTimeout']); + // Step 3: Send bid rejected (afaict the only expected reason would be a bid being too low) + events.emit(EVENTS.BID_REJECTED, prebidEvent['bidResponse']); + + // Simulate "navigate away" behaviour + document.dispatchEvent(new Event('visibilitychange')); + + // Step 4: check the number of calls made to pubx.ai + expect(navigator.sendBeacon.callCount).to.equal(0); + + // Step 5: Send auction end event + events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); + + // Simulate end of session + document.dispatchEvent(new Event('visibilitychange')); + + // Step 6: check the number of calls made to pubx.ai + expect(navigator.sendBeacon.callCount).to.equal(1); + + // Step 7: check the pathname of the calls is correct (sent only to the auction endpoint) + const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; + const parsedUrl = new URL(expectedUrl); + expect(parsedUrl.pathname).to.equal('/analytics/auction'); + + // Step 8: check that the meta information in the call is correct + expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ + auctionTimestamp: '1616654312804', + pubxaiAnalyticsVersion: 'v2.1.0', + prebidVersion: '$prebid.version$', + pubxId: pubxId, + }); + + // Step 9: check that the data sent in the request is correct + expect(expectedData.type).to.equal('text/json'); + expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ + { + ...expectedAfterBid, + bids: [{ + ...expectedAfterBid.bids[0], + bidType: 1 + }] + } + ]); + }); + + it('auction data with only timed out bids', async () => { + // Step 1: Send auction init event + events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); + + // Step 2: Send bid requested event + events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); + + // Step 3: Send bid rejected (afaict the only expected reason would be a bid being too low) + events.emit(EVENTS.BID_TIMEOUT, [prebidEvent['bidResponse']]); // Simulate "navigate away" behaviour document.dispatchEvent(new Event('visibilitychange')); @@ -816,6 +867,54 @@ describe('pubxai analytics adapter', () => { // Step 9: check that the data sent in the request is correct expect(expectedData.type).to.equal('text/json'); + expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ + { + ...expectedAfterBid, + bids: [{ + ...expectedAfterBid.bids[0], + bidType: 3 + }] + } + ]); + }); + + it('auction with no bids', async () => { + // Step 1: Send auction init event + events.emit(EVENTS.AUCTION_INIT, prebidEvent['auctionInit']); + + // Step 2: Send bid requested event + events.emit(EVENTS.BID_REQUESTED, prebidEvent['bidRequested']); + + // Simulate "navigate away" behaviour + document.dispatchEvent(new Event('visibilitychange')); + + // Step 3: check the number of calls made to pubx.ai + expect(navigator.sendBeacon.callCount).to.equal(0); + + // Step 4: Send auction end event + events.emit(EVENTS.AUCTION_END, prebidEvent['auctionEnd']); + + // Simulate end of session + document.dispatchEvent(new Event('visibilitychange')); + + // Step 5: check the number of calls made to pubx.ai + expect(navigator.sendBeacon.callCount).to.equal(1); + + // Step 6: check the pathname of the calls is correct (sent only to the auction endpoint) + const [expectedUrl, expectedData] = navigator.sendBeacon.args[0]; + const parsedUrl = new URL(expectedUrl); + expect(parsedUrl.pathname).to.equal('/analytics/auction'); + + // Step 7: check that the meta information in the call is correct + expect(Object.fromEntries(parsedUrl.searchParams)).to.deep.equal({ + auctionTimestamp: '1616654312804', + pubxaiAnalyticsVersion: 'v2.1.0', + prebidVersion: '$prebid.version$', + pubxId: pubxId, + }); + + // Step 8: check that the data sent in the request is correct + expect(expectedData.type).to.equal('text/json'); expect(JSON.parse(await readBlobSafariCompat(expectedData))).to.deep.equal([ { ...expectedAfterBid,