Skip to content

Commit

Permalink
Core: fix missing BID_WON for some native ad units (prebid#12349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dgirardi authored Oct 22, 2024
1 parent 24306f3 commit d607364
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/adRendering.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
13 changes: 10 additions & 3 deletions src/secureCreatives.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand All @@ -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);
}
}

Expand Down
15 changes: 15 additions & 0 deletions test/spec/unit/secureCreatives_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand Down

0 comments on commit d607364

Please sign in to comment.