console.log('prebid template activated');
var div_1_sizes = [
[300, 250],
[300, 600]
];
var div_2_sizes = [
[728, 90],
[970, 250]
];
var PREBID_TIMEOUT = 1000;
var FAILSAFE_TIMEOUT = 3000;
var adUnits = [
{
code: '/19968336/header-bid-tag-0',
mediaTypes: {
banner: {
sizes: div_1_sizes
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13144370
}
}]
},
{
code: '/19968336/header-bid-tag-1',
mediaTypes: {
banner: {
sizes: div_2_sizes
}
},
bids: [{
bidder: 'appnexus',
params: {
placementId: 13144370
}
}]
}
];
function send(bid) {
var data = {
placementId: bid.params[0].placementId,
publisher_billing_uuid: bid.adserverTargeting.publisher_billing_uuid,
bidId: bid.adId,
requestId: bid.requestId,
auctionId: bid.auctionId,
transactionId: bid.transactionId,
bidder: bid.bidder,
originalCpm: bid.originalCpm,
originalCurrency: bid.originalCurrency,
cpm: bid.cpm,
currency: bid.currency,
adUnitCode: bid.adUnitCode,
netRevenue: bid.netRevenue,
dchain: bid.meta.dchain
};
var http = new XMLHttpRequest();
var url = 'https://test.theenergygrid.com/endpoint';
http.open('POST', url, true);
http.setRequestHeader('Content-Type', 'application/json;charset=UTF-8');
http.send(JSON.stringify(data));
}
pbjs.onEvent('bidWon', function (bid) {
console.log('Bid won:', bid);
send(bid);
});
// ======== DO NOT EDIT BELOW THIS LINE =========== //
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});
var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.bidderSettings = {
appnexus: {
adserverTargeting: [
{
key: "publisher_billing_uuid", // Use key configured in your adserver
val: function (bidResponse) {
return '123';
}
}
]
}
};
pbjs.que.push(function () {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: initAdserver,
timeout: PREBID_TIMEOUT
});
});
function initAdserver() {
if (pbjs.initAdserverSet) return;
pbjs.initAdserverSet = true;
googletag.cmd.push(function () {
pbjs.que.push(function () {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
googletag.pubads().setTargeting('exchain_id', [11223344]);
}
// in case PBJS doesn't load
setTimeout(function () {
initAdserver();
}, FAILSAFE_TIMEOUT);
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', div_1_sizes, 'div-1').addService(googletag.pubads());
googletag.defineSlot('/19968336/header-bid-tag-1', div_2_sizes, 'div-2').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
Ads test page (Prebid, google tag)
Div-1
googletag.cmd.push(function () {
googletag.display('div-1');
});
Div-2
googletag.cmd.push(function () {
googletag.display('div-2');
});