Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core: fix missing BID_WON for some native ad units #12349

Merged
merged 2 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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