Skip to content

Commit

Permalink
Sonobi Adapter - Added referrer param. Fixed timeout error in userSync (
Browse files Browse the repository at this point in the history
  • Loading branch information
JonGoSonobi authored and kitwestneat committed May 15, 2018
1 parent 193ce63 commit d6788db
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
27 changes: 17 additions & 10 deletions modules/sonobiBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export const spec = {
const bids = validBidRequests.map(bid => {
let slotIdentifier = _validateSlot(bid);
if (/^[\/]?[\d]+[[\/].+[\/]?]?$/.test(slotIdentifier)) {
slotIdentifier = slotIdentifier.charAt(0) === '/' ? slotIdentifier : '/' + slotIdentifier
slotIdentifier = slotIdentifier.charAt(0) === '/' ? slotIdentifier : '/' + slotIdentifier;
return {
[`${slotIdentifier}|${bid.bidId}`]: `${_validateSize(bid)}${_validateFloor(bid)}`
}
Expand All @@ -41,7 +41,7 @@ export const spec = {
}
});

let data = {}
let data = {};
bids.forEach((bid) => { Object.assign(data, bid); });

const payload = {
Expand All @@ -57,6 +57,9 @@ export const spec = {
if (validBidRequests[0].params.hfa) {
payload.hfa = validBidRequests[0].params.hfa;
}
if (validBidRequests[0].params.referrer) {
payload.ref = validBidRequests[0].params.referrer;
}

// If there is no key_maker data, then dont make the request.
if (isEmpty(data)) {
Expand Down Expand Up @@ -132,17 +135,21 @@ export const spec = {
*/
getUserSyncs: (syncOptions, serverResponses) => {
const syncs = [];
if (syncOptions.pixelEnabled && serverResponses[0].body.sbi_px) {
serverResponses[0].body.sbi_px.forEach(pixel => {
syncs.push({
type: pixel.type,
url: pixel.url
try {
if (syncOptions.pixelEnabled) {
serverResponses[0].body.sbi_px.forEach(pixel => {
syncs.push({
type: pixel.type,
url: pixel.url
});
});
});
}
} catch (e) {
logError(e)
}
return syncs;
}
}
};

function _validateSize (bid) {
if (bid.params.sizes) {
Expand Down Expand Up @@ -171,7 +178,7 @@ const _creative = (mediaType) => (sbi_dc, sbi_aid) => {
}
const src = 'https://' + sbi_dc + 'apex.go.sonobi.com/sbi.js?aid=' + sbi_aid + '&as=null' + '&ref=' + getTopWindowLocation().host;
return '<script type="text/javascript" src="' + src + '"></script>';
}
};

function _videoCreative(sbi_dc, sbi_aid) {
return `https://${sbi_dc}apex.go.sonobi.com/vast.xml?vid=${sbi_aid}&ref=${getTopWindowLocation().host}`
Expand Down
6 changes: 6 additions & 0 deletions test/spec/modules/sonobiBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ describe('SonobiBidAdapter', () => {
'placement_id': '1a2b3c4d5e6f1a2b3c4d',
'sizes': [[300, 250], [300, 600]],
'floor': '1.25',
'referrer': 'overrides_top_window_location'
},
'adUnitCode': 'adunit-code-1',
'sizes': [[300, 250], [300, 600]],
Expand All @@ -117,6 +118,7 @@ describe('SonobiBidAdapter', () => {
'params': {
'ad_unit': '/7780971/sparks_prebid_LB',
'sizes': [[300, 250], [300, 600]],
'referrer': 'overrides_top_window_location'
},
'adUnitCode': 'adunit-code-2',
'sizes': [[120, 600], [300, 600], [160, 600]],
Expand All @@ -139,6 +141,7 @@ describe('SonobiBidAdapter', () => {
expect(bidRequests.data.pv).to.equal(bidRequestsPageViewID.data.pv)
expect(bidRequests.data.hfa).to.not.exist
expect(bidRequests.bidderRequests).to.eql(bidRequest);
expect(bidRequests.data.ref).to.equal('overrides_top_window_location');
expect(['mobile', 'tablet', 'desktop']).to.contain(bidRequests.data.vp);
})

Expand Down Expand Up @@ -281,6 +284,9 @@ describe('SonobiBidAdapter', () => {
url: 'https://pixel-test'
}]);
})
it('should return an empty array when sync is enabled but there are no bidResponses', () => {
expect(spec.getUserSyncs({ pixelEnabled: true }, [])).to.have.length(0);
})

it('should return an empty array when sync is enabled but no sync pixel returned', () => {
const pixel = Object.assign({}, bidResponse);
Expand Down

0 comments on commit d6788db

Please sign in to comment.