From c1ddbf9024085036b050c99237c2a2643b6757a2 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 31 Aug 2017 14:09:38 +0530 Subject: [PATCH 1/6] added the c1x code shared by partner --- src/adapters/c1x.js | 114 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 114 insertions(+) create mode 100644 src/adapters/c1x.js diff --git a/src/adapters/c1x.js b/src/adapters/c1x.js new file mode 100644 index 00000000000..e9f9ccb9da3 --- /dev/null +++ b/src/adapters/c1x.js @@ -0,0 +1,114 @@ +var CONSTANTS = require('src/constants.json'); +var utils = require('src/utils.js'); +var bidfactory = require('src/bidfactory.js'); +var bidmanager = require('src/bidmanager.js'); +var adloader = require('src/adloader'); +/** + * Adapter for requesting bids from C1X header tag server. + * v0.3 (c) C1X Inc., 2016 + * + * @param {Object} options - Configuration options for C1X + * + * @returns {{callBids: _callBids}} + * @constructor + */ +var C1XAdapter = function C1XAdapter() { + // default endpoint. Can be overridden by adding an "endpoint" property to the first param in bidder config. + var ENDPOINT = 'https://ht.c1exchange.com/ht', + PIXEL_ENDPOINT = '//px.c1exchange.com/pubpixel/', + PIXEL_FIRE_DELAY = 3000; + function getSettings(key) { + var pbjs = window.pbjs; + if (pbjs && pbjs.bidderSettings) { + var c1xSettings = pbjs.bidderSettings['c1x']; + if (c1xSettings) { + return c1xSettings[key]; + } + } + return null; + } + // inject the audience pixel only if pbjs.bidderSettings['c1x'].pixelId is set. + function injectAudiencePixel() { + var pixelId = getSettings('pixelId'); + if (pixelId) { + window.setTimeout(function() { + var pixel = document.createElement('img'); + pixel.width = 1; + pixel.height = 1; + pixel.style='display:none;’; + var useSSL = document.location.protocol == 'https:'; + pixel.src = (useSSL ? 'https:' : 'http:') + + PIXEL_ENDPOINT + pixelId; + document.body.insertBefore(pixel, null); + }, PIXEL_FIRE_DELAY); + } + } + function _callBids(params) { + injectAudiencePixel(); + // serialize all the arguments and send it to C1X header bidder. + // example: ?site=goodsite.com&adunits=2&a1=gpt-34-banner1&a1s=[300x250]&a2=gpt-36-right-center&a2s=[300x200,300x600] + var siteId = getSettings('siteId'); + if (!siteId) { + utils.logError('c1x: error - no site id supplied!'); + return; + } + var bids = params.bids, + options = ['adunits=' + bids.length]; + options.push('site=' + siteId); + for (var i = 0; i < bids.length; i++) { + options.push('a' + (i + 1) + '=' + bids[i].placementCode); + var sizes = bids[i].sizes, + sizeStr = sizes.reduce(function(prev, current) { return prev + (prev === '' ? '' : ',') + current.join('x') }, ''); + // send floor price if the setting is available. + var floorPriceMap = getSettings('floorPriceMap'); + console.log('floor price map: ', floorPriceMap); + console.log('size: ' + sizes[0]); + if (floorPriceMap) { + var adUnitSize = sizes[0].join('x'); + if (adUnitSize in floorPriceMap) { + options.push('a' + (i + 1) + 'p=' + floorPriceMap[adUnitSize]); + } + } + options.push('a' + (i + 1) + 's=[' + sizeStr + ']'); + } + options.push('rnd=' + new Date().getTime()); + options.push('cbmn=_inuxuAdzebraResponse'); + // cache busting + var c1xEndpoint = ENDPOINT; + if (getSettings('endpoint')) { + c1xEndpoint = getSettings('endpoint'); + } + if (getSettings('dspid')) { + options.push('dspid=' + getSettings('dspid')); + } + var url = c1xEndpoint + '?' + options.join('&'); + window._inuxuAdzebraResponse = function(response) { + for (var i = 0; i < response.length; i++) { + var data = response[i], + bidObject = null; + if (data.bid) { + bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD); + bidObject.bidderCode = 'c1x'; + bidObject.cpm = data.cpm; + bidObject.ad = data.ad; + bidObject.width = data.width; + bidObject.height = data.height; + console.log('c1x: INFO creating bid for adunit: ' + data.adId + ' size: ' + data.width + 'x' + data.height); + } else { + // no bid. + bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID); + bidObject.bidderCode = 'c1x'; + console.log('c1x: INFO creating a NO bid for adunit: ' + data.adId); + } + bidmanager.addBidResponse(data.adId, bidObject); + } + } + adloader.loadScript(url); + } + // Export the callBids function, so that prebid.js can execute this function + // when the page asks to send out bid requests. + return { + callBids: _callBids + }; +}; +module.exports = C1XAdapter; From 832b9c9aff1425a1abbc7585abcc3f5488947941 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 31 Aug 2017 14:21:31 +0530 Subject: [PATCH 2/6] changes made to make c1x work --- src/adapters/c1x.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/adapters/c1x.js b/src/adapters/c1x.js index e9f9ccb9da3..080f367d244 100644 --- a/src/adapters/c1x.js +++ b/src/adapters/c1x.js @@ -1,8 +1,8 @@ -var CONSTANTS = require('src/constants.json'); -var utils = require('src/utils.js'); -var bidfactory = require('src/bidfactory.js'); -var bidmanager = require('src/bidmanager.js'); -var adloader = require('src/adloader'); +var CONSTANTS = require('../constants.json'); +var utils = require('../utils.js'); +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader'); /** * Adapter for requesting bids from C1X header tag server. * v0.3 (c) C1X Inc., 2016 @@ -35,7 +35,7 @@ var C1XAdapter = function C1XAdapter() { var pixel = document.createElement('img'); pixel.width = 1; pixel.height = 1; - pixel.style='display:none;’; + pixel.style='display:none;'; var useSSL = document.location.protocol == 'https:'; pixel.src = (useSSL ? 'https:' : 'http:') + PIXEL_ENDPOINT + pixelId; From 50c86b0c7873cf5e24896dc70098dbdb3e640e72 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Thu, 31 Aug 2017 14:41:57 +0530 Subject: [PATCH 3/6] need to add c1x entry --- adapters.json | 1 + 1 file changed, 1 insertion(+) diff --git a/adapters.json b/adapters.json index 71dc5fbb0a2..a2173e81441 100644 --- a/adapters.json +++ b/adapters.json @@ -15,6 +15,7 @@ "appnexusAst", "beachfront", "audienceNetwork", + "c1x", "carambola", "conversant", "districtmDMX", From a98334f5260dcbd79dc174c1046534935c867f90 Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 4 Sep 2017 14:46:00 +0530 Subject: [PATCH 4/6] c1x: for accepting all params from bid.params --- src/adapters/c1x.js | 86 ++++++++++++++++++++++++++++----------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/src/adapters/c1x.js b/src/adapters/c1x.js index 080f367d244..a9f5a9fd0fa 100644 --- a/src/adapters/c1x.js +++ b/src/adapters/c1x.js @@ -17,19 +17,9 @@ var C1XAdapter = function C1XAdapter() { var ENDPOINT = 'https://ht.c1exchange.com/ht', PIXEL_ENDPOINT = '//px.c1exchange.com/pubpixel/', PIXEL_FIRE_DELAY = 3000; - function getSettings(key) { - var pbjs = window.pbjs; - if (pbjs && pbjs.bidderSettings) { - var c1xSettings = pbjs.bidderSettings['c1x']; - if (c1xSettings) { - return c1xSettings[key]; - } - } - return null; - } - // inject the audience pixel only if pbjs.bidderSettings['c1x'].pixelId is set. - function injectAudiencePixel() { - var pixelId = getSettings('pixelId'); + + // inject the audience pixel only if pixelId is set. + function injectAudiencePixel(pixelId) { if (pixelId) { window.setTimeout(function() { var pixel = document.createElement('img'); @@ -43,27 +33,55 @@ var C1XAdapter = function C1XAdapter() { }, PIXEL_FIRE_DELAY); } } + function _callBids(params) { - injectAudiencePixel(); // serialize all the arguments and send it to C1X header bidder. // example: ?site=goodsite.com&adunits=2&a1=gpt-34-banner1&a1s=[300x250]&a2=gpt-36-right-center&a2s=[300x200,300x600] - var siteId = getSettings('siteId'); - if (!siteId) { - utils.logError('c1x: error - no site id supplied!'); - return; - } + var bids = params.bids, - options = ['adunits=' + bids.length]; - options.push('site=' + siteId); + options = ['adunits=' + bids.length], + siteId = null, + dspId = null, + c1xEndpoint = ENDPOINT; + for (var i = 0; i < bids.length; i++) { - options.push('a' + (i + 1) + '=' + bids[i].placementCode); - var sizes = bids[i].sizes, + var bid = bids[i]; + + if (!bid.params.siteId) { + utils.logError('c1x: error - no site id supplied!'); + continue; + } + + // siteid should be set only once in request + if (siteId == null) { + siteId = bid.params.siteId; + options.push('site=' + siteId); + } + + // dspid should be set only once in request + if (dspId == null && bid.params.dspid) { + dspId = bid.params.dspid; + } + + if(bid.params.pixelId){ + injectAudiencePixel(bid.params.pixelId); + } + + // use default endpoint if not provided dynamically + if (bid.params.endpoint) { + c1xEndpoint = bid.params.endpoint; + } + + options.push('a' + (i + 1) + '=' + bid.placementCode); + var sizes = bid.sizes, sizeStr = sizes.reduce(function(prev, current) { return prev + (prev === '' ? '' : ',') + current.join('x') }, ''); + // send floor price if the setting is available. - var floorPriceMap = getSettings('floorPriceMap'); - console.log('floor price map: ', floorPriceMap); - console.log('size: ' + sizes[0]); + var floorPriceMap = bid.params.floorPriceMap; + utils.logInfo('floor price map: ', floorPriceMap); + utils.logInfo('size: ' + sizes[0]); if (floorPriceMap) { + // are we sure that we should not check for other sizes ? var adUnitSize = sizes[0].join('x'); if (adUnitSize in floorPriceMap) { options.push('a' + (i + 1) + 'p=' + floorPriceMap[adUnitSize]); @@ -71,15 +89,19 @@ var C1XAdapter = function C1XAdapter() { } options.push('a' + (i + 1) + 's=[' + sizeStr + ']'); } + + // no need to call server if there are no bids to request + if (options.length == 1) { + utils.logError('c1x: error - no site id supplied for any bid!'); + return; + } + options.push('rnd=' + new Date().getTime()); options.push('cbmn=_inuxuAdzebraResponse'); // cache busting - var c1xEndpoint = ENDPOINT; - if (getSettings('endpoint')) { - c1xEndpoint = getSettings('endpoint'); - } - if (getSettings('dspid')) { - options.push('dspid=' + getSettings('dspid')); + + if (dspId) { + options.push('dspid=' + dspId); } var url = c1xEndpoint + '?' + options.join('&'); window._inuxuAdzebraResponse = function(response) { From 18d704b21e91b47e6dd8ee9becf50d9207ff95ae Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Mon, 4 Sep 2017 14:56:36 +0530 Subject: [PATCH 5/6] added a c1x.html --- integrationExamples/gpt/c1x.html | 101 +++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 integrationExamples/gpt/c1x.html diff --git a/integrationExamples/gpt/c1x.html b/integrationExamples/gpt/c1x.html new file mode 100644 index 00000000000..21c54591a43 --- /dev/null +++ b/integrationExamples/gpt/c1x.html @@ -0,0 +1,101 @@ + + + + + + + + +

Prebid.js S2S Example

+ +
Div-1
+
+ +
+ + From 55b2dce4babe5451556e0783e84d9a606f8750ae Mon Sep 17 00:00:00 2001 From: Harshad Mane Date: Wed, 6 Sep 2017 10:45:46 +0530 Subject: [PATCH 6/6] only one pixel should be executed --- src/adapters/c1x.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/adapters/c1x.js b/src/adapters/c1x.js index a9f5a9fd0fa..22594b0be33 100644 --- a/src/adapters/c1x.js +++ b/src/adapters/c1x.js @@ -42,6 +42,7 @@ var C1XAdapter = function C1XAdapter() { options = ['adunits=' + bids.length], siteId = null, dspId = null, + pixelId = null, c1xEndpoint = ENDPOINT; for (var i = 0; i < bids.length; i++) { @@ -63,8 +64,10 @@ var C1XAdapter = function C1XAdapter() { dspId = bid.params.dspid; } - if(bid.params.pixelId){ - injectAudiencePixel(bid.params.pixelId); + // only one pixel should be executed + if(pixelId == null && bid.params.pixelId){ + pixelId = bid.params.pixelId; + injectAudiencePixel(pixelId); } // use default endpoint if not provided dynamically