From 2fba6a29ce0f473e4b174c35afdd9b535d363699 Mon Sep 17 00:00:00 2001 From: anand-venkatraman Date: Fri, 14 Oct 2016 08:31:49 -0400 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 b5eeb7f618fbe62c81c4c3f80a293f7e12a9aaad Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Thu, 8 Dec 2016 17:34:55 -0500 Subject: [PATCH 5/6] 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 8a715064938208f202b0d363bddd18cdcd081bec Mon Sep 17 00:00:00 2001 From: avenkatraman Date: Mon, 17 Jul 2017 20:58:01 +0530 Subject: [PATCH 6/6] Adding createNew method on the adapter for aliasing --- modules/pulsepointLiteBidAdapter.js | 3 +++ test/spec/modules/pulsepointLiteBidAdapter_spec.js | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/modules/pulsepointLiteBidAdapter.js b/modules/pulsepointLiteBidAdapter.js index b9ce3aacb56..dd04c982e0f 100644 --- a/modules/pulsepointLiteBidAdapter.js +++ b/modules/pulsepointLiteBidAdapter.js @@ -285,6 +285,9 @@ function PulsePointLiteAdapter() { }; } +PulsePointLiteAdapter.createNew = function() { + return new PulsePointLiteAdapter(); +} /** * "pulseLite" will be the adapter name going forward. "pulsepointLite" to be * deprecated, but kept here for backwards compatibility. diff --git a/test/spec/modules/pulsepointLiteBidAdapter_spec.js b/test/spec/modules/pulsepointLiteBidAdapter_spec.js index 9532685a037..2a8b09245a2 100644 --- a/test/spec/modules/pulsepointLiteBidAdapter_spec.js +++ b/test/spec/modules/pulsepointLiteBidAdapter_spec.js @@ -226,4 +226,9 @@ describe('PulsePoint Lite Adapter Tests', () => { expect(bid.native.impressionTrackers[0]).to.equal('http://imp1.trackme.com/'); expect(bid.native.impressionTrackers[1]).to.equal('http://imp1.contextweb.com/'); }); + + it('Verify createNew', function () { + const adapter = PulsePointAdapter.createNew(); + expect(adapter).to.have.property('callBids'); + }); });