-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
PulsePoint Lite adapter #1016
Changes from 17 commits
2fba6a2
ca17acb
5da43c3
cf41114
62756a9
f8fabb7
b9af15c
6523c25
45dfc76
b5eeb7f
704334a
40ed464
ece11ae
c1efbe1
ccdf6c2
4b1a30a
19bcd16
bae2c3d
40c37e8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
"piximedia", | ||
"pubmatic", | ||
"pulsepoint", | ||
"pulsepointLite", | ||
"rhythmone", | ||
"rubicon", | ||
"smartyads", | ||
|
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?'; | ||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would recommend using these function utils.getTopWindowUrl() and utils.getTopWindowLocation() There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrap this in try catch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wrapped in |
||
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; |
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'); | ||
}); | ||
|
||
}); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated.