From 6101172a603322198a581d2592e09a8430e81821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BF=D1=83=D1=85=D1=82=D0=B8=D0=BD=20=D0=9A=D0=B8?= =?UTF-8?q?=D1=80=D0=B8=D0=BB=D0=BB?= Date: Thu, 15 Sep 2016 17:29:26 +0300 Subject: [PATCH 01/18] add roxot adapter --- adapters.json | 1 + src/adapters/roxot.js | 118 ++++++++++++++++++++++++++++ test/spec/adapters/roxot_spec.js | 127 +++++++++++++++++++++++++++++++ 3 files changed, 246 insertions(+) create mode 100644 src/adapters/roxot.js create mode 100644 test/spec/adapters/roxot_spec.js diff --git a/adapters.json b/adapters.json index 369bfad55af..c28707d6bbe 100644 --- a/adapters.json +++ b/adapters.json @@ -28,6 +28,7 @@ "underdogmedia", "memeglobal", "centro", + "roxot", { "appnexus": { "alias": "brealtime" diff --git a/src/adapters/roxot.js b/src/adapters/roxot.js new file mode 100644 index 00000000000..92402dfbdb4 --- /dev/null +++ b/src/adapters/roxot.js @@ -0,0 +1,118 @@ +var CONSTANTS = require('../constants.json'); +var utils = require('../utils.js'); +var events = require('../events.js'); +var bidfactory = require('../bidfactory.js'); +var bidmanager = require('../bidmanager.js'); +var adloader = require('../adloader'); + + +var RoxotAdapter = function RoxotAdapter() { + var roxotUrl = "r.rxthdr.com"; + + $$PREBID_GLOBAL$$.roxotResponseHandler = roxotResponseHandler; + $$PREBID_GLOBAL$$.roxotEvents = events; + + return { + callBids: _callBids + }; + + function _callBids(bidReqs) { + utils.logInfo('callBids roxot adapter invoking'); + + var domain = window.location.host; + var page = window.location.pathname + location.search + location.hash; + + var roxotBidReqs = { + id: utils.getUniqueIdentifierStr(), + bids: bidReqs, + site: { + domain: domain, + page: page + } + }; + + var scriptUrl = '//' + roxotUrl + '?callback=window.pbjs.roxotResponseHandler' + + '&src=' + CONSTANTS.REPO_AND_VERSION + + '&br=' + encodeURIComponent(JSON.stringify(roxotBidReqs)); + + adloader.loadScript(scriptUrl, null); + } + + function roxotResponseHandler(roxotResponseObject) { + utils.logInfo('roxotResponseHandler invoking'); + var placements = []; + + if (isResponseInvalid()) { + return fillPlacementEmptyBid(); + } + + roxotResponseObject.bids.forEach(pushRoxotBid); + + var allBidResponse = fillPlacementEmptyBid(placements); + + utils.logInfo('roxotResponse handler finish'); + + return allBidResponse; + + function isResponseInvalid() { + return !roxotResponseObject || !roxotResponseObject.bids || !Array.isArray(roxotResponseObject.bids) || roxotResponseObject.bids.length <= 0; + } + + function pushRoxotBid(roxotBid) { + var placementCode = ''; + + var bidReq = $$PREBID_GLOBAL$$ + ._bidsRequested.find(bidSet => bidSet.bidderCode === 'roxot') + .bids.find(bid => bid.bidId === roxotBid.bidId); + + if (!bidReq) { + return pushErrorBid(placementCode); + } + + bidReq.status = CONSTANTS.STATUS.GOOD; + + placementCode = bidReq.placementCode; + placements.push(placementCode); + + var cpm = roxotBid.cpm; + var responseNurl = ''; + + if (!cpm) { + return pushErrorBid(placementCode); + } + + var bid = bidfactory.createBid(1, bidReq); + + bid.creative_id = roxotBid.id; + bid.bidderCode = 'roxot'; + bid.cpm = cpm; + bid.ad = decodeURIComponent(roxotBid.adm + responseNurl); + bid.width = parseInt(roxotBid.w); + bid.height = parseInt(roxotBid.h); + + bidmanager.addBidResponse(placementCode, bid); + } + + function fillPlacementEmptyBid(places) { + $$PREBID_GLOBAL$$ + ._bidsRequested.find(bidSet => bidSet.bidderCode === 'roxot') + .bids.forEach(fillIfNotFilled); + + function fillIfNotFilled(bid) { + if (utils.contains(places, bid.placementCode)) { + return null; + } + + pushErrorBid(bid); + } + } + + function pushErrorBid(bidRequest) { + var bid = bidfactory.createBid(2, bidRequest); + bid.bidderCode = 'roxot'; + bidmanager.addBidResponse(bidRequest.placementCode, bid); + } + } +}; + +module.exports = RoxotAdapter; \ No newline at end of file diff --git a/test/spec/adapters/roxot_spec.js b/test/spec/adapters/roxot_spec.js new file mode 100644 index 00000000000..39e296a72ee --- /dev/null +++ b/test/spec/adapters/roxot_spec.js @@ -0,0 +1,127 @@ +describe('Roxot adapter tests', function(){ + const expect = require('chai').expect; + const adapter = require('src/adapters/roxot'); + const bidmanager = require('src/bidmanager'); + + describe('roxotResponseHandler', function () { + + it('should exist and be a function', function () { + expect(pbjs.roxotResponseHandler).to.exist.and.to.be.a('function'); + expect(pbjs.roxotEvents).to.exist.and.to.be.a('object'); + }); + + it('should add empty bid responses if no bids returned', function () { + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var bidderRequest = { + bidderCode: 'roxot', + bids: [ + { + bidId: 'id1', + bidder: 'roxot', + sizes: [[320, 50]], + placementCode: 'div-gpt-ad-12345-1' + }, + { + bidId: 'id2', + bidder: 'roxot', + sizes: [[320, 50]], + placementCode: 'div-gpt-ad-12345-2' + }, + ] + }; + + + // no bids returned in the response. + var response = { + "id": "123", + "bids": [] + }; + + pbjs._bidsRequested.push(bidderRequest); + + // adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.roxotResponseHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + var bidPlacementCode2 = stubAddBidResponse.getCall(1).args[0]; + var bidObject2 = stubAddBidResponse.getCall(1).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-12345-1'); + expect(bidObject1.getStatusCode()).to.equal(2); + expect(bidObject1.bidderCode).to.equal('roxot'); + + expect(bidPlacementCode2).to.equal('div-gpt-ad-12345-2'); + expect(bidObject2.getStatusCode()).to.equal(2); + expect(bidObject2.bidderCode).to.equal('roxot'); + + stubAddBidResponse.restore(); + }); + + it('should add a bid response for bids returned and empty bid responses for the rest', () => { + + var stubAddBidResponse = sinon.stub(bidmanager, 'addBidResponse'); + + var bidderRequest = { + bidderCode: 'roxot', + bids: [ + { + bidId: 'id1', + bidder: 'roxot', + sizes: [[320, 50]], + placementCode: 'div-gpt-ad-12345-1' + }, + { + bidId: 'id2', + bidder: 'roxot', + sizes: [[320, 50]], + placementCode: 'div-gpt-ad-12345-2' + }, + ] + }; + + // Returning a single bid in the response. + var response = { + "id": "12345", + "bids": [ + { + "bidId" : "id1", + "cpm" : 0.09, + "nurl" : "http://roxot.example.com", + "adm" : "<>", + "h" : 320, + "w" : 50 + } + ]}; + + pbjs._bidsRequested.push(bidderRequest); + + // adapter needs to be called, in order for the stub to register. + adapter(); + + pbjs.roxotResponseHandler(response); + + var bidPlacementCode1 = stubAddBidResponse.getCall(0).args[0]; + var bidObject1 = stubAddBidResponse.getCall(0).args[1]; + var bidPlacementCode2 = stubAddBidResponse.getCall(1).args[0]; + var bidObject2 = stubAddBidResponse.getCall(1).args[1]; + + expect(bidPlacementCode1).to.equal('div-gpt-ad-12345-1'); + expect(bidObject1.getStatusCode()).to.equal(1); + expect(bidObject1.bidderCode).to.equal('roxot'); + expect(bidObject1.cpm).to.equal(0.09); + expect(bidObject1.height).to.equal(320); + expect(bidObject1.width).to.equal(50); + expect(bidObject1.ad).to.equal('<>'); + + expect(bidPlacementCode2).to.equal('div-gpt-ad-12345-2'); + expect(bidObject2.getStatusCode()).to.equal(2); + expect(bidObject2.bidderCode).to.equal('roxot'); + + stubAddBidResponse.restore(); + }); + }); +}); \ No newline at end of file From 992c981630d24945893d2dd99e6a9b7b9f4da5e0 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Fri, 30 Sep 2016 15:18:47 +0300 Subject: [PATCH 02/18] update roxot analytics system --- src/adapters/analytics/roxot.js | 23 +++++++++++++++++++++++ src/adapters/roxot.js | 1 - 2 files changed, 23 insertions(+), 1 deletion(-) create mode 100644 src/adapters/analytics/roxot.js diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js new file mode 100644 index 00000000000..8f74ea80fec --- /dev/null +++ b/src/adapters/analytics/roxot.js @@ -0,0 +1,23 @@ +import { ajax } from 'src/ajax'; + +/** + * example2.js - analytics adapter for Example2 Analytics Endpoint example + */ + +import adapter from 'AnalyticsAdapter'; +const utils = require('../../utils'); + +const url = '//d.rxthdr.com/analytics'; +const analyticsType = 'endpoint'; + +export default utils.extend(adapter( + { + url, + analyticsType + } + ), + { + track({ eventType, args }) { + ajax(url, (result) => utils.logInfo('Event ' + eventType + ' sent to roxot analytics with result ' + result), JSON.stringify({ eventType, args })); + } + }); diff --git a/src/adapters/roxot.js b/src/adapters/roxot.js index 92402dfbdb4..45942f8472b 100644 --- a/src/adapters/roxot.js +++ b/src/adapters/roxot.js @@ -10,7 +10,6 @@ var RoxotAdapter = function RoxotAdapter() { var roxotUrl = "r.rxthdr.com"; $$PREBID_GLOBAL$$.roxotResponseHandler = roxotResponseHandler; - $$PREBID_GLOBAL$$.roxotEvents = events; return { callBids: _callBids From d098b413be5809a9b2753d070d4d8cf0f7ebec57 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Fri, 30 Sep 2016 15:34:37 +0300 Subject: [PATCH 03/18] remove unused test --- test/spec/adapters/roxot_spec.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/spec/adapters/roxot_spec.js b/test/spec/adapters/roxot_spec.js index 39e296a72ee..468d3f22ce1 100644 --- a/test/spec/adapters/roxot_spec.js +++ b/test/spec/adapters/roxot_spec.js @@ -7,7 +7,6 @@ describe('Roxot adapter tests', function(){ it('should exist and be a function', function () { expect(pbjs.roxotResponseHandler).to.exist.and.to.be.a('function'); - expect(pbjs.roxotEvents).to.exist.and.to.be.a('object'); }); it('should add empty bid responses if no bids returned', function () { From c23029068fe174a4158561143d6bfc0d28bc1dc3 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Fri, 30 Sep 2016 16:05:04 +0300 Subject: [PATCH 04/18] remove unused import --- src/adapters/roxot.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/adapters/roxot.js b/src/adapters/roxot.js index 45942f8472b..f0878415a40 100644 --- a/src/adapters/roxot.js +++ b/src/adapters/roxot.js @@ -1,6 +1,5 @@ var CONSTANTS = require('../constants.json'); var utils = require('../utils.js'); -var events = require('../events.js'); var bidfactory = require('../bidfactory.js'); var bidmanager = require('../bidmanager.js'); var adloader = require('../adloader'); From 3f34fac30aadc3abcd5e8af0bc2abc2d330a093e Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Wed, 12 Oct 2016 18:58:28 +0300 Subject: [PATCH 05/18] update code after review --- src/adapters/analytics/roxot.js | 6 +----- src/adapters/roxot.js | 7 ++----- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 8f74ea80fec..e00ef05c20f 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -1,10 +1,6 @@ import { ajax } from 'src/ajax'; - -/** - * example2.js - analytics adapter for Example2 Analytics Endpoint example - */ - import adapter from 'AnalyticsAdapter'; + const utils = require('../../utils'); const url = '//d.rxthdr.com/analytics'; diff --git a/src/adapters/roxot.js b/src/adapters/roxot.js index f0878415a40..171fe49e5ec 100644 --- a/src/adapters/roxot.js +++ b/src/adapters/roxot.js @@ -4,7 +4,6 @@ var bidfactory = require('../bidfactory.js'); var bidmanager = require('../bidmanager.js'); var adloader = require('../adloader'); - var RoxotAdapter = function RoxotAdapter() { var roxotUrl = "r.rxthdr.com"; @@ -29,11 +28,11 @@ var RoxotAdapter = function RoxotAdapter() { } }; - var scriptUrl = '//' + roxotUrl + '?callback=window.pbjs.roxotResponseHandler' + + var scriptUrl = '//' + roxotUrl + '?callback=$$PREBID_GLOBAL$$.roxotResponseHandler' + '&src=' + CONSTANTS.REPO_AND_VERSION + '&br=' + encodeURIComponent(JSON.stringify(roxotBidReqs)); - adloader.loadScript(scriptUrl, null); + adloader.loadScript(scriptUrl); } function roxotResponseHandler(roxotResponseObject) { @@ -45,9 +44,7 @@ var RoxotAdapter = function RoxotAdapter() { } roxotResponseObject.bids.forEach(pushRoxotBid); - var allBidResponse = fillPlacementEmptyBid(placements); - utils.logInfo('roxotResponse handler finish'); return allBidResponse; From 699c6fc0f1353172703be97621ee4d26bff0cb9d Mon Sep 17 00:00:00 2001 From: Evgeny Borodko Date: Wed, 1 Mar 2017 15:50:51 +0300 Subject: [PATCH 06/18] add analytic adapter - roxot prebid analytic --- package.json | 2 +- src/adapters/analytics/AnalyticsAdapter.js | 2 ++ .../analytics/roxot_prebid_analytic.js | 28 +++++++++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/adapters/analytics/roxot_prebid_analytic.js diff --git a/package.json b/package.json index f3200d9c541..ec548fff8de 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prebid" ], "globalVarName": "pbjs", - "analytics": [], + "analytics": ["roxot_prebid_analytic"], "author": "the prebid.js contributors", "license": "Apache-2.0", "devDependencies": { diff --git a/src/adapters/analytics/AnalyticsAdapter.js b/src/adapters/analytics/AnalyticsAdapter.js index 62f7143b947..c5b5d5cbae8 100644 --- a/src/adapters/analytics/AnalyticsAdapter.js +++ b/src/adapters/analytics/AnalyticsAdapter.js @@ -6,6 +6,7 @@ const events = require('src/events'); const utils = require('../../utils'); const AUCTION_INIT = CONSTANTS.EVENTS.AUCTION_INIT; +const AUCTION_END = CONSTANTS.EVENTS.AUCTION_END; const BID_REQUESTED = CONSTANTS.EVENTS.BID_REQUESTED; const BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT; const BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; @@ -98,6 +99,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } args.config = config.options; // enableAnaltyics configuration object this.enqueue({ eventType: AUCTION_INIT, args }); }); + events.on(AUCTION_END, args => this.enqueue({ eventType: AUCTION_END, args })); // finally set this function to return log message, prevents multiple adapter listeners this.enableAnalytics = function _enable() { diff --git a/src/adapters/analytics/roxot_prebid_analytic.js b/src/adapters/analytics/roxot_prebid_analytic.js new file mode 100644 index 00000000000..7a890d4e28b --- /dev/null +++ b/src/adapters/analytics/roxot_prebid_analytic.js @@ -0,0 +1,28 @@ +import { ajax } from 'src/ajax'; +import adapter from 'AnalyticsAdapter'; +import CONSTANTS from 'src/constants.json'; + +const utils = require('../../utils'); + +const url = '//d.prebid-analytic.com/analytics'; +const analyticsType = 'endpoint'; + +var events = []; +var auctionEnd = CONSTANTS.EVENTS.AUCTION_END; + +export default utils.extend(adapter( + { + url, + analyticsType + } + ), + { + track({ eventType, args }) { + if (eventType === auctionEnd) { + ajax(url, (result) => utils.logInfo('Event ' + eventType + ' sent to roxot prebid analityc with result ' + result), JSON.stringify(events)); + events = []; + } else { + events.push({ eventType, args }); + } + } + }); From e4449de22d92495dff7c97dacbbbb9181fef4ab9 Mon Sep 17 00:00:00 2001 From: Evgeny Borodko Date: Wed, 1 Mar 2017 17:46:22 +0300 Subject: [PATCH 07/18] Update roxot prebid analytic --- .../analytics/roxot_prebid_analytic.js | 73 +++++++++++++++---- 1 file changed, 60 insertions(+), 13 deletions(-) diff --git a/src/adapters/analytics/roxot_prebid_analytic.js b/src/adapters/analytics/roxot_prebid_analytic.js index 7a890d4e28b..4579859ff8c 100644 --- a/src/adapters/analytics/roxot_prebid_analytic.js +++ b/src/adapters/analytics/roxot_prebid_analytic.js @@ -1,4 +1,4 @@ -import { ajax } from 'src/ajax'; +import {ajax} from 'src/ajax'; import adapter from 'AnalyticsAdapter'; import CONSTANTS from 'src/constants.json'; @@ -7,22 +7,69 @@ const utils = require('../../utils'); const url = '//d.prebid-analytic.com/analytics'; const analyticsType = 'endpoint'; -var events = []; -var auctionEnd = CONSTANTS.EVENTS.AUCTION_END; +let auctionInitConst = CONSTANTS.EVENTS.AUCTION_INIT; +let auctionEndConst = CONSTANTS.EVENTS.AUCTION_END; +let bidWonConst = CONSTANTS.EVENTS.BID_WON; -export default utils.extend(adapter( - { - url, - analyticsType +let initOptions = {publisherIds: []}; +let bidWon = {options: {}, events: []}; +let eventStack = {options: {}, events: []}; + +function checkOptions() { + if (typeof initOptions.publisherIds === 'undefined') { + return false; } - ), + + return initOptions.publisherIds.length > 0; +} + +function buildBidWon(eventType, args) { + bidWon.options = initOptions; + bidWon.events.push({args: args, eventType: eventType}); +} + +function buildEventStack() { + eventStack.options = initOptions; +} + +function send(eventType, data, sendDataType) { + ajax( + url, + (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analityc with result' + result), + JSON.stringify(data) + ); +} + +function pushEvent(eventType, args) { + eventStack.events.push({eventType, args}); +} + +function flushEvents() { + eventStack.events = []; +} + +export default utils.extend(adapter({url, analyticsType}), { - track({ eventType, args }) { - if (eventType === auctionEnd) { - ajax(url, (result) => utils.logInfo('Event ' + eventType + ' sent to roxot prebid analityc with result ' + result), JSON.stringify(events)); - events = []; + track({eventType, args}) { + if (eventType === auctionInitConst) { + initOptions = args.config; + } + + if (!checkOptions()) { + return; + } + + if (eventType === bidWonConst) { + buildBidWon(eventType, args); + send(eventType, bidWon, 'bidWon'); + } + + if (eventType === auctionEndConst) { + buildEventStack(eventType); + send(eventType, eventStack, 'eventStack'); + flushEvents(); } else { - events.push({ eventType, args }); + pushEvent(eventType, args); } } }); From cf3c4806d4b6c24c43a4f203a01ffd556403be78 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Fri, 3 Mar 2017 20:43:27 +0300 Subject: [PATCH 08/18] update --- src/adapters/analytics/AnalyticsAdapter.js | 2 + src/adapters/analytics/roxot.js | 80 ++++++++++++++++--- .../analytics/roxot_prebid_analytic.js | 75 ----------------- test/spec/roxot_analytic_spec.js | 24 ++++++ 4 files changed, 97 insertions(+), 84 deletions(-) delete mode 100644 src/adapters/analytics/roxot_prebid_analytic.js create mode 100644 test/spec/roxot_analytic_spec.js diff --git a/src/adapters/analytics/AnalyticsAdapter.js b/src/adapters/analytics/AnalyticsAdapter.js index c5b5d5cbae8..7367c979703 100644 --- a/src/adapters/analytics/AnalyticsAdapter.js +++ b/src/adapters/analytics/AnalyticsAdapter.js @@ -12,6 +12,7 @@ const BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT; const BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; const BID_WON = CONSTANTS.EVENTS.BID_WON; const BID_ADJUSTMENT = CONSTANTS.EVENTS.BID_ADJUSTMENT; +const REQUEST_BIDS = CONSTANTS.EVENTS.REQUEST_BIDS; const LIBRARY = 'library'; const ENDPOINT = 'endpoint'; @@ -90,6 +91,7 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } //Next register event listeners to send data immediately //bidRequests + events.on(REQUEST_BIDS, args => this.enqueue({ eventType: BID_REQUESTED, args })); events.on(BID_REQUESTED, args => this.enqueue({ eventType: BID_REQUESTED, args })); events.on(BID_RESPONSE, args => this.enqueue({ eventType: BID_RESPONSE, args })); events.on(BID_TIMEOUT, args => this.enqueue({ eventType: BID_TIMEOUT, args })); diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index e00ef05c20f..5410adf74fa 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -1,19 +1,81 @@ -import { ajax } from 'src/ajax'; +import {ajax} from 'src/ajax'; import adapter from 'AnalyticsAdapter'; +import CONSTANTS from 'src/constants.json'; const utils = require('../../utils'); -const url = '//d.rxthdr.com/analytics'; +const url = '//pa.rxthdr.com/'; const analyticsType = 'endpoint'; -export default utils.extend(adapter( - { - url, - analyticsType +let auctionInitConst = CONSTANTS.EVENTS.AUCTION_INIT; +let auctionEndConst = CONSTANTS.EVENTS.AUCTION_END; +let bidWonConst = CONSTANTS.EVENTS.BID_WON; + +let initOptions = {publisherIds: []}; +let bidWon = {options: {}, events: []}; +let eventStack = {options: {}, events: []}; + +let auctionStatus = 'not_started'; + +function checkOptions() { + if (typeof initOptions.publisherIds === 'undefined') { + return false; } - ), + + return initOptions.publisherIds.length > 0; +} + +function buildBidWon(eventType, args) { + bidWon.options = initOptions; + bidWon.events = {args: args, eventType: eventType}; +} + +function buildEventStack() { + eventStack.options = initOptions; +} + +function send(eventType, data, sendDataType) { + ajax( + url, + (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analityc with result' + result), + JSON.stringify(data) + ); +} + +function pushEvent(eventType, args) { + eventStack.events.push({eventType, args}); +} + +function flushEvents() { + eventStack.events = []; +} + +export default utils.extend(adapter({url, analyticsType}), { - track({ eventType, args }) { - ajax(url, (result) => utils.logInfo('Event ' + eventType + ' sent to roxot analytics with result ' + result), JSON.stringify({ eventType, args })); + track({eventType, args}) { + if (eventType === auctionInitConst) { + auctionStatus = 'started'; + initOptions = args.config; + flushEvents(); + } + + if (!checkOptions()) { + return; + } + + if ((eventType === bidWonConst) && auctionStatus === 'not_started') { + buildBidWon(eventType, args); + send(eventType, bidWon, 'bidWon'); + return; + } + + if (eventType === auctionEndConst) { + buildEventStack(eventType); + send(eventType, eventStack, 'eventStack'); + flushEvents(); + auctionStatus = 'not_started'; + } else { + pushEvent(eventType, args); + } } }); diff --git a/src/adapters/analytics/roxot_prebid_analytic.js b/src/adapters/analytics/roxot_prebid_analytic.js deleted file mode 100644 index 4579859ff8c..00000000000 --- a/src/adapters/analytics/roxot_prebid_analytic.js +++ /dev/null @@ -1,75 +0,0 @@ -import {ajax} from 'src/ajax'; -import adapter from 'AnalyticsAdapter'; -import CONSTANTS from 'src/constants.json'; - -const utils = require('../../utils'); - -const url = '//d.prebid-analytic.com/analytics'; -const analyticsType = 'endpoint'; - -let auctionInitConst = CONSTANTS.EVENTS.AUCTION_INIT; -let auctionEndConst = CONSTANTS.EVENTS.AUCTION_END; -let bidWonConst = CONSTANTS.EVENTS.BID_WON; - -let initOptions = {publisherIds: []}; -let bidWon = {options: {}, events: []}; -let eventStack = {options: {}, events: []}; - -function checkOptions() { - if (typeof initOptions.publisherIds === 'undefined') { - return false; - } - - return initOptions.publisherIds.length > 0; -} - -function buildBidWon(eventType, args) { - bidWon.options = initOptions; - bidWon.events.push({args: args, eventType: eventType}); -} - -function buildEventStack() { - eventStack.options = initOptions; -} - -function send(eventType, data, sendDataType) { - ajax( - url, - (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analityc with result' + result), - JSON.stringify(data) - ); -} - -function pushEvent(eventType, args) { - eventStack.events.push({eventType, args}); -} - -function flushEvents() { - eventStack.events = []; -} - -export default utils.extend(adapter({url, analyticsType}), - { - track({eventType, args}) { - if (eventType === auctionInitConst) { - initOptions = args.config; - } - - if (!checkOptions()) { - return; - } - - if (eventType === bidWonConst) { - buildBidWon(eventType, args); - send(eventType, bidWon, 'bidWon'); - } - - if (eventType === auctionEndConst) { - buildEventStack(eventType); - send(eventType, eventStack, 'eventStack'); - flushEvents(); - } else { - pushEvent(eventType, args); - } - } - }); diff --git a/test/spec/roxot_analytic_spec.js b/test/spec/roxot_analytic_spec.js new file mode 100644 index 00000000000..c545f23fc2c --- /dev/null +++ b/test/spec/roxot_analytic_spec.js @@ -0,0 +1,24 @@ +let assert = require('assert'); +let analytic = require('../../src/adapters/analytics/roxot'); +let events = require('../../src/events'); +let constants = require('../../src/constants.json'); + +describe('Roxot Prebid Analytic', function () { + + describe('enableAnalytics', function () { + + it('should catch all events', function () { + let config = {options: { publisherIds : ['foo'] } }; + console.log(analytic); + console.log(analytic.default.enableAnalytics); + analytic.default.enableAnalytics(config); + analytic.default.track(constants.EVENTS.AUCTION_INIT, {}); + + events.emit(constants.EVENTS.AUCTION_INIT, {}); + events.emit(constants.EVENTS.BID_REQUESTED, {}); + events.emit(constants.EVENTS.BID_WON, {}); + events.emit(constants.EVENTS.AUCTION_END, {}); + events.emit(constants.EVENTS.BID_WON, {}); + }); + }); +}); From 0d9cf48f8f81332b8381da551255b8c37c64c04b Mon Sep 17 00:00:00 2001 From: kirillapuhtin Date: Sun, 5 Mar 2017 10:11:35 +0300 Subject: [PATCH 09/18] Fix tests --- test/spec/roxot_analytic_spec.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/test/spec/roxot_analytic_spec.js b/test/spec/roxot_analytic_spec.js index c545f23fc2c..019a0374a94 100644 --- a/test/spec/roxot_analytic_spec.js +++ b/test/spec/roxot_analytic_spec.js @@ -9,16 +9,15 @@ describe('Roxot Prebid Analytic', function () { it('should catch all events', function () { let config = {options: { publisherIds : ['foo'] } }; - console.log(analytic); - console.log(analytic.default.enableAnalytics); + analytic.default.enableAnalytics(config); analytic.default.track(constants.EVENTS.AUCTION_INIT, {}); + analytic.default.track(constants.EVENTS.AUCTION_INIT, {}); + analytic.default.track(constants.EVENTS.BID_REQUESTED, {}); + analytic.default.track(constants.EVENTS.BID_WON, {}); + analytic.default.track(constants.EVENTS.AUCTION_END, {}); + analytic.default.track(constants.EVENTS.BID_WON, {}); - events.emit(constants.EVENTS.AUCTION_INIT, {}); - events.emit(constants.EVENTS.BID_REQUESTED, {}); - events.emit(constants.EVENTS.BID_WON, {}); - events.emit(constants.EVENTS.AUCTION_END, {}); - events.emit(constants.EVENTS.BID_WON, {}); }); }); }); From 9a20ee07878cd251a94e9bcd5a8c5122ce5bb3f0 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Tue, 7 Mar 2017 17:35:56 +0300 Subject: [PATCH 10/18] Fix Roxot tests --- src/adapters/analytics/roxot.js | 12 +++++++----- test/spec/roxot_analytic_spec.js | 28 ++++++++++++++++++++-------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 5410adf74fa..8532562fc5f 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -1,6 +1,6 @@ -import {ajax} from 'src/ajax'; -import adapter from 'AnalyticsAdapter'; -import CONSTANTS from 'src/constants.json'; +import {ajax} from "src/ajax"; +import adapter from "AnalyticsAdapter"; +import CONSTANTS from "src/constants.json"; const utils = require('../../utils'); @@ -35,8 +35,10 @@ function buildEventStack() { } function send(eventType, data, sendDataType) { + let fullUrl = url + '?publisherIds[]=' + initOptions.publisherIds.join('&publisherIds[]=') + '&host=' + window.location.hostname; + ajax( - url, + fullUrl, (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analityc with result' + result), JSON.stringify(data) ); @@ -63,7 +65,7 @@ export default utils.extend(adapter({url, analyticsType}), return; } - if ((eventType === bidWonConst) && auctionStatus === 'not_started') { + if ((eventType === bidWonConst) && auctionStatus === 'not_started') { buildBidWon(eventType, args); send(eventType, bidWon, 'bidWon'); return; diff --git a/test/spec/roxot_analytic_spec.js b/test/spec/roxot_analytic_spec.js index 019a0374a94..9da709d0b83 100644 --- a/test/spec/roxot_analytic_spec.js +++ b/test/spec/roxot_analytic_spec.js @@ -1,6 +1,7 @@ let assert = require('assert'); let analytic = require('../../src/adapters/analytics/roxot'); let events = require('../../src/events'); +let adaptermanager = require('../../src/adaptermanager'); let constants = require('../../src/constants.json'); describe('Roxot Prebid Analytic', function () { @@ -8,15 +9,26 @@ describe('Roxot Prebid Analytic', function () { describe('enableAnalytics', function () { it('should catch all events', function () { - let config = {options: { publisherIds : ['foo'] } }; - analytic.default.enableAnalytics(config); - analytic.default.track(constants.EVENTS.AUCTION_INIT, {}); - analytic.default.track(constants.EVENTS.AUCTION_INIT, {}); - analytic.default.track(constants.EVENTS.BID_REQUESTED, {}); - analytic.default.track(constants.EVENTS.BID_WON, {}); - analytic.default.track(constants.EVENTS.AUCTION_END, {}); - analytic.default.track(constants.EVENTS.BID_WON, {}); + adaptermanager.registerAnalyticsAdapter({ + code: 'roxot', + adapter: analytic + }); + + adaptermanager.enableAnalytics({ + provider: 'roxot', + options: { + publisherIds: ['test_roxot_prebid_analytid_publisher_id'] + } + }); + + events.emit(constants.EVENTS.AUCTION_INIT, {}); + events.emit(constants.EVENTS.AUCTION_INIT, {}); + events.emit(constants.EVENTS.AUCTION_INIT, {}); + events.emit(constants.EVENTS.BID_REQUESTED, {}); + events.emit(constants.EVENTS.BID_WON, {}); + events.emit(constants.EVENTS.AUCTION_END, {}); + events.emit(constants.EVENTS.BID_WON, {}); }); }); From 6830f743680a5955627b80b7a65a5b9743befc2b Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Tue, 7 Mar 2017 17:38:13 +0300 Subject: [PATCH 11/18] Fix endpoint --- src/adapters/analytics/roxot.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 8532562fc5f..723c924cf49 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -4,7 +4,7 @@ import CONSTANTS from "src/constants.json"; const utils = require('../../utils'); -const url = '//pa.rxthdr.com/'; +const url = '//pa.rxthdr.com/analytic'; const analyticsType = 'endpoint'; let auctionInitConst = CONSTANTS.EVENTS.AUCTION_INIT; From 946e1498ba2e2daeb461d061aef37784db677051 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Wed, 15 Mar 2017 14:42:05 +0300 Subject: [PATCH 12/18] Register config only once. --- src/adapters/analytics/roxot.js | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 723c924cf49..8d753eaae59 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -52,19 +52,18 @@ function flushEvents() { eventStack.events = []; } -export default utils.extend(adapter({url, analyticsType}), +let roxotAdapter = utils.extend(adapter({url, analyticsType}), { track({eventType, args}) { + if (!checkOptions()) { + return; + } + if (eventType === auctionInitConst) { auctionStatus = 'started'; - initOptions = args.config; flushEvents(); } - if (!checkOptions()) { - return; - } - if ((eventType === bidWonConst) && auctionStatus === 'not_started') { buildBidWon(eventType, args); send(eventType, bidWon, 'bidWon'); @@ -81,3 +80,13 @@ export default utils.extend(adapter({url, analyticsType}), } } }); + +roxotAdapter.originEnableAnalytics = roxotAdapter.enableAnalytics; + +roxotAdapter.enableAnalytics = function(config) { + initOptions = config.options; + utils.logInfo('Roxot Analtyics enabled with config', initOptions); + roxotAdapter.originEnableAnalytics(config); +}; + +export default roxotAdapter; From 4b06cb7720248f007c01c629c1e97e2e445b5a22 Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Wed, 22 Mar 2017 16:25:35 +0300 Subject: [PATCH 13/18] Clear ad parameter for optimize traffic --- src/adapters/analytics/roxot.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 8d753eaae59..f7585e69e1a 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -59,6 +59,8 @@ let roxotAdapter = utils.extend(adapter({url, analyticsType}), return; } + args.ad = ""; + if (eventType === auctionInitConst) { auctionStatus = 'started'; flushEvents(); From ae802d04505b3bbbc8fd8f3a069c5cd35bbca2bf Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Mon, 27 Mar 2017 18:14:36 +0300 Subject: [PATCH 14/18] Fix after review --- package.json | 2 +- src/adapters/analytics/roxot.js | 10 ++++++---- test/spec/roxot_analytic_spec.js | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package.json b/package.json index e27cef445bb..721061ba1e0 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,7 @@ "prebid" ], "globalVarName": "pbjs", - "analytics": ["roxot_prebid_analytic"], + "analytics": [], "author": "the prebid.js contributors", "license": "Apache-2.0", "devDependencies": { diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index f7585e69e1a..6bb26d2fb88 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -27,7 +27,7 @@ function checkOptions() { function buildBidWon(eventType, args) { bidWon.options = initOptions; - bidWon.events = {args: args, eventType: eventType}; + bidWon.events = [{args: args, eventType: eventType}]; } function buildEventStack() { @@ -52,14 +52,16 @@ function flushEvents() { eventStack.events = []; } -let roxotAdapter = utils.extend(adapter({url, analyticsType}), +let roxotAdapter = Object.assign(adapter({url, analyticsType}), { track({eventType, args}) { if (!checkOptions()) { return; } - args.ad = ""; + if (args && args.ad) { + args.ad = ""; + } if (eventType === auctionInitConst) { auctionStatus = 'started'; @@ -85,7 +87,7 @@ let roxotAdapter = utils.extend(adapter({url, analyticsType}), roxotAdapter.originEnableAnalytics = roxotAdapter.enableAnalytics; -roxotAdapter.enableAnalytics = function(config) { +roxotAdapter.enableAnalytics = function (config) { initOptions = config.options; utils.logInfo('Roxot Analtyics enabled with config', initOptions); roxotAdapter.originEnableAnalytics(config); diff --git a/test/spec/roxot_analytic_spec.js b/test/spec/roxot_analytic_spec.js index 9da709d0b83..5f4cf25ef0d 100644 --- a/test/spec/roxot_analytic_spec.js +++ b/test/spec/roxot_analytic_spec.js @@ -1,4 +1,3 @@ -let assert = require('assert'); let analytic = require('../../src/adapters/analytics/roxot'); let events = require('../../src/events'); let adaptermanager = require('../../src/adaptermanager'); From f3ed3f7b3388bb6189fac1808d7ae419c3f6fe3a Mon Sep 17 00:00:00 2001 From: Kir Apukhtin Date: Mon, 10 Apr 2017 12:27:22 +0300 Subject: [PATCH 15/18] Fix remove ad from global object --- src/adapters/analytics/roxot.js | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 6bb26d2fb88..0ba5f5a752b 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -59,8 +59,10 @@ let roxotAdapter = Object.assign(adapter({url, analyticsType}), return; } - if (args && args.ad) { - args.ad = ""; + let info = Object.assign({}, args); + + if (info && info.ad) { + info.ad = ""; } if (eventType === auctionInitConst) { @@ -69,7 +71,7 @@ let roxotAdapter = Object.assign(adapter({url, analyticsType}), } if ((eventType === bidWonConst) && auctionStatus === 'not_started') { - buildBidWon(eventType, args); + buildBidWon(eventType,info); send(eventType, bidWon, 'bidWon'); return; } @@ -80,7 +82,7 @@ let roxotAdapter = Object.assign(adapter({url, analyticsType}), flushEvents(); auctionStatus = 'not_started'; } else { - pushEvent(eventType, args); + pushEvent(eventType, info); } } }); From f7c3eab47ea1c6b1933d6e9fe0cf06740bbefb98 Mon Sep 17 00:00:00 2001 From: Alexandr Ivanov Date: Mon, 10 Apr 2017 16:39:16 +0300 Subject: [PATCH 16/18] Add tests. --- package.json | 6 ++++-- src/adapters/analytics/roxot.js | 4 ++-- .../analytics}/roxot_analytic_spec.js | 19 ++++++++++--------- 3 files changed, 16 insertions(+), 13 deletions(-) rename test/spec/{ => adapters/analytics}/roxot_analytic_spec.js (60%) diff --git a/package.json b/package.json index 926d3270068..bfb2afeb46f 100644 --- a/package.json +++ b/package.json @@ -25,7 +25,7 @@ "babel-plugin-transform-es3-member-expression-literals": "^6.8.0", "babel-plugin-transform-es3-property-literals": "^6.8.0", "babel-plugin-transform-object-assign": "^6.8.0", - "babel-preset-es2015": "^6.5.0", + "babel-preset-es2015": "^6.24.1", "block-loader": "^2.1.0", "chai": "^3.3.0", "coveralls": "^2.11.11", @@ -98,6 +98,8 @@ }, "dependencies": { "array-includes": "^3.0.2", - "array.prototype.find": "^2.0.3" + "array.prototype.find": "^2.0.3", + "babel-cli": "^6.24.1", + "babel-preset-node6": "^11.0.0" } } diff --git a/src/adapters/analytics/roxot.js b/src/adapters/analytics/roxot.js index 0ba5f5a752b..7668d0ba050 100644 --- a/src/adapters/analytics/roxot.js +++ b/src/adapters/analytics/roxot.js @@ -39,7 +39,7 @@ function send(eventType, data, sendDataType) { ajax( fullUrl, - (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analityc with result' + result), + (result) => utils.logInfo('Event ' + eventType + ' sent ' + sendDataType + ' to roxot prebid analytic with result' + result), JSON.stringify(data) ); } @@ -91,7 +91,7 @@ roxotAdapter.originEnableAnalytics = roxotAdapter.enableAnalytics; roxotAdapter.enableAnalytics = function (config) { initOptions = config.options; - utils.logInfo('Roxot Analtyics enabled with config', initOptions); + utils.logInfo('Roxot Analytics enabled with config', initOptions); roxotAdapter.originEnableAnalytics(config); }; diff --git a/test/spec/roxot_analytic_spec.js b/test/spec/adapters/analytics/roxot_analytic_spec.js similarity index 60% rename from test/spec/roxot_analytic_spec.js rename to test/spec/adapters/analytics/roxot_analytic_spec.js index 5f4cf25ef0d..fd19ca464a8 100644 --- a/test/spec/roxot_analytic_spec.js +++ b/test/spec/adapters/analytics/roxot_analytic_spec.js @@ -1,17 +1,19 @@ -let analytic = require('../../src/adapters/analytics/roxot'); -let events = require('../../src/events'); -let adaptermanager = require('../../src/adaptermanager'); -let constants = require('../../src/constants.json'); +import roxotAnalytic from 'src/adapters/analytics/roxot'; +let events = require('../../../../src/events'); +let adaptermanager = require('../../../../src/adaptermanager'); +let constants = require('../../../../src/constants.json'); describe('Roxot Prebid Analytic', function () { describe('enableAnalytics', function () { + it('should catch all events', function () { + sinon.spy(roxotAnalytic, 'track'); adaptermanager.registerAnalyticsAdapter({ code: 'roxot', - adapter: analytic + adapter: roxotAnalytic }); adaptermanager.enableAnalytics({ @@ -22,13 +24,12 @@ describe('Roxot Prebid Analytic', function () { }); events.emit(constants.EVENTS.AUCTION_INIT, {}); - events.emit(constants.EVENTS.AUCTION_INIT, {}); - events.emit(constants.EVENTS.AUCTION_INIT, {}); - events.emit(constants.EVENTS.BID_REQUESTED, {}); - events.emit(constants.EVENTS.BID_WON, {}); events.emit(constants.EVENTS.AUCTION_END, {}); + events.emit(constants.EVENTS.BID_REQUESTED, {}); + events.emit(constants.EVENTS.BID_RESPONSE, {}); events.emit(constants.EVENTS.BID_WON, {}); + sinon.assert.callCount(roxotAnalytic.track, 5); }); }); }); From 8702ba3d946149d1ca36ac9630f78ca885d181d5 Mon Sep 17 00:00:00 2001 From: Alexandr Ivanov Date: Mon, 10 Apr 2017 17:29:10 +0300 Subject: [PATCH 17/18] Remove request_bids event from AnalyticsAdapter.js --- src/adapters/analytics/AnalyticsAdapter.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/adapters/analytics/AnalyticsAdapter.js b/src/adapters/analytics/AnalyticsAdapter.js index 9b373391fb9..2c177621047 100644 --- a/src/adapters/analytics/AnalyticsAdapter.js +++ b/src/adapters/analytics/AnalyticsAdapter.js @@ -12,7 +12,6 @@ const BID_TIMEOUT = CONSTANTS.EVENTS.BID_TIMEOUT; const BID_RESPONSE = CONSTANTS.EVENTS.BID_RESPONSE; const BID_WON = CONSTANTS.EVENTS.BID_WON; const BID_ADJUSTMENT = CONSTANTS.EVENTS.BID_ADJUSTMENT; -const REQUEST_BIDS = CONSTANTS.EVENTS.REQUEST_BIDS; const LIBRARY = 'library'; const ENDPOINT = 'endpoint'; @@ -102,7 +101,6 @@ export default function AnalyticsAdapter({ url, analyticsType, global, handler } //Next register event listeners to send data immediately _handlers = { - [REQUEST_BIDS]: args => this.enqueue({ eventType: REQUEST_BIDS, args }), [BID_REQUESTED]: args => this.enqueue({ eventType: BID_REQUESTED, args }), [BID_RESPONSE]: args => this.enqueue({ eventType: BID_RESPONSE, args }), [BID_TIMEOUT]: args => this.enqueue({ eventType: BID_TIMEOUT, args }), From b6ac875ad04509c841ff1f64e2de7e91f396fab2 Mon Sep 17 00:00:00 2001 From: Alexandr Ivanov Date: Tue, 11 Apr 2017 12:18:39 +0300 Subject: [PATCH 18/18] Remove extra dependencies --- package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/package.json b/package.json index bfb2afeb46f..28f0ac3375f 100644 --- a/package.json +++ b/package.json @@ -98,8 +98,6 @@ }, "dependencies": { "array-includes": "^3.0.2", - "array.prototype.find": "^2.0.3", - "babel-cli": "^6.24.1", - "babel-preset-node6": "^11.0.0" + "array.prototype.find": "^2.0.3" } }