Skip to content

Gjirafa Bidder Adapter #1944

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

Merged
merged 10 commits into from
Jan 4, 2018
Merged
Show file tree
Hide file tree
Changes from 7 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -77,3 +77,5 @@ typings/

# MacOS system files
.DS_Store

modules.json
Copy link
Member

Choose a reason for hiding this comment

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

please drop

Copy link
Contributor Author

Choose a reason for hiding this comment

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

dropped

263 changes: 173 additions & 90 deletions integrationExamples/gpt/hello_world.html
Original file line number Diff line number Diff line change
@@ -1,102 +1,185 @@
<!--

This page calls a single bidder for a single ad slot. It can be considered a "hello world" example for using
Prebid with the Google Publisher Tag.

It also makes a good test page for new adapter PR submissions. Simply set your server's Bid Params object in the
bids array inside the adUnits, and it will use your adapter to load an ad.

NOTE that many ad servers won't send back an ad if the URL is localhost... so you might need to
set an alias in your /etc/hosts file so that you can load this page from a different domain.

-->

<html>
<head>
<script>
var PREBID_TIMEOUT = 700;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250], [300,600]],

// Replace this object to test a new Adapter!
bids: [{
bidder: 'appnexusAst',
params: {
placementId: '10433394'
<head>
Copy link
Member

Choose a reason for hiding this comment

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

drop changes to this file please

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just dropped them.

<script>
var PREBID_TIMEOUT = 21000;

function initAdserver(bidResponses) {
for(var unit in bidResponses){
var adSlot = document.getElementById(unit);
var params = pbjs.getAdserverTargetingForAdUnitCode(unit);
if(adSlot){
if(params && params['hb_adid']){
pbjs.renderAd(adSlot.contentWindow.document, params['hb_adid']);
} else {
loadedAdUnits.push(unit);
}
}
}
initPassbacks();
}

function initPassbacks(){
adUnits.map(function(ad){
if(loadedAdUnits.indexOf(ad.code) > -1) {
if(passbacks[ad.code] && passbacks[ad.code].length > 0){
var adSlot = document.getElementById(ad.code);
adSlot.contentWindow.document.write(passbacks[ad.code]);
} else {
document.getElementById(ad.code).remove();
}
}
});
}

var passbacks = {
// "hb-rectangle": "",
// "hb-leaderboard": "",
"hb-inarticle": "",
"hb-mob1": "",
// "hb-mob2": ""
};

var useSSL = 'https:' == document.location.protocol;

function hasClass(element, cls) {
return (' ' + element.className + ' ').indexOf(' ' + cls + ' ') > -1;
}

function isMobile(){
return /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
}

var inarticle = {
code: 'hb-inarticle',
sizes: [[300, 250]],
bids: [
{ bidder: "gjirafa", params: { minCPM: 0.0001, minCPC: 0.001, explicit: true } }
]
};

<!-- var rectangle1 = { -->
<!-- code: 'hb-rectangle', -->
<!-- sizes: [[300, 250], [300, 600], [300, 400]], -->
<!-- bids: [ -->
<!-- { bidder: "gjirafa", params: { minCPM: 0.0001, minCPC: 0.001, explicit: true } } -->
<!-- ] -->
<!-- }; -->

<!-- var leaderboard = { -->
<!-- code: 'hb-leaderboard', -->
<!-- sizes: [[728, 90], [980, 200], [980, 150], [970, 90], [970, 250]], -->
<!-- bids: [ -->
<!-- { bidder: "gjirafa", params: { placementId: '71-3' } } -->
<!-- ] -->
<!-- }; -->

var mob1 = {
code: 'hb-mob1',
sizes: [[320, 50], [300, 100], [300, 70], [300, 50], [300, 250]],
bids: [
{ bidder: "gjirafa", params: { minCPM: 0.0001, minCPC: 0.001, explicit: true } }
]
};

<!-- var mob2 = { -->
<!-- code: 'hb-mob2', -->
<!-- sizes: [[320, 50], [300, 100], [300, 70], [300, 50], [300, 250]], -->
<!-- bids: [ -->
<!-- { bidder: "gjirafa", params: { minCPM: 0.0001, minCPC: 0.001, explicit: true } } -->
<!-- ] -->
<!-- }; -->

var adUnits = [];
var loadedAdUnits = [];
if(!isMobile()){
adUnits.push(inarticle);//, rectangle1, leaderboard);
} else {
adUnits.push(mob1);//, mob2);
}

var pbjs = pbjs || {};
pbjs.que = pbjs.que || [];
pbjs.que.push(function() {
pbjs.setConfig({
priceGranularity: 'dense'
});
});

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 Math.round(((bidResponse.cpm) * 10) / 10).toFixed(2);
if(bidResponse.cpm >= 0.0001)
return Math.round(((bidResponse.cpm * 1000.00) * 10) / 10).toFixed(2);
else
return Math.round(((bidResponse.cpm * 10000.00) * 10) / 10).toFixed(2);
}
}, {
key: 'hb_size',
val: function (bidResponse) {
return bidResponse.size;
}
}]
}
};
</script>

<script type="text/javascript" src="../../build/dev/prebid.js" async></script>
<script>
pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
//pbjs.setBidderSequence('random');
pbjs.aliasBidder('appnexus', 'springserve');
pbjs.requestBids({
bidsBackHandler: function (bidResponses) {
initAdserver(bidResponses);
}
}]

}];

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

</script>

<script type="text/javascript" src="../../build/dev/prebid.js" async></script>
<script>
var googletag = googletag || {};
googletag.cmd = googletag.cmd || [];
googletag.cmd.push(function() {
googletag.pubads().disableInitialLoad();
});

pbjs.que.push(function() {
pbjs.addAdUnits(adUnits);
pbjs.requestBids({
bidsBackHandler: sendAdserverRequest
});
});

function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
googletag.cmd.push(function() {
pbjs.que.push(function() {
pbjs.setTargetingForGPTAsync();
googletag.pubads().refresh();
});
});
}

setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);

</script>

<script>
(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);
})();
</script>

<script>
googletag.cmd.push(function () {
googletag.defineSlot('/19968336/header-bid-tag-0', [[300, 250], [300, 600]], 'div-gpt-ad-1460505748561-0').addService(googletag.pubads());

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

<body>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>
<div id='div-gpt-ad-1460505748561-0'>
<script type='text/javascript'>
googletag.cmd.push(function() { googletag.display('div-gpt-ad-1460505748561-0'); });
</script>
</div>
</body>
</html>
});
function sendAdserverRequest() {
if (pbjs.adserverRequestSent) return;
pbjs.adserverRequestSent = true;
}
setTimeout(function() {
sendAdserverRequest();
}, PREBID_TIMEOUT);
</script>
</head>

<body>
<h2>Prebid.js Test</h2>
<h5>Div-1</h5>

<iframe id='hb-inarticle' width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;">
</iframe>
<!-- <iframe id='hb-rectangle' width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;"> -->
<!-- </iframe> -->
<!-- <iframe id='hb-leaderboard' width="728" height="90" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;"> -->
<!-- </iframe> -->
<iframe id='hb-mob1' width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;">
</iframe>
<!-- <iframe id='hb-mob2' width="300" height="250" scrolling="no" marginwidth="0" marginheight="0" frameborder="0" srcdoc="" style="border: 0px; vertical-align: bottom;"> -->
<!-- </iframe> -->
</body>
</html>
91 changes: 91 additions & 0 deletions modules/gjirafaBidAdapter.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as utils from 'src/utils';
import {registerBidder} from 'src/adapters/bidderFactory';

const BIDDER_CODE = 'gjirafa';
const ENDPOINT_URL = 'https://gjc.gjirafa.com/Home/GetBid';
const DIMENSION_SEPARATOR = 'x';
const SIZE_SEPARATOR = ';';

export const spec = {
code: BIDDER_CODE,
/**
* Determines whether or not the given bid request is valid.
*
* @param {BidRequest} bid The bid params to validate.
* @return boolean True if this is a valid bid, and false otherwise.
*/
isBidRequestValid: function(bid) {
return bid.params && (!!bid.params.placementId || (!!bid.params.minCPM && !!bid.params.minCPC));
},
/**
* Make a server request from the list of BidRequests.
*
* @param {validBidRequests[]} - an array of bids
* @return ServerRequest Info describing the request to the server.
*/
buildRequests: function(validBidRequests, bidderRequest) {
return validBidRequests.map(bidRequest => {
let gjid = Math.floor(Math.random() * 99999999);
let sizes = generateSizeParam(bidRequest.sizes);
let configId = bidRequest.params.placementId || '';
let minCPM = bidRequest.params.minCPM || 0.0;
let minCPC = bidRequest.params.minCPC || 0.0;
let allowExplicit = bidRequest.params.explicit || 0;
const body = {
gjid: gjid,
sizes: sizes,
configId: configId,
minCPM: minCPM,
minCPC: minCPC,
allowExplicit: allowExplicit,
referrer: utils.getTopWindowUrl(),
requestid: bidRequest.bidderRequestId,
bidid: bidRequest.bidId
};
if (document.referrer) {
body.referrer = document.referrer;
}
return {
method: 'GET',
url: ENDPOINT_URL,
data: body
};
});
},
/**
* Unpack the response from the server into a list of bids.
*
* @param {ServerResponse} serverResponse A successful response from the server.
* @return {Bid[]} An array of bids which were nested inside the server.
*/
interpretResponse: function(serverResponse, bidRequest) {
const serverBody = serverResponse.body;
const bidResponses = [];
const bidResponse = {
requestId: bidRequest.data.bidid,
cpm: serverBody.CPM,
width: serverBody.Width,
height: serverBody.Height,
creativeId: serverBody.CreativeId,
currency: serverBody.Currency,
netRevenue: serverBody.NetRevenue,
ttl: serverBody.TTL,
referrer: serverBody.Referrer,
ad: serverBody.Ad
};
bidResponses.push(bidResponse);
return bidResponses;
}
}

/**
* Generate size param for bid request using sizes array
*
* @param {Array} sizes Possible sizes for the ad unit.
* @return {string} Processed sizes param to be used for the bid request.
*/
function generateSizeParam(sizes) {
return sizes.map(size => size.join(DIMENSION_SEPARATOR)).join(SIZE_SEPARATOR);
}

registerBidder(spec);
Loading