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: Bid responses for various media types (+ TestBidder) #12720

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
79 changes: 79 additions & 0 deletions integrationExamples/testBidder/testBidderBannerExample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
<html>
<head>
<title>Prebid Test Bidder Example</title>
<script src="../../build/dev/prebid.js" async></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

const adUnitCode = 'adUnit-0000';

const adUnits = [{
mediaTypes: {
banner: {
sizes: [600, 500]
}
},
code: adUnitCode,
bids: [
{bidder: 'testBidder', params: {}}
]
}]

pbjs.que.push(function () {

/**
* BID RESPONSE SIMULATION SECTION START
*
* This section handles simulating a bidder
* that will always respond with bid responses.
*
* This part should not be present in production.
*/
pbjs.registerBidAdapter(null, 'testBidder', {
supportedMediaTypes: ['banner', 'video', 'native'],
isBidRequestValid: () => true
});

pbjs.setConfig({
debugging: {
enabled: true,
intercept: [
{
when: {
bidder: 'testBidder',
},
then: {
creativeId: 'testCreativeId',
}
}
]
}
});
/**
* BID RESPONSE SIMULATION SECTION END
*/

pbjs.addAdUnits(adUnits);
pbjs.requestBids({
adUnitCodes: [adUnitCode],
bidsBackHandler: function() {
const bids = pbjs.getHighestCpmBids(adUnitCode);
const winningBid = bids[0];
const div = document.getElementById('banner');
let iframe = document.createElement('iframe');
iframe.frameBorder = '0';
div.appendChild(iframe);
var iframeDoc = iframe.contentWindow.document;
pbjs.renderAd(iframeDoc, winningBid.adId);
}
});
});
</script>
</head>
<body>
<h2>Prebid Test Bidder Example</h2>
<h5>Banner ad</h5>
<div id="banner"></div>
</body>
</html>
111 changes: 111 additions & 0 deletions integrationExamples/testBidder/testBidderNativeExample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
<html>
<head>
<title>Prebid Test Bidder Example</title>
<script src="../../build/dev/prebid.js" async></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

const adUnitCode = 'adUnit-0000';

const adUnits = [{
mediaTypes: {
native: {
image: {
required: true,
sizes: [600, 500],
}
}
},
code: adUnitCode,
bids: [
{bidder: 'testBidder', params: {}}
]
}]

pbjs.que.push(function () {

/**
* BID RESPONSE SIMULATION SECTION START
*
* This section handles simulating a bidder
* that will always respond with bid responses.
*
* This part should not be present in production.
*/
pbjs.registerBidAdapter(null, 'testBidder', {
supportedMediaTypes: ['banner', 'video', 'native'],
isBidRequestValid: () => true
});

pbjs.setConfig({
debugging: {
enabled: true,
intercept: [
{
when: {
bidder: 'testBidder',
},
then: {
creativeId: 'testCreativeId',
}
}
]
}
});
/**
* BID RESPONSE SIMULATION SECTION END
*/

pbjs.addAdUnits(adUnits);
pbjs.requestBids({
adUnitCodes: [adUnitCode],
bidsBackHandler: function() {
const bids = pbjs.getHighestCpmBids(adUnitCode);
const bid = bids[0];
const slot = document.getElementById('native');
const iframe = document.createElement('iframe');
Object.entries({
frameBorder: 0,
marginWidth: 0,
marginHeight: 0,
width: 600,
height: 500,
scrolling: 'no',
srcdoc: document.getElementById('native-template').innerHTML
}).forEach(([prop, val]) => iframe.setAttribute(prop, val));
slot.appendChild(iframe);
iframe.onload = () => pbjs.renderAd(iframe.contentDocument, bid.adId);
}
});
});
</script>
</head>
<body>
<template id="native-template">
<style>
body {
display: inline-block;
}

.container {
display: inline-block;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
font-size: 14px;
line-height: 1.42857143;
color: #333;
background: #fff url(##hb_native_asset_id_0##) no-repeat center;
background-size: cover;
width: 600px;
height: 500px;
}

</style>
<div class="container">
</div>
</template>
<h2>Prebid Test Bidder Example</h2>
<h5>Native ad</h5>
<div id="native"></div>
</body>
</html>
89 changes: 89 additions & 0 deletions integrationExamples/testBidder/testBidderVideoExample.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<html>
<head>
<title>Prebid Test Bidder Example</title>
<script src="https://cdn.jwplayer.com/libraries/l5MchIxB.js"></script>
<script src="../../build/dev/prebid.js" async></script>
<script>
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

const adUnitCode = 'adUnit-0000';

const adUnits = [{
mediaTypes: {
video: {
playerSize: [640, 360]
}
},
code: adUnitCode,
bids: [
{bidder: 'testBidder', params: {}}
]
}]

pbjs.que.push(function () {

/**
* BID RESPONSE SIMULATION SECTION START
*
* This section handles simulating a bidder
* that will always respond with bid responses.
*
* This part should not be present in production.
*/
pbjs.registerBidAdapter(null, 'testBidder', {
supportedMediaTypes: ['banner', 'video', 'native'],
isBidRequestValid: () => true
});

pbjs.setConfig({
debugging: {
enabled: true,
intercept: [
{
when: {
bidder: 'testBidder',
},
then: {
creativeId: 'testCreativeId',
}
}
]
}
});
/**
* BID RESPONSE SIMULATION SECTION END
*/

pbjs.addAdUnits(adUnits);
pbjs.requestBids({
adUnitCodes: [adUnitCode],
bidsBackHandler: function() {
const bids = pbjs.getHighestCpmBids(adUnitCode);
const winningBid = bids[0];
jwplayer("player").setup({
playlist: "https://cdn.jwplayer.com/v2/media/hWF9vG66",
autostart: "viewable",
width: 640,
height: 360,
advertising: {
client: "vast",
schedule: [
{
vastxml: winningBid.vastXml,
offset: 'pre'
}
]
}
});
}
});
});
</script>
</head>
<body>
<h2>Prebid Test Bidder Example</h2>
<h5>Video ad</h5>
<div id="player"></div>
</body>
</html>
40 changes: 32 additions & 8 deletions modules/debugging/bidInterceptor.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
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 responseResolvers from './responses.js';

/**
* @typedef {Number|String|boolean|null|undefined} Scalar
Expand Down Expand Up @@ -143,9 +146,7 @@ Object.assign(BidInterceptor.prototype, {
return (bid, ...args) => {
const response = this.responseDefaults(bid);
mergeDeep(response, replFn({args: [bid, ...args]}));
if (!response.hasOwnProperty('ad') && !response.hasOwnProperty('adUrl')) {
response.ad = this.defaultAd(bid, response);
}
this.setDefaultAd(bid, response);
response.isDebug = true;
return response;
}
Expand All @@ -169,20 +170,43 @@ Object.assign(BidInterceptor.prototype, {
},

responseDefaults(bid) {
return {
const response = {
requestId: bid.bidId,
cpm: 3.5764,
currency: 'EUR',
width: 300,
height: 250,
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';
}

return response;
},
defaultAd(bid, bidResponse) {
return `<html><head><style>#ad {width: ${bidResponse.width}px;height: ${bidResponse.height}px;background-color: #f6f6ae;color: #85144b;padding: 5px;text-align: center;display: flex;flex-direction: column;align-items: center;justify-content: center;}#bidder {font-family: monospace;font-weight: normal;}#title {font-size: x-large;font-weight: bold;margin-bottom: 5px;}#body {font-size: large;margin-top: 5px;}</style></head><body><div id="ad"><div id="title">Mock ad: <span id="bidder">${bid.bidder}</span></div><div id="body">${bidResponse.width}x${bidResponse.height}</div></div></body></html>`;
setDefaultAd(bid, bidResponse) {
switch (bidResponse.mediaType) {
case VIDEO:
if (!bidResponse.hasOwnProperty('vastXml') && !bidResponse.hasOwnProperty('vastUrl')) {
bidResponse.vastXml = responseResolvers[VIDEO]();
}
break;
case NATIVE:
if (!bidResponse.hasOwnProperty('native')) {
bidResponse.native = responseResolvers[NATIVE]();
}
break;
case BANNER:
default:
if (!bidResponse.hasOwnProperty('ad') && !bidResponse.hasOwnProperty('adUrl')) {
bidResponse.ad = responseResolvers[BANNER](bid, bidResponse);
}
}
},
/**
* Match a candidate bid against all registered rules.
Expand Down
Loading