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

Debugging module: make mock creatives respect requested sizes #12804

Merged
merged 3 commits into from
Feb 27, 2025
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: 2 additions & 2 deletions integrationExamples/testBidder/testBidderVideoExample.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@
<body>
<h2>Prebid Test Bidder Example</h2>
<h5>Video ad</h5>
<div id="player"></div>
<div id="adUnit-0000"></div>
</body>
</html>
</html>
66 changes: 14 additions & 52 deletions modules/debugging/bidInterceptor.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,5 @@
import { Renderer } from '../../src/Renderer.js';
import { auctionManager } from '../../src/auctionManager.js';
import { BANNER, NATIVE, VIDEO } from '../../src/mediaTypes.js';
import {
deepAccess,
deepClone,
delayExecution,
mergeDeep,
hasNonSerializableProperty
} from '../../src/utils.js';
import {BANNER, VIDEO} from '../../src/mediaTypes.js';
import {deepAccess, deepClone, delayExecution, hasNonSerializableProperty, mergeDeep} from '../../src/utils.js';
import responseResolvers from './responses.js';

/**
Expand Down Expand Up @@ -147,7 +139,8 @@ Object.assign(BidInterceptor.prototype, {
return (bid, ...args) => {
const response = this.responseDefaults(bid);
mergeDeep(response, replFn({args: [bid, ...args]}));
this.setDefaultAd(bid, response);
const resolver = responseResolvers[response.mediaType];
resolver && resolver(bid, response);
response.isDebug = true;
return response;
}
Expand Down Expand Up @@ -175,56 +168,25 @@ Object.assign(BidInterceptor.prototype, {
requestId: bid.bidId,
cpm: 3.5764,
currency: 'EUR',
width: 600,
height: 500,
ttl: 360,
creativeId: 'mock-creative-id',
netRevenue: false,
meta: {}
};

if (!bid.mediaType) {
const adUnit = auctionManager.index.getAdUnit({adUnitId: bid.adUnitId}) || {mediaTypes: {}};
response.mediaType = Object.keys(adUnit.mediaTypes)[0] || 'banner';
response.mediaType = Object.keys(bid.mediaTypes ?? {})[0] ?? BANNER;
}

return response;
},
setDefaultAd(bid, bidResponse) {
switch (bidResponse.mediaType) {
case VIDEO:
if (!bidResponse.hasOwnProperty('vastXml') && !bidResponse.hasOwnProperty('vastUrl')) {
bidResponse.vastXml = responseResolvers[VIDEO]();
bidResponse.renderer = Renderer.install({
url: 'https://cdn.jwplayer.com/libraries/l5MchIxB.js',
});
bidResponse.renderer.setRender(function (bid) {
const player = window.jwplayer('player').setup({
width: 640,
height: 360,
advertising: {
client: 'vast',
outstream: true,
endstate: 'close'
},
});
player.on('ready', function() {
player.loadAdXml(bid.vastXml);
});
})
}
break;
case NATIVE:
if (!bidResponse.hasOwnProperty('native')) {
bidResponse.native = responseResolvers[NATIVE](bid);
}
break;
case BANNER:
default:
if (!bidResponse.hasOwnProperty('ad') && !bidResponse.hasOwnProperty('adUrl')) {
bidResponse.ad = responseResolvers[BANNER]();
}
let size;
if (response.mediaType === BANNER) {
size = bid.mediaTypes?.banner?.sizes?.[0] ?? [300, 250];
} else if (response.mediaType === VIDEO) {
size = bid.mediaTypes?.video?.playerSize?.[0] ?? [600, 500];
}
if (Array.isArray(size)) {
([response.width, response.height] = size);
}
return response;
},
/**
* Match a candidate bid against all registered rules.
Expand Down
2 changes: 1 addition & 1 deletion modules/debugging/pbsInterceptor.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function makePbsInterceptor({createBid}) {
function addBid(bid, bidRequest) {
onBid({
adUnit: bidRequest.adUnitCode,
bid: Object.assign(createBid(STATUS.GOOD, bidRequest), bid)
bid: Object.assign(createBid(STATUS.GOOD, bidRequest), {requestBidder: bidRequest.bidder}, bid)
})
}
bidRequests = bidRequests
Expand Down
61 changes: 50 additions & 11 deletions modules/debugging/responses.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,57 @@
import { BANNER, NATIVE, VIDEO } from '../../src/mediaTypes.js';
import {BANNER, NATIVE, VIDEO} from '../../src/mediaTypes.js';
import {Renderer} from '../../src/Renderer.js';
import {getGptSlotInfoForAdUnitCode} from '../../libraries/gptUtils/gptUtils.js';

const ORTB_NATIVE_ASSET_TYPES = ['img', 'video', 'link', 'data', 'title'];

export default {
[BANNER]: () => `<html><head><body><img src="https://vcdn.adnxs.com/p/creative-image/27/c0/52/67/27c05267-5a6d-4874-834e-18e218493c32.png"/></body></html>`,
[VIDEO]: () => '<?xml version=\"1.0\" encoding=\"UTF-8\"?><VAST version=\"3.0\"><Ad><InLine><AdSystem>GDFP</AdSystem><AdTitle>Demo</AdTitle><Description><![CDATA[Demo]]></Description><Creatives><Creative><Linear ><Duration>00:00:11</Duration><VideoClicks><ClickThrough><![CDATA[https://prebid.org/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile delivery=\"progressive\" width=\"640\" height=\"360\" type=\"video/mp4\" scalable=\"true\" maintainAspectRatio=\"true\"><![CDATA[https://s3.amazonaws.com/files.prebid.org/creatives/PrebidLogo.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>',
[NATIVE]: (bid) => {
return {
ortb: {
link: {
url: 'https://www.link.example',
clicktrackers: ['https://impression.example']
},
assets: bid.nativeOrtbRequest.assets.map(mapDefaultNativeOrtbAsset)
[BANNER]: (bid, bidResponse) => {
if (!bidResponse.hasOwnProperty('ad') && !bidResponse.hasOwnProperty('adUrl')) {
const [size, repeat] = bidResponse.width < bidResponse.height ? [bidResponse.width, 'repeat-y'] : [bidResponse.height, 'repeat-x'];
bidResponse.ad = `<html><body><div style="display: inline-block; height: ${bidResponse.height}px; width: ${bidResponse.width}px; background-image: url(https://vcdn.adnxs.com/p/creative-image/27/c0/52/67/27c05267-5a6d-4874-834e-18e218493c32.png); background-size: ${size}px; background-repeat: ${repeat}"></div></body></html>`;
}
},
[VIDEO]: (bid, bidResponse) => {
if (!bidResponse.hasOwnProperty('vastXml') && !bidResponse.hasOwnProperty('vastUrl')) {
bidResponse.vastXml = '<?xml version="1.0" encoding="UTF-8"?><VAST version="3.0"><Ad><InLine><AdSystem>GDFP</AdSystem><AdTitle>Demo</AdTitle><Description><![CDATA[Demo]]></Description><Creatives><Creative><Linear ><Duration>00:00:11</Duration><VideoClicks><ClickThrough><![CDATA[https://prebid.org/]]></ClickThrough></VideoClicks><MediaFiles><MediaFile delivery="progressive" width="640" height="360" type="video/mp4" scalable="true" maintainAspectRatio="true"><![CDATA[https://s3.amazonaws.com/files.prebid.org/creatives/PrebidLogo.mp4]]></MediaFile></MediaFiles></Linear></Creative></Creatives></InLine></Ad></VAST>';
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ChrisHuie this would be nice to have somewhere served with application/xml content type

bidResponse.renderer = Renderer.install({
url: 'https://cdn.jwplayer.com/libraries/l5MchIxB.js',
});
bidResponse.renderer.setRender(function (bid, doc) {
const parentId = getGptSlotInfoForAdUnitCode(bid.adUnitCode).divId ?? bid.adUnitCode;
const div = doc.createElement('div');
div.id = `${parentId}-video-player`;
doc.getElementById(parentId).appendChild(div);
const player = window.jwplayer(div.id).setup({
debug: true,
width: bidResponse.width,
height: bidResponse.height,
advertising: {
client: 'vast',
outstream: true,
endstate: 'close'
},
});
player.on('ready', async function () {
if (bid.vastUrl) {
player.loadAdTag(bid.vastUrl);
} else {
player.loadAdXml(bid.vastXml);
}
});
})
}
},
[NATIVE]: (bid, bidResponse) => {
if (!bidResponse.hasOwnProperty('native')) {
bidResponse.native = {
ortb: {
link: {
url: 'https://www.link.example',
clicktrackers: ['https://impression.example']
},
assets: bid.nativeOrtbRequest.assets.map(mapDefaultNativeOrtbAsset)
}
}
}
}
Expand Down