Skip to content

Commit

Permalink
- New Adapter: Innity (#1074)
Browse files Browse the repository at this point in the history
* Oct 27

Oct 27

* Added Innity

Innity Adapter

* Innity GPT Test Page

* Restore Master pbjs_example_gpt.html

* Changes based on jaiminpanchal27 feedback

- Align innity in adapters.json
- Format innity_spec.js
- Add bidRequest into innity.js

* Fixed formatting and remove unnecessary code (#1074)
  • Loading branch information
engtat authored and Matt Kendall committed Apr 14, 2017
1 parent 2a7298f commit 4257158
Show file tree
Hide file tree
Showing 4 changed files with 313 additions and 0 deletions.
1 change: 1 addition & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"gumgum",
"hiromedia",
"indexExchange",
"innity",
"kruxlink",
"getintent",
"inneractive",
Expand Down
94 changes: 94 additions & 0 deletions integrationExamples/gpt/pbjs_innity_gpt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<!-- Prebid Config Section START -->
<!-- Make sure this is inserted before your GPT tag -->
<script>
var PREBID_TIMEOUT = 1000;

var adUnits = [{
code: 'div-gpt-ad-1460505748561-0',
sizes: [[300, 250]],
bids: [{
bidder: 'innity',
params: {
pub: 267,
zone: 62546
}
}
]
}];

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

</script>
<!-- Prebid Config Section END -->

<!-- Prebid Boilerplate Section START. No Need to Edit. -->
<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>
<!-- Prebid Boilerplate Section END -->

<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]], '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>
56 changes: 56 additions & 0 deletions src/adapters/innity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader.js');
var utils = require('../utils.js');
var CONSTANTS = require('../constants.json');

var InnityAdapter = function InnityAdapter() {

function _callBids(params) {
var bidURL, bids = params.bids || [], requestURL = window.location.protocol + '//as.innity.com/synd/?cb=' + new Date().getTime() + '&ver=2&hb=1&output=js&';
for (var i = 0; i < bids.length; i++) {
var requestParams = {}, bid = bids[i];
requestParams.pub = bid.params.pub;
requestParams.zone = bid.params.zone;
// Page URL
requestParams.url = utils.getTopWindowUrl();
// Sizes
var parseSized = utils.parseSizesInput(bid.sizes), arrSize = parseSized[0].split('x');
requestParams.width = arrSize[0];
requestParams.height = arrSize[1];
// Callback function
requestParams.callback = "$$PREBID_GLOBAL$$._doInnityCallback";
// Callback ID
requestParams.callback_uid = bid.bidId;
// Load Bidder URL
bidURL = requestURL + utils.parseQueryStringParameters(requestParams);
utils.logMessage('Innity.prebid, Bid ID: ' + bid.bidId + ', Pub ID: ' + bid.params.pub + ', Zone ID: ' + bid.params.zone + ', URL: ' + bidURL);
adloader.loadScript(bidURL);
}
}

$$PREBID_GLOBAL$$._doInnityCallback = function(response) {
var bidObject, bidRequest, callbackID, libURL = window.location.protocol + "//cdn.innity.net/frame_util.js";
callbackID = response.callback_uid;
bidRequest = utils.getBidRequest(callbackID);
if (response.cpm > 0) {
bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidRequest);
bidObject.bidderCode = 'innity';
bidObject.cpm = parseFloat(response.cpm) / 100;
bidObject.ad = '<script src="' + libURL + '"></script>' + response.tag;
bidObject.width = response.width;
bidObject.height = response.height;
} else {
bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest);
bidObject.bidderCode = 'innity';
utils.logMessage('No Bid response from Innity request: ' + callbackID);
}
bidmanager.addBidResponse(bidRequest.placementCode, bidObject);
};

return {
callBids: _callBids
};
};

module.exports = InnityAdapter;
162 changes: 162 additions & 0 deletions test/spec/adapters/innity_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
describe('innity adapter tests', function () {

var expect = require('chai').expect;
var urlParse = require('url-parse');
var querystringify = require('querystringify');
var adapter = require('src/adapters/innity');
var adLoader = require('src/adloader');
var bidmanager = require('src/bidmanager');

var stubLoadScript;

beforeEach(function () {
stubLoadScript = sinon.stub(adLoader, 'loadScript');
});

afterEach(function () {
stubLoadScript.restore();
});

describe('creation of bid url', function () {

if (typeof($$PREBID_GLOBAL$$._bidsReceived) === "undefined") {
$$PREBID_GLOBAL$$._bidsReceived = [];
}
if (typeof($$PREBID_GLOBAL$$._bidsRequested) === "undefined") {
$$PREBID_GLOBAL$$._bidsRequested = [];
}

it('bid request for single placement', function () {

var params = {
bids: [{
placementCode: '/19968336/header-bid-tag-0',
sizes: [[300,250]],
bidId: 'b12345',
bidder: 'innity',
params: { pub: '267', zone: '62546' }
}]
};

adapter().callBids(params);

var bidUrl = stubLoadScript.getCall(0).args[0];

sinon.assert.calledOnce(stubLoadScript);

var parsedBidUrl = urlParse(bidUrl);
var parsedBidUrlQueryString = querystringify.parse(parsedBidUrl.query);

expect(parsedBidUrlQueryString).to.have.property('pub').and.to.equal('267');
expect(parsedBidUrlQueryString).to.have.property('zone').and.to.equal('62546');
expect(parsedBidUrlQueryString).to.have.property('width').and.to.equal('300');
expect(parsedBidUrlQueryString).to.have.property('height').and.to.equal('250');
});
});

describe('handling bid response', function () {
it('should return complete bid response', function() {

var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse');

var params = {
bids: [{
placementCode: '/19968336/header-bid-tag-0',
sizes: [[300,250]],
bidId: 'b12345',
bidder: 'innity',
params: { pub: '267', zone: '62546' }
}]
};

var response = {
cpm: 100,
width: 300,
height: 250,
callback_uid: 'b12345',
tag: '<script>document.write("this is a campaign banner");<\/script>'
};

adapter().callBids(params);

var adUnits = [];
var unit = {};
unit.bids = params.bids;
unit.code = '/123456/header-bid-tag-1';
unit.sizes = [[300,250]];
adUnits.push(unit);

if (typeof($$PREBID_GLOBAL$$._bidsRequested) === "undefined") {
$$PREBID_GLOBAL$$._bidsRequested = [params];
} else {
$$PREBID_GLOBAL$$._bidsRequested.push(params);
}

$$PREBID_GLOBAL$$.adUnits = adUnits;

$$PREBID_GLOBAL$$._doInnityCallback(response);

var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
var bidObject1 = stubAddBidResponse.getCall(0).args[1];

expect(bidPlacementCode1).to.equal('/19968336/header-bid-tag-0');
expect(bidObject1.bidderCode).to.equal('innity');
expect(bidObject1.cpm).to.equal(1);
expect(bidObject1.width).to.equal(300);
expect(bidObject1.height).to.equal(250);
expect(bidObject1.ad).to.have.length.above(1);

stubAddBidResponse.restore();
});

it('should return no bid response', function() {

var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse');

var params = {
bids: [{
placementCode: '/19968336/header-bid-tag-0',
sizes: [[300,250]],
bidId: 'b12345',
bidder: 'innity',
params: { pub: '267', zone: '7958' }
}]
};

var response = {
cpm: 0,
width: 300,
height: 250,
callback_uid: 'b12345',
tag: '<script>document.write("this is a default banner");<\/script>'
};

adapter().callBids(params);

var adUnits = [];
var unit = {};
unit.bids = params.bids;
unit.code = '/123456/header-bid-tag-1';
unit.sizes = [[300,250]];
adUnits.push(unit);

if (typeof($$PREBID_GLOBAL$$._bidsRequested) === "undefined") {
$$PREBID_GLOBAL$$._bidsRequested = [params];
} else {
$$PREBID_GLOBAL$$._bidsRequested.push(params);
}

$$PREBID_GLOBAL$$.adUnits = adUnits;

$$PREBID_GLOBAL$$._doInnityCallback(response);

var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0];
var bidObject1 = stubAddBidResponse.getCall(0).args[1];

expect(bidPlacementCode1).to.equal('/19968336/header-bid-tag-0');
expect(bidObject1.bidderCode).to.equal('innity');

stubAddBidResponse.restore();
});
});
});

0 comments on commit 4257158

Please sign in to comment.