0% found this document useful (0 votes)
5 views4 pages

BX-UsingPrebid Js

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

BX-UsingPrebid Js

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Using Prebid.

js
Step 1: Building Prebid.js
Option 1: on Prebid.js website. Go to https://docs.prebid.org/download.html, «Get Prebid.js!» at the bottom of the page.
Option 2: from Github. Go to github and build sources according to instructions.

Step 2: Setup Prebid on a website

The parameters are used as an example:

s: 3649326 — Between section id


code: ad_slot — id of a iframe element showing prebid ads

1. Include into <head> builded prebid.js: <script src="prebid.js></script>


2. Include into <head> following code:
<script>
var PREBID_TIMEOUT = 1000;
var adUnits = [{
code: 'ad_slot',
mediaTypes: {
banner: {
sizes: [[240, 400]],
}
},
bids: [
{
bidder: 'between',
params: {
s: 3649326,
}
}
]
}];

var pbjs = pbjs || {};


pbjs.que = pbjs.que || [];

</script>

<script>
pbjs.que.push(function() {
pbjs.que.push(function () {
pbjs.setConfig({userSync: {
iframeEnabled:true
}})
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
var params = pbjs.getAdserverTargetingForAdUnitCode('ad_slot');
var iframe = document.getElementById('ad_slot');
var iframeDoc = iframe.contentWindow.document;
if(params && params['hb_adid']) {
pbjs.renderAd(iframeDoc, params['hb_adid']);
}
}

setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);
</script>

3. Include into <body> this code: <iframe id="ad_slot"></iframe>

Currency
You can choose in which currency the SSP server will send cpm: 'USD' or 'EUR'. Default is 'USD'. To do this, in the params field of our adapter you need
to add the cur field, which takes one of the values: 'USD' or 'EUR'.

For example, you want cpm to be sent in dollars. Then the code of our adapter settings will look like this:
{
bidder: 'between',
params: {
s: BETWEEN_SECTION_ID,
cur: 'USD'
}
}

Multisizes
If you specify several sizes in the AdUnits settings in the mediaTypes.banner.sizes field, our SSP server will hold an auction with each size and respond
with a bid with the maximum CPM. For example, your ad-slot supports three sizes: 970x250, 728x90 and 468x60. Then the AdUnits code will look like this:

var adUnits = [{
code: 'ad-slot',
mediaTypes: {
banner: {
sizes: [[970, 250], [728, 90], [468, 60]]
}
},
bids: [
{
bidder: 'between',
params: {
s: BETWEEN_SECTION_ID,
}
}
]
}];

Full example:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta http-equiv="X-UA-Compatible" />
<title>Prebid Test</title>
<script src="prebid.js"></script>
<script>
var PREBID_TIMEOUT = 1000;
var adUnits = [
{
code: "ad_slot",
mediaTypes: {
banner: {
sizes: [[970, 250]]
}
},
bids: [
{
bidder: "between",
params: {
s: 3635454
}
}
]
}
];
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
</script>
<script>
pbjs.que.push(function() {
pbjs.que.push(function() {
pbjs.setConfig({
userSync: {
iframeEnabled: true
}
});
});
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});
function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
var params = pbjs.getAdserverTargetingForAdUnitCode("ad_slot");
var iframe = document.getElementById("ad_slot");
var iframeDoc = iframe.contentWindow.document;
if (params && params["hb_adid"]) {
pbjs.renderAd(iframeDoc, params["hb_adid"]);
}
}
setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);
</script>
</head>
<body>
<iframe id="ad_slot"></iframe>
</body>
</html>

You might also like