Skip to content

Commit

Permalink
Pulsepoint Analytics adapter for Prebid (prebid#706)
Browse files Browse the repository at this point in the history
* 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

* Adding bidRequest to bidFactory.createBid method as per prebid#509
  • Loading branch information
anand-venkatraman authored and jaiminpanchal27 committed Oct 25, 2016
1 parent 504059e commit e17518b
Show file tree
Hide file tree
Showing 3 changed files with 161 additions and 2 deletions.
12 changes: 12 additions & 0 deletions src/adapters/analytics/pulsepoint.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* pulsepoint.js - Analytics Adapter for PulsePoint
*/

import adapter from 'AnalyticsAdapter';

export default adapter({
global: 'PulsePointPrebidAnalytics',
handler: 'on',
analyticsType: 'bundle'
});

4 changes: 2 additions & 2 deletions src/adapters/pulsepoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ 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;
bid.width = adSize[0];
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);
}
Expand Down
147 changes: 147 additions & 0 deletions test/spec/adapters/pulsepoint_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
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",
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();
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');
expect(bid.adId).to.equal('bid12345');
});

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');
expect(bid.adId).to.equal('bid12345');
});

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');
});

});

0 comments on commit e17518b

Please sign in to comment.