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

C1x Adapter (already rebased the current Prebid.js code) #1

Closed
wants to merge 15 commits into from
Closed
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
172 changes: 172 additions & 0 deletions integrationExamples/gpt/c1x-prebid-cathytest.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<!DOCTYPE html>
<html>
<head>
<title>Prebid.js integration example</title>
<script>
var PREBID_TIMEOUT = 2000;
var MAX_RETRIES = 20;

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function () {
googletag.pubads().disableInitialLoad();
});

var pbjs = pbjs || {};
pbjs.cmd = pbjs.cmd || [];
pbjs.retries = 0;

/* pbjs.initAdserver will be called either when all bids are back, or
when the timeout is reached.
*/
function initAdserver() {
if (pbjs.initAdserverSet) return;
googletag.cmd.push(function () {
pbjs.cmd.push(function () {
pbjs.setTargetingForGPTAsync();
});
googletag.pubads().refresh();
});
pbjs.initAdserverSet = true;
}

// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);

// Load the Prebid Javascript Library Async. We recommend loading it immediately after the initAdserver() and setTimeout functions.
(function() {
var d = document, pbs = d.createElement('script'), pro = d.location.protocol;
pbs.type = 'text/javascript';
pbs.src = '../../build/dev/prebid.js';
var target = document.getElementsByTagName('head')[0];
target.insertBefore(pbs, target.firstChild);
})();

//load GPT library here
(function () {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();

pbjs.cmd.push(function () {

/* 1. Register bidder tag Ids

Registers the bidder tags for your ad units. Once the prebid.js
library loads, it reads the pbjs.adUnits object and sends out
bid requests.

code: Your GPT slot’s ad unit path. If they don’t match, prebid.js
would not be able to set targeting correctly
sizes: All sizes your ad unit accepts. They should match with GPT.

*/
var adUnits = [
{
code: 'div-gpt-ad-1498193081995-0',
sizes: [[300, 250], [300, 600]],
bids: [
// 1 ad unit can be targeted by multiple bids.
{
bidder: 'c1x'
}
]
}
];

//add the adUnits
pbjs.addAdUnits(adUnits);

//register a callback handler
pbjs.onEvent('bidResponse', function (bidResponse) {
console.log('A bid response has arrived:');
});

/* Configure Ad Server Targeting
The below section defines what key value targeting will be sent to GPT.
*/
pbjs.bidderSettings = {
standard: {
adserverTargeting: [
{
key: "hb_bidder",
val: function (bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function (bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function (bidResponse) {
return bidResponse.pbMg;
}
}, {
key: 'hb_size',
val: function (bidResponse) {
return bidResponse.size;
}
}
]
},
c1x: {
pixelId: 99999, //optional
siteId: 999,
endpoint: 'http://ht-integration.c1exchange.com:9000/ht', //optional
floorPriceMap: {
'300x250': 4.00,
'300x600': 3.00
}, //optional
dspid: 0704 //optional
}
};

/* Request bids for the added ad units. If adUnits or adUnitCodes are
not specified, the function will request bids for all added ad units.
*/
pbjs.requestBids({

/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
*/
bidsBackHandler: function (bidResponses) {
// c1x.logs.push([new Date().getTime(), 'Bids back handler called.']);
console.log('all the bid responses are back');
console.log(bidResponses);
initAdserver();
}
});

});

googletag.cmd.push(function() {
googletag.defineSlot('/188708772/cathy-test-unit', [[300, 250], [300, 600]], 'div-gpt-ad-1498193081995-0').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();
});

</script>

</head>
<body>

<h2>Prebid.js Test</h2>

<!-- /188708772/cathy-test-unit -->
<div id='div-gpt-ad-1498193081995-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1498193081995-0'); });
</script>
</div>

</body>

</html>
162 changes: 162 additions & 0 deletions integrationExamples/gpt/c1x-test-prebid.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title></title>

<script>
var PREBID_TIMEOUT = 700;

var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

/* pbjs.initAdserver will be called either when all bids are back, or
when the timeout is reached.
*/
function initAdserver() {
if (pbjs.initAdserverSet) return;
//load GPT library here
(function() {
var gads = document.createElement('script');
gads.async = true;
gads.type = 'text/javascript';
var useSSL = 'https:' == document.location.protocol;
gads.src = (useSSL ? 'https:' : 'http:') +
'//www.googletagservices.com/tag/js/gpt.js';
var node = document.getElementsByTagName('script')[0];
node.parentNode.insertBefore(gads, node);
})();
pbjs.initAdserverSet = true;
};
// Load GPT when timeout is reached.
setTimeout(initAdserver, PREBID_TIMEOUT);

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];

// Load the Prebid Javascript Library Async. We recommend loading it immediately after
// the initAdserver() and setTimeout functions.
(function() {
var d = document, pbs = d.createElement("script"), pro = d.location.protocol;
pbs.type = "text/javascript";
pbs.src = '../../build/dist/prebid.js';
var target = document.getElementsByTagName("head")[0];
target.insertBefore(pbs, target.firstChild);
})();

pbjs.que.push(function(){

/* 1. Register bidder tag Ids

Registers the bidder tags for your ad units. Once the prebid.js
library loads, it reads the pbjs.adUnits object and sends out
bid requests. Find the complete reference on bidders at
http://prebid.org/bidders.html.

code: Your GPT slot’s ad unit path. If they don’t match, prebid.js
would not be able to set targeting correctly
sizes: All sizes your ad unit accepts. They should match with GPT.

*/
var adUnits = [{
code: 'div-gpt-ad-1494499685659-0',
sizes: [[300, 250]],
bids: [
{
bidder: 'c1x'

}
]
}];

//add the adUnits
pbjs.addAdUnits(adUnits);


pbjs.bidderSettings = {
'c1x': {
pixelId: 9999,
siteId: 999,
endpoint: 'http://ht-integration.c1exchange.com:9000/ht',
// endpoint: 'http://ht.c1exchange.com:8080/ht',
// endpoint: 'https://ht.c1exchange.com/ht',
floorPriceMap: {
'300x250': 4.00,
'728x90': 3.50,
'300x600': 6.00,
'160x600': 6.00
},
adserverTargeting: [{
key: "hb_bidder",
val: function(bidResponse) {
return bidResponse.bidderCode;
}
}, {
key: "hb_adid",
val: function(bidResponse) {
return bidResponse.adId;
}
}, {
key: "hb_pb",
val: function(bidResponse) {
return bidResponse.pbLg;
}
}
]
}
};

pbjs.requestBids({

/* The bidsBack function will be called when either timeout is
reached, or when all bids come back, whichever happens sooner.
*/
bidsBackHandler: function(bidResponses) {
initAdserver();
}

/* You can specify specific `adUnitCodes` to only request bids
for certain ad units.
adUnitCodes: ['code1', 'code2']
*/

/* You can also make one off bid requests for the given `adUnits`.
adUnits: [adUnit2, adUnit1]
*/

/* The bidsBackHandler will be executed either when all bids are
back, or when the timeout is reached.
timeout: 1000
*/
});

});

</script>

<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];

googletag.cmd.push(function() {
googletag.defineSlot('/188708772/Hb_test_300x250', [300, 250], 'div-gpt-ad-1494499685659-0').addService(googletag.pubads());

pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
});

googletag.pubads().enableSingleRequest();
googletag.enableServices();
});
</script>

</head>
<body>
<!-- /188708772/Hb_test_300x250 -->
<div id='div-gpt-ad-1494499685659-0' style='height:250px; width:300px;'>
<script>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1494499685659-0'); });
</script>
</div>
</body>
</html>
Loading