From d60736431bcc08c42193969ab3b0ed8815fd5eb8 Mon Sep 17 00:00:00 2001 From: Demetrio Girardi Date: Tue, 22 Oct 2024 08:30:14 -0700 Subject: [PATCH] Core: fix missing BID_WON for some native ad units (#12349) --- src/adRendering.js | 4 ++++ src/secureCreatives.js | 13 ++++++++++--- test/spec/unit/secureCreatives_spec.js | 15 +++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/adRendering.js b/src/adRendering.js index 6f268ca1aec..47f335664e5 100644 --- a/src/adRendering.js +++ b/src/adRendering.js @@ -219,6 +219,10 @@ export function deferRendering(bidResponse, renderFn) { if (!bidResponse.deferRendering) { renderIfDeferred(bidResponse); } + markWinner(bidResponse); +} + +export function markWinner(bidResponse) { if (!WINNERS.has(bidResponse)) { WINNERS.add(bidResponse); markWinningBid(bidResponse); diff --git a/src/secureCreatives.js b/src/secureCreatives.js index a69585d28e8..baa8a82eec7 100644 --- a/src/secureCreatives.js +++ b/src/secureCreatives.js @@ -7,7 +7,14 @@ import {getAllAssetsMessage, getAssetMessage} from './native.js'; import {BID_STATUS, MESSAGES} from './constants.js'; import {isApnGetTagDefined, isGptPubadsDefined, logError, logWarn} from './utils.js'; import {find, includes} from './polyfill.js'; -import {deferRendering, getBidToRender, handleCreativeEvent, handleNativeMessage, handleRender} from './adRendering.js'; +import { + deferRendering, + getBidToRender, + handleCreativeEvent, + handleNativeMessage, + handleRender, + markWinner +} from './adRendering.js'; import {getCreativeRendererSource} from './creativeRenderers.js'; const { REQUEST, RESPONSE, NATIVE, EVENT } = MESSAGES; @@ -102,7 +109,6 @@ function handleNativeRequest(reply, data, adObject) { logError(`Cannot find ad for x-origin event request: '${data.adId}'`); return; } - switch (data.action) { case 'assetRequest': deferRendering(adObject, () => reply(getAssetMessage(data, adObject))); @@ -111,7 +117,8 @@ function handleNativeRequest(reply, data, adObject) { deferRendering(adObject, () => reply(getAllAssetsMessage(data, adObject))); break; default: - handleNativeMessage(data, adObject, {resizeFn: getResizer(data.adId, adObject)}) + handleNativeMessage(data, adObject, {resizeFn: getResizer(data.adId, adObject)}); + markWinner(adObject); } } diff --git a/test/spec/unit/secureCreatives_spec.js b/test/spec/unit/secureCreatives_spec.js index 64213073eee..aeb78501d51 100644 --- a/test/spec/unit/secureCreatives_spec.js +++ b/test/spec/unit/secureCreatives_spec.js @@ -411,6 +411,21 @@ describe('secureCreatives', () => { }); }); + it('should fire BID_WON when no asset is requested', () => { + pushBidResponseToAuction({}); + const data = { + adId: bidId, + message: 'Prebid Native', + }; + + const ev = makeEvent({ + data: JSON.stringify(data), + }); + return receive(ev).then(() => { + sinon.assert.calledWith(stubEmit, EVENTS.BID_WON, adResponse); + }); + }) + describe('resizing', () => { let container, slot; before(() => {