Skip to content

Commit

Permalink
feat(krux): add Krux Link adapter (#384)
Browse files Browse the repository at this point in the history
  • Loading branch information
Seth Yates authored and protonate committed Jun 15, 2016
1 parent d5b0e4f commit c951eac
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 24 deletions.
50 changes: 26 additions & 24 deletions integrationExamples/gpt/pbjs_example_gpt.html
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<!DOCTYPE html>
<html>

<head>

<title>Prebid.js integration example</title>
<script>

var PREBID_TIMEOUT = 700;

var googletag = googletag || {};
Expand Down Expand Up @@ -39,7 +38,7 @@
var d = document;
var pbs = d.createElement("script");
pbs.type = "text/javascript";
pbs.src = '/build/dist/prebid.js';
pbs.src = '/build/dev/prebid.js';
var target = d.getElementsByTagName("head")[0];
target.insertBefore(pbs, target.firstChild);
})();
Expand Down Expand Up @@ -171,7 +170,13 @@
bidder: 'adequant',
params: {
publisher_id: 5000563, // REQUIRED int or str publisher ID. To get one, register at https://control.adequant.com
bidfloor: 0.01, // OPTIONAL float bid floor in $ CPM
bidfloor: 0.01 // OPTIONAL float bid floor in $ CPM
}
},
{
bidder: 'kruxlink',
params: {
impid: 36
}
},
{
Expand Down Expand Up @@ -234,7 +239,7 @@
params: {
id: 'TO ADD', //String - required
siteID: 123, //Number - required
timeout: 456, //Number - Optional
timeout: 456 //Number - Optional
}
},
{
Expand All @@ -253,7 +258,13 @@
bidder: 'adequant',
params: {
publisher_id: 5000563, // REQUIRED int or str publisher ID. To get one, register at https://control.adequant.com
bidfloor: 0.01, // OPTIONAL float bid floor in $ CPM
bidfloor: 0.01 // OPTIONAL float bid floor in $ CPM
}
},
{
bidder: 'kruxlink',
params: {
impid: 37
}
},
{
Expand All @@ -272,7 +283,7 @@

//register a callback handler
pbjs.addCallback('adUnitBidsBack', function (adUnitCode) {
console.log('ad unit bids back for : ' + adUnitCode);
console.debug('ad unit bids back for:', adUnitCode);
});

/* Request bids for the added ad units. If adUnits or adUnitCodes are
Expand All @@ -285,7 +296,6 @@
*/
bidsBackHandler: function (bidResponses) {
initAdserver();

}

/* You can specify specific `adUnitCodes` to only request bids
Expand Down Expand Up @@ -371,27 +381,18 @@
]
}
};

});

</script>

<script>
googletag.cmd.push(function () {

var rightSlot = googletag.defineSlot('/9968336/header-bid-tag-0', [[300, 250],[300, 600]], 'div-gpt-ad-12345678-0').addService(googletag.pubads());
var topSlot = googletag.defineSlot('/9968336/header-bid-tag1', [[728, 90],[970, 90]], 'div-gpt-ad-12345678-1').addService(googletag.pubads());

googletag.defineSlot('/9968336/header-bid-tag-0', [[300, 250],[300, 600]], 'div-gpt-ad-12345678-0').addService(googletag.pubads());
googletag.defineSlot('/9968336/header-bid-tag1', [[728, 90],[970, 90]], 'div-gpt-ad-12345678-1').addService(googletag.pubads());
googletag.pubads().enableSingleRequest();
googletag.enableServices();

});


</script>
</head>


<body>

<h2>Prebid.js Test</h2>
Expand All @@ -405,7 +406,7 @@ <h2>Prebid.js Test</h2>
</div>


<div id='{id}'>
<div id='div-gpt-ad-12345678-1'>
<script type='text/javascript'>
googletag.cmd.push(function () {
googletag.display('div-gpt-ad-12345678-1');
Expand All @@ -414,8 +415,6 @@ <h2>Prebid.js Test</h2>
</div>


</body>

<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r;
Expand All @@ -430,16 +429,19 @@ <h2>Prebid.js Test</h2>
})(window, document, 'script', '//www.google-analytics.com/analytics.js', 'ga');

ga('create', 'XXXXXX', 'auto');

//Send data from prebid.js automatically
pbjs.que.push(function () {
pbjs.enableAnalytics({
provider: 'ga',
options: {
global: 'ga', // <string> name of GA global. Default is 'ga'
enableDistribution: false, // <bool> enable/disable distribution. Recommend disable to save bandwidth/calls
enableDistribution: false // <bool> enable/disable distribution. Recommend disable to save bandwidth/calls
}
});
});
</script>

</body>

</html>
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"aol",
"appnexus",
"indexExchange",
"kruxlink",
"openx",
"pubmatic",
"pulsepoint",
Expand Down
79 changes: 79 additions & 0 deletions src/adapters/kruxlink.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
var bidfactory = require('../bidfactory.js');
var bidmanager = require('../bidmanager.js');
var adloader = require('../adloader.js');

function _qs(key, value) {
return encodeURIComponent(key) + '=' + encodeURIComponent(value);
}

function _makeBidResponse(placementCode, bid) {
var bidResponse = bidfactory.createBid(bid !== undefined ? 1 : 2);
bidResponse.bidderCode = 'kruxlink';
if (bid !== undefined) {
bidResponse.cpm = bid.price;
bidResponse.ad = bid.adm;
bidResponse.width = bid.w;
bidResponse.height = bid.h;
}
bidmanager.addBidResponse(placementCode, bidResponse);
}

function _makeCallback(id, placements) {
var callback = '_kruxlink_' + id;
pbjs[callback] = function(response) {
// Clean up our callback
delete pbjs[callback];

// Add in the bid respones
for (var i = 0; i < response.seatbid.length; i++) {
var seatbid = response.seatbid[i];
for (var j = 0; j < seatbid.bid.length; j++) {
var bid = seatbid.bid[j];
_makeBidResponse(placements[bid.impid], bid);
delete placements[bid.impid];
}
}

// Add any no-bids remaining
for (var placementCode in placements) {
if (placements.hasOwnProperty(placementCode)) {
_makeBidResponse(placementCode);
}
}
};

return 'pbjs.' + callback;
}

function _callBids(params) {
var impids = [];
var placements = {};

var bids = params.bids || [];
for (var i = 0; i < bids.length; i++) {
var bidRequest = bids[i];
var bidRequestParams = bidRequest.params || {};
var impid = bidRequestParams.impid;
placements[impid] = bidRequest.placementCode;

impids.push(impid);
}

var callback = _makeCallback(params.bidderRequestId, placements);
var qs = [
_qs('id', params.bidderRequestId),
_qs('u', window.location.href),
_qs('impid', impids.join(',')),
_qs('calltype', 'pbd'),
_qs('callback', callback)
];
var url = 'https://link.krxd.net/hb?' + qs.join('&');

adloader.loadScript(url);
}

module.exports = function KruxAdapter() {
return {
callBids: _callBids
};
};

0 comments on commit c951eac

Please sign in to comment.