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

Inskin Bid Adapter - New Feature #4011

Merged
merged 4 commits into from
Jul 23, 2019
Merged
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
102 changes: 102 additions & 0 deletions integrationExamples/gpt/inskin_example.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
<!--
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 = 3300;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
mediaTypes: {
banner: {
sizes: [[300, 250]],
}
},
// Replace this object to test a new Adapter!
bids: [{
bidder: 'inskin',
params: {
networkId: '9874',
siteId: '983808'
}
}]

}];

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>
9 changes: 8 additions & 1 deletion modules/inskinBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,15 @@ export const spec = {

if (serverResponse) {
const decision = serverResponse.decisions && serverResponse.decisions[bidId];
const price = decision && decision.pricing && decision.pricing.clearPrice;
const data = decision && decision.contents && decision.contents[0] && decision.contents[0].data;
const pubCPM = data && data.customData && data.customData.pubCPM;
const clearPrice = decision && decision.pricing && decision.pricing.clearPrice;
const price = pubCPM || clearPrice;

if (decision && price) {
decision.impressionUrl += ('&property:pubcpm=' + price);
bidObj.price = price;

bid.requestId = bidId;
bid.cpm = price;
bid.width = decision.width;
Expand Down Expand Up @@ -149,6 +155,7 @@ export const spec = {
const id = 'ism_tag_' + Math.floor((Math.random() * 10e16));
window[id] = {
bidId: e.data.bidId,
bidPrice: bidsMap[e.data.bidId].price,
serverResponse
};
const script = document.createElement('script');
Expand Down
10 changes: 10 additions & 0 deletions test/spec/modules/inskinBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ const RESPONSE = {
'type': 'html',
'body': '<html></html>',
'data': {
'customData': {
'pubCPM': 1
},
'height': 90,
'width': 728,
'imageUrl': 'https://static.adzerk.net/Advertisers/b0ab77db8a7848c8b78931aed022a5ef.gif',
Expand Down Expand Up @@ -241,6 +244,13 @@ describe('InSkin BidAdapter', function () {
});
});

it('cpm is correctly set', function () {
let bids = spec.interpretResponse(RESPONSE, REQUEST);

expect(bids[0].cpm).to.equal(0.5);
expect(bids[1].cpm).to.equal(1);
});

it('handles nobid responses', function () {
let EMPTY_RESP = Object.assign({}, RESPONSE, {'body': {'decisions': null}})
let bids = spec.interpretResponse(EMPTY_RESP, REQUEST);
Expand Down