From 2cc71fb949459478e12730e6e41b6ce265a078ee Mon Sep 17 00:00:00 2001 From: varashellov Date: Tue, 1 Aug 2017 09:38:25 -0700 Subject: [PATCH 01/56] Add PlatformioBidAdapter --- modules/platformioBidAdapter.js | 55 +++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 modules/platformioBidAdapter.js diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js new file mode 100644 index 00000000000..6a4e9a65756 --- /dev/null +++ b/modules/platformioBidAdapter.js @@ -0,0 +1,55 @@ +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 PlatformIOAdapter = function PlatformIOAdapter() { + function _callBids(params) { + var bidURL, bids = params.bids || [], requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; + + for (var i = 0; i < bids.length; i++) { + var requestParams = {}, bid = bids[i]; + + requestParams.pub_id = bid.params.pubId; + requestParams.placement_id = bid.params.placementId; + requestParams.site_id = bid.params.siteId; + + var parseSized = utils.parseSizesInput(bid.sizes), arrSize = parseSized[0].split('x'); + + requestParams.width = arrSize[0]; + requestParams.height = arrSize[1]; + requestParams.callback = 'pbjs._doPlatformIOCallback'; + requestParams.callback_uid = bid.bidId; + bidURL = requestURL + utils.parseQueryStringParameters(requestParams); + + utils.logMessage('PlatformIO.prebid, Bid ID: ' + bid.bidId + ', Pub ID: ' + bid.params.pubId); + adloader.loadScript(bidURL); + } + } + + pbjs._doPlatformIOCallback = function (response) { + var bidObject, bidRequest, callbackID; + callbackID = response.callback_uid; + bidRequest = utils.getBidRequest(callbackID); + if (response.cpm > 0) { + bidObject = bidfactory.createBid(CONSTANTS.STATUS.GOOD, bidRequest); + bidObject.bidderCode = 'platformio'; + bidObject.cpm = response.cpm; + bidObject.ad = response.tag; + bidObject.width = response.width; + bidObject.height = response.height; + } else { + bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); + bidObject.bidderCode = 'platformio'; + utils.logMessage('No Bid response from Admachine request: ' + callbackID); + } + bidmanager.addBidResponse(bidRequest.placementCode, bidObject); + }; + + return { + callBids: _callBids + }; +}; + +module.exports = PlatformIOAdapter; From 6801ca138fbdd0187cff957cfcb345e41c985744 Mon Sep 17 00:00:00 2001 From: varashellov Date: Wed, 2 Aug 2017 09:05:18 -0700 Subject: [PATCH 02/56] Update platformioBidAdapter.js --- modules/platformioBidAdapter.js | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js index 6a4e9a65756..2c157d4842b 100644 --- a/modules/platformioBidAdapter.js +++ b/modules/platformioBidAdapter.js @@ -1,21 +1,26 @@ -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 bidfactory = require('src/bidfactory.js'); +var bidmanager = require('src/bidmanager.js'); +var adloader = require('src/adloader.js'); +var utils = require('src/utils.js'); +var CONSTANTS = require('src/constants.json'); +var adaptermanager = require('src/adaptermanager'); var PlatformIOAdapter = function PlatformIOAdapter() { function _callBids(params) { - var bidURL, bids = params.bids || [], requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; + var bidURL; + var bids = params.bids || []; + var requestURL = window.location.protocol + '//adx1js.s3.amazonaws.com/pb_ortb.js?cb=' + new Date().getTime() + '&ver=1&'; for (var i = 0; i < bids.length; i++) { - var requestParams = {}, bid = bids[i]; + var requestParams = {}; + var bid = bids[i]; requestParams.pub_id = bid.params.pubId; requestParams.placement_id = bid.params.placementId; requestParams.site_id = bid.params.siteId; - var parseSized = utils.parseSizesInput(bid.sizes), arrSize = parseSized[0].split('x'); + var parseSized = utils.parseSizesInput(bid.sizes); + var arrSize = parseSized[0].split('x'); requestParams.width = arrSize[0]; requestParams.height = arrSize[1]; @@ -29,7 +34,9 @@ var PlatformIOAdapter = function PlatformIOAdapter() { } pbjs._doPlatformIOCallback = function (response) { - var bidObject, bidRequest, callbackID; + var bidObject; + var bidRequest; + var callbackID; callbackID = response.callback_uid; bidRequest = utils.getBidRequest(callbackID); if (response.cpm > 0) { @@ -42,7 +49,7 @@ var PlatformIOAdapter = function PlatformIOAdapter() { } else { bidObject = bidfactory.createBid(CONSTANTS.STATUS.NO_BID, bidRequest); bidObject.bidderCode = 'platformio'; - utils.logMessage('No Bid response from Admachine request: ' + callbackID); + utils.logMessage('No Bid response from Platformio request: ' + callbackID); } bidmanager.addBidResponse(bidRequest.placementCode, bidObject); }; @@ -51,5 +58,6 @@ var PlatformIOAdapter = function PlatformIOAdapter() { callBids: _callBids }; }; +adaptermanager.registerBidAdapter(new PlatformIOAdapter(), 'platformio'); module.exports = PlatformIOAdapter; From 9bdcd7e9d1164ef5b5b3760bf16c2b22b29e424c Mon Sep 17 00:00:00 2001 From: varashellov Date: Wed, 2 Aug 2017 09:08:49 -0700 Subject: [PATCH 03/56] Add files via upload --- .../spec/modules/platformioBidAdapter_spec.js | 157 ++++++++++++++++++ 1 file changed, 157 insertions(+) create mode 100644 test/spec/modules/platformioBidAdapter_spec.js diff --git a/test/spec/modules/platformioBidAdapter_spec.js b/test/spec/modules/platformioBidAdapter_spec.js new file mode 100644 index 00000000000..76fa0cfea5a --- /dev/null +++ b/test/spec/modules/platformioBidAdapter_spec.js @@ -0,0 +1,157 @@ +describe('platformio adapter tests', function () { + var expect = require('chai').expect; + var urlParse = require('url-parse'); + var querystringify = require('querystringify'); + var adapter = require('modules/platformioBidAdapter'); + 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: 'bid1111', + bidder: 'platformio', + params: { pubId: '37054', siteId: '123', placementId: '1234' } + }] + }; + + 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_id').and.to.equal('37054'); + expect(parsedBidUrlQueryString).to.have.property('site_id').and.to.equal('123'); + expect(parsedBidUrlQueryString).to.have.property('placement_id').and.to.equal('1234'); + 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: 'bid1111', + bidder: 'platformio', + params: { pubId: '37054', siteId: '123', placementId: '1234' } + }] + }; + + var response = { + cpm: 1, + width: 300, + height: 250, + callback_uid: 'bid1111', + tag: ' - - - - - - - - - - -

Prebid.js Test

-
Div-1
-
- -
- + + + + + + + + + + + + + + + +

Prebid.js Test

+

Banner

+
+ +
+

Native

+ +
+ +
+ \ No newline at end of file From 6e4a6780a9f2c7b468a8a91001e50b5186b27b18 Mon Sep 17 00:00:00 2001 From: varashellov Date: Wed, 28 Mar 2018 19:49:56 +0300 Subject: [PATCH 49/56] Add files via upload --- integrationExamples/gpt/hello_world.html | 46 ++++-------------------- 1 file changed, 7 insertions(+), 39 deletions(-) diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html index d08d56cf084..a5949b87c56 100644 --- a/integrationExamples/gpt/hello_world.html +++ b/integrationExamples/gpt/hello_world.html @@ -10,46 +10,22 @@ -

Native

- -
- -
\ No newline at end of file From 795381b0fcc7c06838c1d256adefb5e5965b85ab Mon Sep 17 00:00:00 2001 From: varashellov Date: Thu, 29 Mar 2018 02:15:32 -0700 Subject: [PATCH 50/56] Delete hello_world.html --- integrationExamples/gpt/hello_world.html | 98 ------------------------ 1 file changed, 98 deletions(-) delete mode 100644 integrationExamples/gpt/hello_world.html diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html deleted file mode 100644 index a5949b87c56..00000000000 --- a/integrationExamples/gpt/hello_world.html +++ /dev/null @@ -1,98 +0,0 @@ - - - - - - - - - - - - - - - -

Prebid.js Test

-
Div-1
-
- -
- - \ No newline at end of file From 8eecd2da6f8d53ed518309577ab1fe0f3925f151 Mon Sep 17 00:00:00 2001 From: varashellov Date: Thu, 29 Mar 2018 17:38:10 +0300 Subject: [PATCH 51/56] Add files via upload --- integrationExamples/gpt/hello_world.html | 98 ++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 integrationExamples/gpt/hello_world.html diff --git a/integrationExamples/gpt/hello_world.html b/integrationExamples/gpt/hello_world.html new file mode 100644 index 00000000000..a5949b87c56 --- /dev/null +++ b/integrationExamples/gpt/hello_world.html @@ -0,0 +1,98 @@ + + + + + + + + + + + + + + + +

Prebid.js Test

+
Div-1
+
+ +
+ + \ No newline at end of file From bc1cabc4fbd8133f236e495d41c916ea98ec844a Mon Sep 17 00:00:00 2001 From: varashellov Date: Sun, 29 Apr 2018 19:35:48 +0300 Subject: [PATCH 52/56] Add files via upload --- modules/platformioBidAdapter.js | 70 ++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 15 deletions(-) diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js index abb0cf50722..c1595b44daa 100644 --- a/modules/platformioBidAdapter.js +++ b/modules/platformioBidAdapter.js @@ -1,3 +1,4 @@ + import * as utils from 'src/utils'; import { registerBidder } from 'src/adapters/bidderFactory'; import { BANNER, NATIVE, VIDEO } from 'src/mediaTypes'; @@ -10,7 +11,6 @@ const NATIVE_DEFAULTS = { IMG_MIN: 150, ICON_MIN: 50, }; - const DEFAULT_MIMES = ['video/mp4', 'video/webm', 'application/x-shockwave-flash', 'application/javascript']; const VIDEO_TARGETING = ['mimes', 'skippable', 'playback_method', 'protocols', 'api']; const DEFAULT_PROTOCOLS = [2, 3, 5, 6]; @@ -22,7 +22,7 @@ export const spec = { supportedMediaTypes: [BANNER, NATIVE, VIDEO], isBidRequestValid: bid => ( - !!(bid && bid.params && bid.params.pubId && bid.params.siteId) + !!(bid && bid.params && bid.params.pubId && bid.params.placementId) ), buildRequests: bidRequests => { const request = { @@ -30,7 +30,8 @@ export const spec = { at: 2, imp: bidRequests.map(slot => impression(slot)), site: site(bidRequests), - device: device(), + app: app(bidRequests), + device: device(bidRequests), }; return { method: 'POST', @@ -101,6 +102,7 @@ function bidResponseAvailable(bidRequest, bidResponse) { function impression(slot) { return { id: slot.bidId, + secure: window.location.protocol === 'https:' ? 1 : 0, 'banner': banner(slot), 'native': nativeImpression(slot), 'video': videoImpression(slot), @@ -110,10 +112,16 @@ function impression(slot) { } function getSizes(slot) { - const size = slot.params.size.toUpperCase().split('X'); + if (slot.params.size) { + const size = slot.params.size.toUpperCase().split('X'); + return { + width: parseInt(size[0]), + height: parseInt(size[1]), + }; + } return { - width: parseInt(size[0]), - height: parseInt(size[1]), + width: 1, + height: 1, }; } @@ -207,25 +215,57 @@ function dataAsset(id, params, type, defaultLen) { function site(bidderRequest) { const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0'; const siteId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.siteId : '0'; - return { - publisher: { - id: pubId.toString(), - domain: utils.getTopWindowLocation().hostname, - }, - id: siteId.toString(), - ref: utils.getTopWindowReferrer(), - page: utils.getTopWindowLocation().href, + const appParams = bidderRequest[0].params.app; + if (!appParams) { + return { + publisher: { + id: pubId.toString(), + domain: utils.getTopWindowLocation().hostname, + }, + id: siteId.toString(), + ref: utils.getTopWindowReferrer(), + page: utils.getTopWindowLocation().href, + } } + return null; } -function device() { +function app(bidderRequest) { + const pubId = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.pubId : '0'; + const appParams = bidderRequest[0].params.app; + if (appParams) { + return { + publisher: { + id: pubId.toString(), + }, + id: appParams.id, + name: appParams.name, + bundle: appParams.bundle, + storeurl: appParams.storeUrl, + domain: appParams.domain, + } + } + return null; +} + +function device(bidderRequest) { + const lat = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.latitude : ''; + const lon = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.longitude : ''; + const ifa = bidderRequest && bidderRequest.length > 0 ? bidderRequest[0].params.ifa : ''; return { + dnt: utils.getDNT() ? 1 : 0, ua: navigator.userAgent, language: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage), w: (window.screen.width || window.innerWidth), h: (window.screen.height || window.innerHeigh), + geo: { + lat: lat, + lon: lon, + }, + ifa: ifa, }; } + function parse(rawResponse) { try { if (rawResponse) { From 84e816398cb516e8324f6ba6bd0a5cb1ff1c5a87 Mon Sep 17 00:00:00 2001 From: varashellov Date: Sun, 29 Apr 2018 19:36:36 +0300 Subject: [PATCH 53/56] Add files via upload --- .../spec/modules/platformioBidAdapter_spec.js | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/test/spec/modules/platformioBidAdapter_spec.js b/test/spec/modules/platformioBidAdapter_spec.js index c9954d4531a..fc8ba5bf45e 100644 --- a/test/spec/modules/platformioBidAdapter_spec.js +++ b/test/spec/modules/platformioBidAdapter_spec.js @@ -13,7 +13,10 @@ describe('Platform.io Adapter Tests', () => { siteId: '26047', placementId: '123', size: '300x250', - bidFloor: '0.001' + bidFloor: '0.001', + ifa: 'IFA', + latitude: '40.712775', + longitude: '-74.005973' } }, { placementCode: '/DfpAccount2/slot2', @@ -24,7 +27,7 @@ describe('Platform.io Adapter Tests', () => { siteId: '26047', placementId: '1234', size: '728x90', - bidFloor: '0.000001' + bidFloor: '0.000001', } }]; const nativeSlotConfig = [{ @@ -58,6 +61,21 @@ describe('Platform.io Adapter Tests', () => { size: '640x480' } }]; + const appSlotConfig = [{ + placementCode: '/DfpAccount1/slot5', + bidId: 'bid12345', + params: { + pubId: '29521', + placementId: '1234', + app: { + id: '1111', + name: 'app name', + bundle: 'io.platform.apps', + storeUrl: 'http://platform.io/apps', + domain: 'platform.io' + } + } + }]; it('Verify build request', () => { const request = spec.buildRequests(slotConfigs); @@ -74,6 +92,9 @@ describe('Platform.io Adapter Tests', () => { // device object expect(ortbRequest.device).to.not.equal(null); expect(ortbRequest.device.ua).to.equal(navigator.userAgent); + expect(ortbRequest.device.ifa).to.equal('IFA'); + expect(ortbRequest.device.geo.lat).to.equal('40.712775'); + expect(ortbRequest.device.geo.lon).to.equal('-74.005973'); // slot 1 expect(ortbRequest.imp[0].tagid).to.equal('123'); expect(ortbRequest.imp[0].banner).to.not.equal(null); @@ -278,4 +299,18 @@ describe('Platform.io Adapter Tests', () => { expect(spec.isBidRequestValid(nativeSlotConfig[0])).to.equal(true); expect(spec.isBidRequestValid(videoSlotConfig[0])).to.equal(true); }); + + it('Verify app requests', () => { + const request = spec.buildRequests(appSlotConfig); + const ortbRequest = JSON.parse(request.data); + expect(ortbRequest.site).to.equal(null); + expect(ortbRequest.app).to.not.be.null; + expect(ortbRequest.app.publisher).to.not.equal(null); + expect(ortbRequest.app.publisher.id).to.equal('29521'); + expect(ortbRequest.app.id).to.equal('1111'); + expect(ortbRequest.app.name).to.equal('app name'); + expect(ortbRequest.app.bundle).to.equal('io.platform.apps'); + expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps'); + expect(ortbRequest.app.domain).to.equal('platform.io'); + }); }); From d1327cb031ad823df15c6d6ea89b203dad15670c Mon Sep 17 00:00:00 2001 From: varashellov Date: Thu, 3 May 2018 15:08:29 +0300 Subject: [PATCH 54/56] Add files via upload --- modules/platformioBidAdapter.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/platformioBidAdapter.md b/modules/platformioBidAdapter.md index 8233d5cd545..ff6335d1d70 100644 --- a/modules/platformioBidAdapter.md +++ b/modules/platformioBidAdapter.md @@ -38,6 +38,10 @@ Please use ```platformio``` as the bidder code. pubId: '29521', siteId: '26048', placementId: '123', + bidFloor: '0.001', // optional + ifa: 'XXX-XXX', // optional + latitude: '40.712775', // optional + longitude: '-74.005973', // optional } }] }, @@ -76,7 +80,7 @@ Please use ```platformio``` as the bidder code. size: '640X480', placementId: '123', video: { - skippable: true, + skipppable: true, } } }] From 119037677dd51d19a80cfc7a1e65e67cf73f6377 Mon Sep 17 00:00:00 2001 From: varashellov Date: Thu, 28 Jun 2018 17:26:30 +0300 Subject: [PATCH 55/56] Add files via upload --- modules/platformioBidAdapter.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/modules/platformioBidAdapter.js b/modules/platformioBidAdapter.js index b33aeab8f88..79fcd2120b5 100644 --- a/modules/platformioBidAdapter.js +++ b/modules/platformioBidAdapter.js @@ -23,7 +23,7 @@ export const spec = { isBidRequestValid: bid => ( !!(bid && bid.params && bid.params.pubId && bid.params.placementId) ), - buildRequests: bidRequests => { + buildRequests: (bidRequests, bidderRequest) => { const request = { id: bidRequests[0].bidderRequestId, at: 2, @@ -32,6 +32,7 @@ export const spec = { app: app(bidRequests), device: device(bidRequests), }; + applyGdpr(bidderRequest, request); return { method: 'POST', url: '//piohbdisp.hb.adx1.com/', @@ -276,6 +277,13 @@ function parse(rawResponse) { return null; } +function applyGdpr(bidderRequest, ortbRequest) { + if (bidderRequest && bidderRequest.gdprConsent) { + ortbRequest.regs = { ext: { gdpr: bidderRequest.gdprConsent.gdprApplies ? 1 : 0 } }; + ortbRequest.user = { ext: { consent: bidderRequest.gdprConsent.consentString } }; + } +} + function nativeResponse(imp, bid) { if (imp['native']) { const nativeAd = parse(bid.adm); From 95fd255d87d80844cc93bba127b5fd48becba6d1 Mon Sep 17 00:00:00 2001 From: varashellov Date: Thu, 28 Jun 2018 17:27:13 +0300 Subject: [PATCH 56/56] Add files via upload --- .../spec/modules/platformioBidAdapter_spec.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/test/spec/modules/platformioBidAdapter_spec.js b/test/spec/modules/platformioBidAdapter_spec.js index fc8ba5bf45e..39ada3cc01c 100644 --- a/test/spec/modules/platformioBidAdapter_spec.js +++ b/test/spec/modules/platformioBidAdapter_spec.js @@ -313,4 +313,23 @@ describe('Platform.io Adapter Tests', () => { expect(ortbRequest.app.storeurl).to.equal('http://platform.io/apps'); expect(ortbRequest.app.domain).to.equal('platform.io'); }); + + it('Verify GDPR', () => { + const bidderRequest = { + gdprConsent: { + gdprApplies: true, + consentString: 'serialized_gpdr_data' + } + }; + const request = spec.buildRequests(slotConfigs, bidderRequest); + expect(request.url).to.equal('//piohbdisp.hb.adx1.com/'); + expect(request.method).to.equal('POST'); + const ortbRequest = JSON.parse(request.data); + expect(ortbRequest.user).to.not.equal(null); + expect(ortbRequest.user.ext).to.not.equal(null); + expect(ortbRequest.user.ext.consent).to.equal('serialized_gpdr_data'); + expect(ortbRequest.regs).to.not.equal(null); + expect(ortbRequest.regs.ext).to.not.equal(null); + expect(ortbRequest.regs.ext.gdpr).to.equal(1); + }); });