From 2fba6a29ce0f473e4b174c35afdd9b535d363699 Mon Sep 17 00:00:00 2001 From: anand-venkatraman Date: Fri, 14 Oct 2016 08:31:49 -0400 Subject: [PATCH 01/13] ET-1691: Pulsepoint Analytics adapter for Prebid. (#1) * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: Adding pulsepoint analytics and tests for pulsepoint adapter * ET-1691: cleanup * ET-1691: minor * ET-1691: revert package.json change --- src/adapters/analytics/pulsepoint.js | 12 +++ test/spec/adapters/pulsepoint_spec.js | 143 ++++++++++++++++++++++++++ 2 files changed, 155 insertions(+) create mode 100644 src/adapters/analytics/pulsepoint.js create mode 100644 test/spec/adapters/pulsepoint_spec.js diff --git a/src/adapters/analytics/pulsepoint.js b/src/adapters/analytics/pulsepoint.js new file mode 100644 index 00000000000..28f4e7f1c78 --- /dev/null +++ b/src/adapters/analytics/pulsepoint.js @@ -0,0 +1,12 @@ +/** + * pulsepoint.js - Analytics Adapter for PulsePoint + */ + +import adapter from 'AnalyticsAdapter'; + +export default adapter({ + global: 'PulsePointPrebidAnalytics', + handler: 'on', + analyticsType: 'bundle' + }); + diff --git a/test/spec/adapters/pulsepoint_spec.js b/test/spec/adapters/pulsepoint_spec.js new file mode 100644 index 00000000000..fe5dee461db --- /dev/null +++ b/test/spec/adapters/pulsepoint_spec.js @@ -0,0 +1,143 @@ +import {expect} from 'chai'; +import PulsePointAdapter from '../../../src/adapters/pulsepoint'; +import bidManager from '../../../src/bidmanager'; +import adLoader from '../../../src/adloader'; + +describe("PulsePoint Adapter Tests", () => { + + let pulsepointAdapter = new PulsePointAdapter(); + let slotConfigs; + let requests = []; + let responses = {}; + + function initPulsepointLib() { + /* Mocked PulsePoint library */ + window.pp = { + requestActions: { + BID: 0 + } + }; + /* Ad object*/ + window.pp.Ad = function(config) { + this.display = function() { + requests.push(config); + config.callback(responses[config.ct]); + }; + }; + } + + function resetPulsepointLib() { + window.pp = undefined; + } + + beforeEach(() => { + initPulsepointLib(); + sinon.stub(bidManager, 'addBidResponse'); + sinon.stub(adLoader, 'loadScript'); + + slotConfigs = { + bids: [ + { + placementCode: "/DfpAccount1/slot1", + bidder: "pulsepoint", + params: { + cp: "p10000", + ct: "t10000", + cf: "300x250" + } + },{ + placementCode: "/DfpAccount2/slot2", + bidder: "pulsepoint", + params: { + cp: "p20000", + ct: "t20000", + cf: "728x90" + } + } + ] + }; + }); + + afterEach(() => { + bidManager.addBidResponse.restore(); + adLoader.loadScript.restore(); + requests = []; + responses = {}; + }); + + it('Verify requests sent to PulsePoint library', () => { + pulsepointAdapter.callBids(slotConfigs); + expect(requests).to.have.length(2); + //slot 1 + expect(requests[0].cp).to.equal('p10000'); + expect(requests[0].ct).to.equal('t10000'); + expect(requests[0].cf).to.equal('300x250'); + expect(requests[0].ca).to.equal(0); + expect(requests[0].cn).to.equal(1); + expect(requests[0].cu).to.equal('http://bid.contextweb.com/header/tag'); + expect(requests[0].adUnitId).to.equal('/DfpAccount1/slot1'); + expect(requests[0]).to.have.property('callback'); + // //slot 2 + expect(requests[1].cp).to.equal('p20000'); + expect(requests[1].ct).to.equal('t20000'); + expect(requests[1].cf).to.equal('728x90'); + expect(requests[1].ca).to.equal(0); + expect(requests[1].cn).to.equal(1); + expect(requests[1].cu).to.equal('http://bid.contextweb.com/header/tag'); + expect(requests[1].adUnitId).to.equal('/DfpAccount2/slot2'); + expect(requests[1]).to.have.property('callback'); + }); + + it('Verify bid', () => { + responses['t10000'] = { + html: 'This is an Ad', + bidCpm: 1.25 + }; + pulsepointAdapter.callBids(slotConfigs); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid.cpm).to.equal(1.25); + expect(bid.ad).to.equal('This is an Ad'); + expect(bid.width).to.equal('300'); + expect(bid.height).to.equal('250'); + }); + + it('Verify passback', () => { + pulsepointAdapter.callBids(slotConfigs); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid).to.not.have.property('ad'); + expect(bid).to.not.have.property('cpm'); + }); + + it('Verify PulsePoint library is downloaded if nessesary', () => { + resetPulsepointLib(); + pulsepointAdapter.callBids(slotConfigs); + let libraryLoadCall = adLoader.loadScript.firstCall.args[0]; + let callback = adLoader.loadScript.firstCall.args[1]; + expect(libraryLoadCall).to.equal('http://tag.contextweb.com/getjs.static.js'); + expect(callback).to.be.a('function'); + }); + + it('Verify Bids get processed after PulsePoint library downloads', () => { + resetPulsepointLib(); + pulsepointAdapter.callBids(slotConfigs); + let callback = adLoader.loadScript.firstCall.args[1]; + let bidCall = bidManager.addBidResponse.firstCall; + expect(callback).to.be.a('function'); + expect(bidCall).to.be.a('null'); + //the library load should initialize pulsepoint lib + initPulsepointLib(); + callback(); + expect(requests.length).to.equal(2); + bidCall = bidManager.addBidResponse.firstCall; + expect(bidCall).to.be.a('object'); + expect(bidCall.args[0]).to.equal('/DfpAccount1/slot1'); + expect(bidCall.args[1]).to.be.a('object'); + }); + +}); From 5da43c32c0d739bb1946601bdf7bf713cd7b1d7c Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Tue, 25 Oct 2016 15:56:41 -0400 Subject: [PATCH 02/13] Adding bidRequest to bidFactory.createBid method as per https://github.com/prebid/Prebid.js/issues/509 --- src/adapters/pulsepoint.js | 4 ++-- test/spec/adapters/pulsepoint_spec.js | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index fa2d2f73748..ef82b05f4e5 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -43,7 +43,7 @@ var PulsePointAdapter = function PulsePointAdapter() { function bidResponseAvailable(bidRequest, bidResponse) { if (bidResponse) { var adSize = bidRequest.params.cf.toUpperCase().split('X'); - var bid = bidfactory.createBid(1); + var bid = bidfactory.createBid(1, bidRequest); bid.bidderCode = bidRequest.bidder; bid.cpm = bidResponse.bidCpm; bid.ad = bidResponse.html; @@ -51,7 +51,7 @@ var PulsePointAdapter = function PulsePointAdapter() { bid.height = adSize[1]; bidmanager.addBidResponse(bidRequest.placementCode, bid); } else { - var passback = bidfactory.createBid(2); + var passback = bidfactory.createBid(2, bidRequest); passback.bidderCode = bidRequest.bidder; bidmanager.addBidResponse(bidRequest.placementCode, passback); } diff --git a/test/spec/adapters/pulsepoint_spec.js b/test/spec/adapters/pulsepoint_spec.js index fe5dee461db..96755a36207 100644 --- a/test/spec/adapters/pulsepoint_spec.js +++ b/test/spec/adapters/pulsepoint_spec.js @@ -40,6 +40,7 @@ describe("PulsePoint Adapter Tests", () => { { placementCode: "/DfpAccount1/slot1", bidder: "pulsepoint", + bidId: 'bid12345', params: { cp: "p10000", ct: "t10000", @@ -48,6 +49,7 @@ describe("PulsePoint Adapter Tests", () => { },{ placementCode: "/DfpAccount2/slot2", bidder: "pulsepoint", + bidId: 'bid23456', params: { cp: "p20000", ct: "t20000", @@ -102,6 +104,7 @@ describe("PulsePoint Adapter Tests", () => { expect(bid.ad).to.equal('This is an Ad'); expect(bid.width).to.equal('300'); expect(bid.height).to.equal('250'); + expect(bid.adId).to.equal('bid12345'); }); it('Verify passback', () => { @@ -112,6 +115,7 @@ describe("PulsePoint Adapter Tests", () => { expect(bid.bidderCode).to.equal('pulsepoint'); expect(bid).to.not.have.property('ad'); expect(bid).to.not.have.property('cpm'); + expect(bid.adId).to.equal('bid12345'); }); it('Verify PulsePoint library is downloaded if nessesary', () => { From 62756a9cf82a835fd2e77f0efc1449c84d748467 Mon Sep 17 00:00:00 2001 From: anand-venkatraman Date: Wed, 9 Nov 2016 10:57:09 -0500 Subject: [PATCH 03/13] ET-1765: Adding support for additional params in PulsePoint adapter (#2) --- src/adapters/pulsepoint.js | 29 +++++++++++++++++---------- test/spec/adapters/pulsepoint_spec.js | 6 +++++- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index ef82b05f4e5..42479b895a3 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -19,21 +19,28 @@ var PulsePointAdapter = function PulsePointAdapter() { var bids = params.bids; for (var i = 0; i < bids.length; i++) { var bidRequest = bids[i]; - var callback = bidResponseCallback(bidRequest); - var ppBidRequest = new window.pp.Ad({ - cf: bidRequest.params.cf, - cp: bidRequest.params.cp, - ct: bidRequest.params.ct, - cn: 1, - ca: window.pp.requestActions.BID, - cu: bidUrl, - adUnitId: bidRequest.placementCode, - callback: callback - }); + var ppBidRequest = new window.pp.Ad(bidRequestOptions(bidRequest)); ppBidRequest.display(); } } + function bidRequestOptions(bidRequest) { + var callback = bidResponseCallback(bidRequest); + var options = { + cn: 1, + ca: window.pp.requestActions.BID, + cu: bidUrl, + adUnitId: bidRequest.placementCode, + callback: callback + }; + for(var param in bidRequest.params) { + if(bidRequest.params.hasOwnProperty(param)) { + options[param] = bidRequest.params[param]; + } + } + return options; + } + function bidResponseCallback(bid) { return function (bidResponse) { bidResponseAvailable(bid, bidResponse); diff --git a/test/spec/adapters/pulsepoint_spec.js b/test/spec/adapters/pulsepoint_spec.js index 96755a36207..9c901cd149b 100644 --- a/test/spec/adapters/pulsepoint_spec.js +++ b/test/spec/adapters/pulsepoint_spec.js @@ -44,7 +44,9 @@ describe("PulsePoint Adapter Tests", () => { params: { cp: "p10000", ct: "t10000", - cf: "300x250" + cf: "300x250", + param1: "value1", + param2: 2 } },{ placementCode: "/DfpAccount2/slot2", @@ -79,6 +81,8 @@ describe("PulsePoint Adapter Tests", () => { expect(requests[0].cu).to.equal('http://bid.contextweb.com/header/tag'); expect(requests[0].adUnitId).to.equal('/DfpAccount1/slot1'); expect(requests[0]).to.have.property('callback'); + expect(requests[0].param1).to.equal('value1'); + expect(requests[0].param2).to.equal(2); // //slot 2 expect(requests[1].cp).to.equal('p20000'); expect(requests[1].ct).to.equal('t20000'); From b9af15cac48fc7180ef79c6a7936ae721c6a0fb1 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Thu, 8 Dec 2016 12:48:40 -0500 Subject: [PATCH 04/13] ET-1850: Fixing https://github.com/prebid/Prebid.js/issues/866 --- src/adapters/pulsepoint.js | 11 +++++++++++ test/spec/adapters/pulsepoint_spec.js | 14 ++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index 42479b895a3..7e882ea8591 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -1,6 +1,7 @@ var bidfactory = require('../bidfactory.js'); var bidmanager = require('../bidmanager.js'); var adloader = require('../adloader.js'); +var utils = require('../utils.js'); var PulsePointAdapter = function PulsePointAdapter() { @@ -19,8 +20,18 @@ var PulsePointAdapter = function PulsePointAdapter() { var bids = params.bids; for (var i = 0; i < bids.length; i++) { var bidRequest = bids[i]; + requestBid(bidRequest); + } + } + + function requestBid(bidRequest) { + try { var ppBidRequest = new window.pp.Ad(bidRequestOptions(bidRequest)); ppBidRequest.display(); + } catch(e) { + //register passback on any exceptions while attempting to fetch response. + utils.logMessage('pulsepoint.requestBid', 'ERROR', e); + bidResponseAvailable(bidRequest); } } diff --git a/test/spec/adapters/pulsepoint_spec.js b/test/spec/adapters/pulsepoint_spec.js index 9c901cd149b..0e9fb97fa4c 100644 --- a/test/spec/adapters/pulsepoint_spec.js +++ b/test/spec/adapters/pulsepoint_spec.js @@ -148,4 +148,18 @@ describe("PulsePoint Adapter Tests", () => { expect(bidCall.args[1]).to.be.a('object'); }); + //related to issue https://github.com/prebid/Prebid.js/issues/866 + it('Verify Passbacks when window.pp is not available', () => { + window.pp = function() {}; + pulsepointAdapter.callBids(slotConfigs); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + //verify that we passed back without exceptions, should window.pp be already taken. + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid).to.not.have.property('ad'); + expect(bid).to.not.have.property('cpm'); + expect(bid.adId).to.equal('bid12345'); + }); + }); From 45dfc76f564c1b1666a2c00f8020e7be952ebe36 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Thu, 8 Dec 2016 17:32:45 -0500 Subject: [PATCH 05/13] ET-1850: Adding a "lite" adapter. --- adapters.json | 1 + src/adapters/pulsepointLite.js | 83 ++++++++++++++++++++ test/spec/adapters/pulsepointLite_spec.js | 96 +++++++++++++++++++++++ 3 files changed, 180 insertions(+) create mode 100644 src/adapters/pulsepointLite.js create mode 100644 test/spec/adapters/pulsepointLite_spec.js diff --git a/adapters.json b/adapters.json index 06a353e6541..a35f6edbba9 100644 --- a/adapters.json +++ b/adapters.json @@ -21,6 +21,7 @@ "piximedia", "pubmatic", "pulsepoint", + "pulsepointLite", "rhythmone", "rubicon", "sonobi", diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js new file mode 100644 index 00000000000..a4801522045 --- /dev/null +++ b/src/adapters/pulsepointLite.js @@ -0,0 +1,83 @@ +import {createBid} from 'src/bidfactory'; +import {addBidResponse} from 'src/bidmanager'; +import {logError} from 'src/utils'; +import {ajax} from 'src/ajax'; +import {STATUS} from 'src/constants'; + +function PulsePointLiteAdapter() { + + var bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag'; + + function _callBids(bidderRequest) { + var bids = bidderRequest.bids; + for (var i = 0; i < bids.length; i++) { + var bidRequest = bids[i]; + requestBid(bidRequest); + } + } + + function requestBid(bidRequest) { + try { + var env = environment(); + var params = Object.assign({}, env, bidRequest.params); + var ajaxOptions = { + withCredentials: true + }; + ajax(bidUrl, (bidResponse) => { + bidResponseAvailable(bidRequest, bidResponse); + }, params, ajaxOptions); + } catch(e) { + //register passback on any exceptions while attempting to fetch response. + logError('pulsepoint.requestBid', 'ERROR', e); + bidResponseAvailable(bidRequest); + } + } + + function environment() { + return { + cn: 1, + ca: 'BID', + tl: 1, + 'if': 0, + cwu: encodeURIComponent(getPageUrl()), + cwr: encodeURIComponent(document.referrer), + dw: document.documentElement.clientWidth, + cxy: document.documentElement.clientWidth + ',' + document.documentElement.clientHeight, + tz: new Date().getTimezoneOffset(), + ln: (navigator.language || navigator.browserLanguage || navigator.userLanguage || navigator.systemLanguage) + }; + } + + function getPageUrl() { + try { + return window.top.location.href; + } + catch (e) { + return window.location.href; + } + } + + function bidResponseAvailable(bidRequest, bidResponse) { + if (bidResponse) { + var adSize = bidRequest.params.cf.toUpperCase().split('X'); + var bid = createBid(STATUS.GOOD, bidRequest); + bid.bidderCode = bidRequest.bidder; + bid.cpm = bidResponse.bidCpm; + bid.ad = bidResponse.html; + bid.width = adSize[0]; + bid.height = adSize[1]; + addBidResponse(bidRequest.placementCode, bid); + } else { + var passback = createBid(STATUS.NO_BID, bidRequest); + passback.bidderCode = bidRequest.bidder; + addBidResponse(bidRequest.placementCode, passback); + } + } + + return { + callBids: _callBids + }; + +} + +module.exports = PulsePointLiteAdapter; \ No newline at end of file diff --git a/test/spec/adapters/pulsepointLite_spec.js b/test/spec/adapters/pulsepointLite_spec.js new file mode 100644 index 00000000000..2f34e3b65df --- /dev/null +++ b/test/spec/adapters/pulsepointLite_spec.js @@ -0,0 +1,96 @@ +import {expect} from 'chai'; +import PulsePointAdapter from 'src/adapters/pulsepointLite'; +import bidManager from 'src/bidmanager'; +import * as ajax from "src/ajax"; +import {parse as parseURL} from 'src/url'; + +describe("PulsePoint Adapter Tests", () => { + + let pulsepointAdapter = new PulsePointAdapter(); + let slotConfigs; + let ajaxStub; + + beforeEach(() => { + sinon.stub(bidManager, 'addBidResponse'); + ajaxStub = sinon.stub(ajax, 'ajax'); + + slotConfigs = { + bids: [ + { + placementCode: "/DfpAccount1/slot1", + bidder: "pulsepoint", + bidId: 'bid12345', + params: { + cp: "p10000", + ct: "t10000", + cf: "300x250" + } + },{ + placementCode: "/DfpAccount2/slot2", + bidder: "pulsepoint", + bidId: 'bid23456', + params: { + cp: "p20000", + ct: "t20000", + cf: "728x90" + } + } + ] + }; + }); + + afterEach(() => { + bidManager.addBidResponse.restore(); + ajaxStub.restore(); + }); + + it('Verify requests sent to PulsePoint', () => { + pulsepointAdapter.callBids(slotConfigs); + var call = ajaxStub.firstCall.args[2]; + //slot 1 + expect(call.cp).to.equal('p10000'); + expect(call.ct).to.equal('t10000'); + expect(call.cf).to.equal('300x250'); + expect(call.ca).to.equal('BID'); + expect(call.cn).to.equal(1); + //slot 2 + call = ajaxStub.secondCall.args[2]; + expect(call.cp).to.equal('p20000'); + expect(call.ct).to.equal('t20000'); + expect(call.cf).to.equal('728x90'); + expect(call.ca).to.equal('BID'); + expect(call.cn).to.equal(1); + }); + + it('Verify bid', () => { + pulsepointAdapter.callBids(slotConfigs); + //trigger a mock ajax callback with bid. + ajaxStub.firstCall.args[1]({ + html: 'This is an Ad', + bidCpm: 1.25 + }); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid.cpm).to.equal(1.25); + expect(bid.ad).to.equal('This is an Ad'); + expect(bid.width).to.equal('300'); + expect(bid.height).to.equal('250'); + expect(bid.adId).to.equal('bid12345'); + }); + + it('Verify passback', () => { + pulsepointAdapter.callBids(slotConfigs); + //trigger a mock ajax callback with no bid. + ajaxStub.firstCall.args[1](null); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid).to.not.have.property('ad'); + expect(bid).to.not.have.property('cpm'); + expect(bid.adId).to.equal('bid12345'); + }); + +}); From b5eeb7f618fbe62c81c4c3f80a293f7e12a9aaad Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Thu, 8 Dec 2016 17:34:55 -0500 Subject: [PATCH 06/13] Minor fix --- src/adapters/pulsepoint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index 7e882ea8591..aaad60ee311 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -30,7 +30,7 @@ var PulsePointAdapter = function PulsePointAdapter() { ppBidRequest.display(); } catch(e) { //register passback on any exceptions while attempting to fetch response. - utils.logMessage('pulsepoint.requestBid', 'ERROR', e); + utils.logError('pulsepoint.requestBid', 'ERROR', e); bidResponseAvailable(bidRequest); } } From 40ed4643e6ec3c1f31274a80029cb38e49607d7f Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Fri, 9 Dec 2016 16:35:15 -0500 Subject: [PATCH 07/13] Fix for response parsing --- src/adapters/pulsepointLite.js | 35 +++++++++++++---------- test/spec/adapters/pulsepointLite_spec.js | 4 +-- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js index a4801522045..a6d02d16ed7 100644 --- a/src/adapters/pulsepointLite.js +++ b/src/adapters/pulsepointLite.js @@ -21,7 +21,9 @@ function PulsePointLiteAdapter() { var env = environment(); var params = Object.assign({}, env, bidRequest.params); var ajaxOptions = { - withCredentials: true + contentType: 'text/plain', + withCredentials: true, + method: 'GET' }; ajax(bidUrl, (bidResponse) => { bidResponseAvailable(bidRequest, bidResponse); @@ -57,21 +59,24 @@ function PulsePointLiteAdapter() { } } - function bidResponseAvailable(bidRequest, bidResponse) { - if (bidResponse) { - var adSize = bidRequest.params.cf.toUpperCase().split('X'); - var bid = createBid(STATUS.GOOD, bidRequest); - bid.bidderCode = bidRequest.bidder; - bid.cpm = bidResponse.bidCpm; - bid.ad = bidResponse.html; - bid.width = adSize[0]; - bid.height = adSize[1]; - addBidResponse(bidRequest.placementCode, bid); - } else { - var passback = createBid(STATUS.NO_BID, bidRequest); - passback.bidderCode = bidRequest.bidder; - addBidResponse(bidRequest.placementCode, passback); + function bidResponseAvailable(bidRequest, rawResponse) { + if (rawResponse) { + var bidResponse = JSON.parse(rawResponse); + if(bidResponse) { + var adSize = bidRequest.params.cf.toUpperCase().split('X'); + var bid = createBid(STATUS.GOOD, bidRequest); + bid.bidderCode = bidRequest.bidder; + bid.cpm = bidResponse.bidCpm; + bid.ad = bidResponse.html; + bid.width = adSize[0]; + bid.height = adSize[1]; + addBidResponse(bidRequest.placementCode, bid); + return; + } } + var passback = createBid(STATUS.NO_BID, bidRequest); + passback.bidderCode = bidRequest.bidder; + addBidResponse(bidRequest.placementCode, passback); } return { diff --git a/test/spec/adapters/pulsepointLite_spec.js b/test/spec/adapters/pulsepointLite_spec.js index 2f34e3b65df..2f1da7a8e9b 100644 --- a/test/spec/adapters/pulsepointLite_spec.js +++ b/test/spec/adapters/pulsepointLite_spec.js @@ -65,10 +65,10 @@ describe("PulsePoint Adapter Tests", () => { it('Verify bid', () => { pulsepointAdapter.callBids(slotConfigs); //trigger a mock ajax callback with bid. - ajaxStub.firstCall.args[1]({ + ajaxStub.firstCall.args[1](JSON.stringify({ html: 'This is an Ad', bidCpm: 1.25 - }); + })); let placement = bidManager.addBidResponse.firstCall.args[0]; let bid = bidManager.addBidResponse.firstCall.args[1]; expect(placement).to.equal('/DfpAccount1/slot1'); From ece11aef9d50fe6a30dad5b2caaa528d221ff7af Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Mon, 12 Dec 2016 12:28:42 -0500 Subject: [PATCH 08/13] Minor changes --- src/adapters/pulsepointLite.js | 49 ++++++++++++----------- test/spec/adapters/pulsepointLite_spec.js | 10 ++--- 2 files changed, 30 insertions(+), 29 deletions(-) diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js index a6d02d16ed7..dc8f37fed0d 100644 --- a/src/adapters/pulsepointLite.js +++ b/src/adapters/pulsepointLite.js @@ -6,28 +6,22 @@ import {STATUS} from 'src/constants'; function PulsePointLiteAdapter() { - var bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag'; + var bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag?'; + var ajaxOptions = { + method: 'GET', + withCredentials: true, + contentType: 'text/plain' + }; function _callBids(bidderRequest) { - var bids = bidderRequest.bids; - for (var i = 0; i < bids.length; i++) { - var bidRequest = bids[i]; - requestBid(bidRequest); - } - } - - function requestBid(bidRequest) { try { - var env = environment(); - var params = Object.assign({}, env, bidRequest.params); - var ajaxOptions = { - contentType: 'text/plain', - withCredentials: true, - method: 'GET' - }; - ajax(bidUrl, (bidResponse) => { - bidResponseAvailable(bidRequest, bidResponse); - }, params, ajaxOptions); + bidderRequest.bids.forEach(bidRequest => { + var params = Object.assign({}, environment(), bidRequest.params); + var url = bidUrl + Object.keys(params).map(k => k + '=' + encodeURIComponent(params[k])).join('&'); + ajax(url, (bidResponse) => { + bidResponseAvailable(bidRequest, bidResponse); + }, null, ajaxOptions); + }); } catch(e) { //register passback on any exceptions while attempting to fetch response. logError('pulsepoint.requestBid', 'ERROR', e); @@ -36,13 +30,14 @@ function PulsePointLiteAdapter() { } function environment() { + var pg = pageUrl(); return { cn: 1, ca: 'BID', tl: 1, 'if': 0, - cwu: encodeURIComponent(getPageUrl()), - cwr: encodeURIComponent(document.referrer), + cwu: pg.pg, + cwr: pg.ref, dw: document.documentElement.clientWidth, cxy: document.documentElement.clientWidth + ',' + document.documentElement.clientHeight, tz: new Date().getTimezoneOffset(), @@ -50,12 +45,18 @@ function PulsePointLiteAdapter() { }; } - function getPageUrl() { + function pageUrl() { try { - return window.top.location.href; + return { + pg: window.top.location.href, + ref: window.top.document.referrer + }; } catch (e) { - return window.location.href; + return { + pg: location.href, + ref: document.referrer + }; } } diff --git a/test/spec/adapters/pulsepointLite_spec.js b/test/spec/adapters/pulsepointLite_spec.js index 2f1da7a8e9b..116cdb859a7 100644 --- a/test/spec/adapters/pulsepointLite_spec.js +++ b/test/spec/adapters/pulsepointLite_spec.js @@ -4,7 +4,7 @@ import bidManager from 'src/bidmanager'; import * as ajax from "src/ajax"; import {parse as parseURL} from 'src/url'; -describe("PulsePoint Adapter Tests", () => { +describe("PulsePoint Lite Adapter Tests", () => { let pulsepointAdapter = new PulsePointAdapter(); let slotConfigs; @@ -46,20 +46,20 @@ describe("PulsePoint Adapter Tests", () => { it('Verify requests sent to PulsePoint', () => { pulsepointAdapter.callBids(slotConfigs); - var call = ajaxStub.firstCall.args[2]; + var call = parseURL(ajaxStub.firstCall.args[0]).search; //slot 1 expect(call.cp).to.equal('p10000'); expect(call.ct).to.equal('t10000'); expect(call.cf).to.equal('300x250'); expect(call.ca).to.equal('BID'); - expect(call.cn).to.equal(1); + expect(call.cn).to.equal('1'); //slot 2 - call = ajaxStub.secondCall.args[2]; + call = parseURL(ajaxStub.secondCall.args[0]).search; expect(call.cp).to.equal('p20000'); expect(call.ct).to.equal('t20000'); expect(call.cf).to.equal('728x90'); expect(call.ca).to.equal('BID'); - expect(call.cn).to.equal(1); + expect(call.cn).to.equal('1'); }); it('Verify bid', () => { From c1efbe10bc1fb8b2e1d103bbde81fd127a63d395 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Mon, 12 Dec 2016 12:35:27 -0500 Subject: [PATCH 09/13] Minor changes --- src/adapters/pulsepointLite.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js index dc8f37fed0d..463f0d44132 100644 --- a/src/adapters/pulsepointLite.js +++ b/src/adapters/pulsepointLite.js @@ -14,19 +14,19 @@ function PulsePointLiteAdapter() { }; function _callBids(bidderRequest) { - try { - bidderRequest.bids.forEach(bidRequest => { + bidderRequest.bids.forEach(bidRequest => { + try { var params = Object.assign({}, environment(), bidRequest.params); var url = bidUrl + Object.keys(params).map(k => k + '=' + encodeURIComponent(params[k])).join('&'); ajax(url, (bidResponse) => { bidResponseAvailable(bidRequest, bidResponse); }, null, ajaxOptions); - }); - } catch(e) { - //register passback on any exceptions while attempting to fetch response. - logError('pulsepoint.requestBid', 'ERROR', e); - bidResponseAvailable(bidRequest); - } + } catch(e) { + //register passback on any exceptions while attempting to fetch response. + logError('pulsepoint.requestBid', 'ERROR', e); + bidResponseAvailable(bidRequest); + } + }); } function environment() { From ccdf6c2e3b5449c7e665aa51d5b0b0736f788baa Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Tue, 28 Feb 2017 11:25:07 -0500 Subject: [PATCH 10/13] Updating JS lib endpoint --- src/adapters/pulsepoint.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/pulsepoint.js b/src/adapters/pulsepoint.js index aaad60ee311..e206c32550a 100644 --- a/src/adapters/pulsepoint.js +++ b/src/adapters/pulsepoint.js @@ -5,7 +5,7 @@ var utils = require('../utils.js'); var PulsePointAdapter = function PulsePointAdapter() { - var getJsStaticUrl = window.location.protocol + '//tag.contextweb.com/getjs.static.js'; + var getJsStaticUrl = window.location.protocol + '//tag-st.contextweb.com/getjs.static.js'; var bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag'; function _callBids(params) { From 19bcd16153bbbb59eaf0106fd345f792cbd996d4 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Tue, 28 Feb 2017 11:39:10 -0500 Subject: [PATCH 11/13] Updating JS lib endpoint --- test/spec/adapters/pulsepoint_spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spec/adapters/pulsepoint_spec.js b/test/spec/adapters/pulsepoint_spec.js index 0e9fb97fa4c..b3c24d38890 100644 --- a/test/spec/adapters/pulsepoint_spec.js +++ b/test/spec/adapters/pulsepoint_spec.js @@ -127,7 +127,7 @@ describe("PulsePoint Adapter Tests", () => { pulsepointAdapter.callBids(slotConfigs); let libraryLoadCall = adLoader.loadScript.firstCall.args[0]; let callback = adLoader.loadScript.firstCall.args[1]; - expect(libraryLoadCall).to.equal('http://tag.contextweb.com/getjs.static.js'); + expect(libraryLoadCall).to.equal('http://tag-st.contextweb.com/getjs.static.js'); expect(callback).to.be.a('function'); }); From bae2c3d9a05d04d2e71c801c7416298c95735440 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Tue, 14 Mar 2017 07:38:55 -0400 Subject: [PATCH 12/13] addressing review comments --- src/adapters/pulsepointLite.js | 41 ++++++++++++----------- test/spec/adapters/pulsepointLite_spec.js | 22 +++++++++--- 2 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js index 463f0d44132..4982211f3be 100644 --- a/src/adapters/pulsepointLite.js +++ b/src/adapters/pulsepointLite.js @@ -1,13 +1,13 @@ import {createBid} from 'src/bidfactory'; import {addBidResponse} from 'src/bidmanager'; -import {logError} from 'src/utils'; +import {logError,getTopWindowLocation} from 'src/utils'; import {ajax} from 'src/ajax'; import {STATUS} from 'src/constants'; function PulsePointLiteAdapter() { - var bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag?'; - var ajaxOptions = { + const bidUrl = window.location.protocol + '//bid.contextweb.com/header/tag?'; + const ajaxOptions = { method: 'GET', withCredentials: true, contentType: 'text/plain' @@ -30,14 +30,13 @@ function PulsePointLiteAdapter() { } function environment() { - var pg = pageUrl(); return { cn: 1, ca: 'BID', tl: 1, 'if': 0, - cwu: pg.pg, - cwr: pg.ref, + cwu: getTopWindowLocation().href, + cwr: referrer(), dw: document.documentElement.clientWidth, cxy: document.documentElement.clientWidth + ',' + document.documentElement.clientHeight, tz: new Date().getTimezoneOffset(), @@ -45,24 +44,17 @@ function PulsePointLiteAdapter() { }; } - function pageUrl() { - try { - return { - pg: window.top.location.href, - ref: window.top.document.referrer - }; - } - catch (e) { - return { - pg: location.href, - ref: document.referrer - }; + function referrer() { + try { + return window.top.document.referrer; + } catch (e) { + return document.referrer; } } function bidResponseAvailable(bidRequest, rawResponse) { if (rawResponse) { - var bidResponse = JSON.parse(rawResponse); + var bidResponse = parse(rawResponse); if(bidResponse) { var adSize = bidRequest.params.cf.toUpperCase().split('X'); var bid = createBid(STATUS.GOOD, bidRequest); @@ -80,10 +72,19 @@ function PulsePointLiteAdapter() { addBidResponse(bidRequest.placementCode, passback); } + function parse(rawResponse) { + try { + return JSON.parse(rawResponse) + } catch (ex) { + logError('pulsepoint.safeParse', 'ERROR', ex); + return null; + } + } + return { callBids: _callBids }; } -module.exports = PulsePointLiteAdapter; \ No newline at end of file +module.exports = PulsePointLiteAdapter; diff --git a/test/spec/adapters/pulsepointLite_spec.js b/test/spec/adapters/pulsepointLite_spec.js index 116cdb859a7..c52ef556880 100644 --- a/test/spec/adapters/pulsepointLite_spec.js +++ b/test/spec/adapters/pulsepointLite_spec.js @@ -9,15 +9,15 @@ describe("PulsePoint Lite Adapter Tests", () => { let pulsepointAdapter = new PulsePointAdapter(); let slotConfigs; let ajaxStub; - + beforeEach(() => { sinon.stub(bidManager, 'addBidResponse'); ajaxStub = sinon.stub(ajax, 'ajax'); - + slotConfigs = { bids: [ { - placementCode: "/DfpAccount1/slot1", + placementCode: "/DfpAccount1/slot1", bidder: "pulsepoint", bidId: 'bid12345', params: { @@ -26,7 +26,7 @@ describe("PulsePoint Lite Adapter Tests", () => { cf: "300x250" } },{ - placementCode: "/DfpAccount2/slot2", + placementCode: "/DfpAccount2/slot2", bidder: "pulsepoint", bidId: 'bid23456', params: { @@ -92,5 +92,17 @@ describe("PulsePoint Lite Adapter Tests", () => { expect(bid).to.not.have.property('cpm'); expect(bid.adId).to.equal('bid12345'); }); - + + it('Verify passback when ajax call fails', () => { + ajaxStub.throws(); + pulsepointAdapter.callBids(slotConfigs); + let placement = bidManager.addBidResponse.firstCall.args[0]; + let bid = bidManager.addBidResponse.firstCall.args[1]; + expect(placement).to.equal('/DfpAccount1/slot1'); + expect(bid.bidderCode).to.equal('pulsepoint'); + expect(bid).to.not.have.property('ad'); + expect(bid).to.not.have.property('cpm'); + expect(bid.adId).to.equal('bid12345'); + }); + }); From 40c37e86fd5951472b1ef0aea255143d5b68f6e1 Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Tue, 14 Mar 2017 07:54:27 -0400 Subject: [PATCH 13/13] fixing jshint error --- src/adapters/pulsepointLite.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/adapters/pulsepointLite.js b/src/adapters/pulsepointLite.js index 4982211f3be..49900bc2c08 100644 --- a/src/adapters/pulsepointLite.js +++ b/src/adapters/pulsepointLite.js @@ -74,7 +74,7 @@ function PulsePointLiteAdapter() { function parse(rawResponse) { try { - return JSON.parse(rawResponse) + return JSON.parse(rawResponse); } catch (ex) { logError('pulsepoint.safeParse', 'ERROR', ex); return null;