Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PulsePoint Lite adapter #1016

Merged
merged 19 commits into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
2fba6a2
ET-1691: Pulsepoint Analytics adapter for Prebid. (#1)
anand-venkatraman Oct 14, 2016
ca17acb
Merge remote-tracking branch 'upstream/master'
anand-venkatraman Oct 25, 2016
5da43c3
Adding bidRequest to bidFactory.createBid method as per https://githu…
anand-venkatraman Oct 25, 2016
cf41114
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Nov 8, 2016
62756a9
ET-1765: Adding support for additional params in PulsePoint adapter (#2)
anand-venkatraman Nov 9, 2016
f8fabb7
Merge branch 'master' of https://github.com/prebid/Prebid.js
anand-venkatraman Dec 8, 2016
b9af15c
ET-1850: Fixing https://github.com/prebid/Prebid.js/issues/866
anand-venkatraman Dec 8, 2016
6523c25
Merge pull request #3 from pulsepointinc/ET-1850
anand-venkatraman Dec 8, 2016
45dfc76
ET-1850: Adding a "lite" adapter.
anand-venkatraman Dec 8, 2016
b5eeb7f
Minor fix
anand-venkatraman Dec 8, 2016
704334a
Merge branch 'master' of https://github.com/pulsepointinc/Prebid.js i…
anand-venkatraman Dec 8, 2016
40ed464
Fix for response parsing
anand-venkatraman Dec 9, 2016
ece11ae
Minor changes
anand-venkatraman Dec 12, 2016
c1efbe1
Minor changes
anand-venkatraman Dec 12, 2016
ccdf6c2
Updating JS lib endpoint
anand-venkatraman Feb 28, 2017
4b1a30a
Merge branch 'master' of https://github.com/prebid/Prebid.js into ET-…
anand-venkatraman Feb 28, 2017
19bcd16
Updating JS lib endpoint
anand-venkatraman Feb 28, 2017
bae2c3d
addressing review comments
anand-venkatraman Mar 14, 2017
40c37e8
fixing jshint error
anand-venkatraman Mar 14, 2017
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions adapters.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
"piximedia",
"pubmatic",
"pulsepoint",
"pulsepointLite",
"rhythmone",
"rubicon",
"smartyads",
Expand Down
2 changes: 1 addition & 1 deletion src/adapters/pulsepoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
89 changes: 89 additions & 0 deletions src/adapters/pulsepointLite.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
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?';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using const/let is recommended.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated.

var ajaxOptions = {
method: 'GET',
withCredentials: true,
contentType: 'text/plain'
};

function _callBids(bidderRequest) {
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);
}
});
}

function environment() {
var pg = pageUrl();
return {
cn: 1,
ca: 'BID',
tl: 1,
'if': 0,
cwu: pg.pg,
cwr: pg.ref,
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 pageUrl() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend using these function utils.getTopWindowUrl() and utils.getTopWindowLocation()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

try {
return {
pg: window.top.location.href,
ref: window.top.document.referrer
};
}
catch (e) {
return {
pg: location.href,
ref: document.referrer
};
}
}

function bidResponseAvailable(bidRequest, rawResponse) {
if (rawResponse) {
var bidResponse = JSON.parse(rawResponse);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrap this in try catch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wrapped in try/catch

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 {
callBids: _callBids
};

}

module.exports = PulsePointLiteAdapter;
96 changes: 96 additions & 0 deletions test/spec/adapters/pulsepointLite_spec.js
Original file line number Diff line number Diff line change
@@ -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 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",
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 = 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');
//slot 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');
});

it('Verify bid', () => {
pulsepointAdapter.callBids(slotConfigs);
//trigger a mock ajax callback with bid.
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');
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');
});

});
2 changes: 1 addition & 1 deletion test/spec/adapters/pulsepoint_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});

Expand Down