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

Updated Sovrn Bid Adaptor for MultiSized and added Error Call Home. #3237

Merged
merged 6 commits into from
Nov 15, 2018
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
213 changes: 137 additions & 76 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import * as utils from 'src/utils';
import { registerBidder } from 'src/adapters/bidderFactory';
import { BANNER } from 'src/mediaTypes';
import { REPO_AND_VERSION } from 'src/constants';
import * as utils from 'src/utils'
import { registerBidder } from 'src/adapters/bidderFactory'
import { BANNER } from 'src/mediaTypes'
import { REPO_AND_VERSION } from 'src/constants'
const errorUrl = 'https://pcb.aws.lijit.com/c'
let errorpxls = []

export const spec = {
code: 'sovrn',
Expand All @@ -22,48 +24,59 @@ export const spec = {
* @return object of parameters for Prebid AJAX request
*/
buildRequests: function(bidReqs, bidderRequest) {
const loc = utils.getTopWindowLocation();
let sovrnImps = [];
let iv;
utils._each(bidReqs, function (bid) {
iv = iv || utils.getBidIdParameter('iv', bid.params);
sovrnImps.push({
id: bid.bidId,
banner: { w: 1, h: 1 },
tagid: String(utils.getBidIdParameter('tagid', bid.params)),
bidfloor: utils.getBidIdParameter('bidfloor', bid.params)
try {
const loc = utils.getTopWindowLocation();
let sovrnImps = [];
let iv;
utils._each(bidReqs, function (bid) {
iv = iv || utils.getBidIdParameter('iv', bid.params);
bid.sizes = ((utils.isArray(bid.sizes) && utils.isArray(bid.sizes[0])) ? bid.sizes : [bid.sizes])
bid.sizes = bid.sizes.filter(size => utils.isArray(size))
const processedSizes = bid.sizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))
sovrnImps.push({
id: bid.bidId,
banner: {
format: processedSizes,
w: 1,
h: 1,
},
tagid: String(utils.getBidIdParameter('tagid', bid.params)),
bidfloor: utils.getBidIdParameter('bidfloor', bid.params)
});
});
});
const sovrnBidReq = {
id: utils.getUniqueIdentifierStr(),
imp: sovrnImps,
site: {
domain: loc.host,
page: loc.host + loc.pathname + loc.search + loc.hash
}
};
const sovrnBidReq = {
id: utils.getUniqueIdentifierStr(),
imp: sovrnImps,
site: {
domain: loc.host,
page: loc.host + loc.pathname + loc.search + loc.hash
}
};

if (bidderRequest && bidderRequest.gdprConsent) {
sovrnBidReq.regs = {
ext: {
gdpr: +bidderRequest.gdprConsent.gdprApplies
}};
sovrnBidReq.user = {
ext: {
consent: bidderRequest.gdprConsent.consentString
}};
}
if (bidderRequest && bidderRequest.gdprConsent) {
sovrnBidReq.regs = {
ext: {
gdpr: +bidderRequest.gdprConsent.gdprApplies
}};
sovrnBidReq.user = {
ext: {
consent: bidderRequest.gdprConsent.consentString
}};
}

let url = `//ap.lijit.com/rtb/bid?` +
`src=${REPO_AND_VERSION}`;
if (iv) url += `&iv=${iv}`;
let url = `//ap.lijit.com/rtb/bid?` +
`src=${REPO_AND_VERSION}`;
if (iv) url += `&iv=${iv}`;

return {
method: 'POST',
url: url,
data: JSON.stringify(sovrnBidReq),
options: {contentType: 'text/plain'}
};
return {
method: 'POST',
url: url,
data: JSON.stringify(sovrnBidReq),
options: {contentType: 'text/plain'}
}
} catch (e) {
new LogError(e, {bidReqs, bidderRequest}).append()
}
},

/**
Expand All @@ -72,48 +85,96 @@ export const spec = {
* @return {Bid[]} An array of formatted bids.
*/
interpretResponse: function({ body: {id, seatbid} }) {
let sovrnBidResponses = [];
if (id &&
seatbid &&
seatbid.length > 0 &&
seatbid[0].bid &&
seatbid[0].bid.length > 0) {
seatbid[0].bid.map(sovrnBid => {
sovrnBidResponses.push({
requestId: sovrnBid.impid,
cpm: parseFloat(sovrnBid.price),
width: parseInt(sovrnBid.w),
height: parseInt(sovrnBid.h),
creativeId: sovrnBid.crid || sovrnBid.id,
dealId: sovrnBid.dealid || null,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: decodeURIComponent(`${sovrnBid.adm}<img src="${sovrnBid.nurl}">`),
ttl: 60
try {
let sovrnBidResponses = [];
if (id &&
seatbid &&
seatbid.length > 0 &&
seatbid[0].bid &&
seatbid[0].bid.length > 0) {
seatbid[0].bid.map(sovrnBid => {
sovrnBidResponses.push({
requestId: sovrnBid.impid,
cpm: parseFloat(sovrnBid.price),
width: parseInt(sovrnBid.w),
height: parseInt(sovrnBid.h),
creativeId: sovrnBid.crid || sovrnBid.id,
dealId: sovrnBid.dealid || null,
currency: 'USD',
netRevenue: true,
mediaType: BANNER,
ad: decodeURIComponent(`${sovrnBid.adm}<img src="${sovrnBid.nurl}">`),
ttl: 60
});
});
});
}
return sovrnBidResponses
} catch (e) {
new LogError(e, {id, seatbid}).append()
}
return sovrnBidResponses;
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
if (serverResponses && serverResponses.length !== 0 && syncOptions.iframeEnabled) {
let iidArr = serverResponses.filter(rsp => rsp.body && rsp.body.ext && rsp.body.ext.iid)
.map(rsp => { return rsp.body.ext.iid });
let consentString = '';
if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') {
consentString = gdprConsent.consentString
try {
let tracks = []
if (serverResponses && serverResponses.length !== 0 && syncOptions.iframeEnabled) {
let iidArr = serverResponses.filter(rsp => rsp.body && rsp.body.ext && rsp.body.ext.iid)
.map(rsp => { return rsp.body.ext.iid });
let consentString = '';
if (gdprConsent && gdprConsent.gdprApplies && typeof gdprConsent.consentString === 'string') {
consentString = gdprConsent.consentString
}
if (iidArr[0]) {
tracks.push({
type: 'iframe',
url: '//ap.lijit.com/beacon?informer=' + iidArr[0] + '&gdpr_consent=' + consentString,
});
}
}
if (errorpxls.length && syncOptions.pixelEnabled) {
tracks = tracks.concat(errorpxls)
}
if (iidArr[0]) {
return [{
type: 'iframe',
url: '//ap.lijit.com/beacon?informer=' + iidArr[0] + '&gdpr_consent=' + consentString,
}];
return tracks
} catch (e) {
if (syncOptions.pixelEnabled) {
return errorpxls
}
return []
}
return [];
},
};
}

class LogError {
constructor(e, data) {
utils.logError(e)
this.error = {}
this.error.t = utils.timestamp()
this.error.m = e.message
this.error.s = e.stack
this.error.d = data
this.error.v = REPO_AND_VERSION
this.error.u = utils.getTopWindowLocation().href
this.error.ua = navigator.userAgent
}
buildErrorString(obj) {
return errorUrl + '?b=' + btoa(JSON.stringify(obj))
}
append() {
let errstr = this.buildErrorString(this.error)
if (errstr.length > 2083) {
delete this.error.d
errstr = this.buildErrorString(this.error)
if (errstr.length > 2083) {
delete this.error.s
errstr = this.buildErrorString(this.error)
if (errstr.length > 2083) {
errstr = this.buildErrorString({m: 'unknown error message', t: this.error.t, u: this.error.u})
}
}
}
let obj = {type: 'image', url: errstr}
errorpxls.push(obj)
}
}

registerBidder(spec);
39 changes: 35 additions & 4 deletions test/spec/modules/sovrnBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ describe('sovrnBidAdapter', function() {
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
[300, 250],
[300, 600]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
Expand Down Expand Up @@ -47,7 +48,8 @@ describe('sovrnBidAdapter', function() {
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
[300, 250],
[300, 600]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
Expand All @@ -64,6 +66,33 @@ describe('sovrnBidAdapter', function() {
expect(request.url).to.equal(ENDPOINT)
});

it('sets the proper banner object', function() {
const payload = JSON.parse(request.data);
expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}, {w: 300, h: 600}])
expect(payload.imp[0].banner.w).to.equal(1)
expect(payload.imp[0].banner.h).to.equal(1)
})

it('accepts a single array as a size', function() {
const singleSize = [{
'bidder': 'sovrn',
'params': {
'tagid': '403370',
'iv': 'vet'
},
'adUnitCode': 'adunit-code',
'sizes': [300, 250],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
'auctionId': '1d1a030790a475'
}];
const request = spec.buildRequests(singleSize)
const payload = JSON.parse(request.data)
expect(payload.imp[0].banner.format).to.deep.equal([{w: 300, h: 250}])
expect(payload.imp[0].banner.w).to.equal(1)
expect(payload.imp[0].banner.h).to.equal(1)
})

it('sends \'iv\' as query param if present', function () {
const ivBidRequests = [{
'bidder': 'sovrn',
Expand All @@ -73,7 +102,8 @@ describe('sovrnBidAdapter', function() {
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
[300, 250],
[300, 600]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
Expand Down Expand Up @@ -116,7 +146,8 @@ describe('sovrnBidAdapter', function() {
},
'adUnitCode': 'adunit-code',
'sizes': [
[300, 250]
[300, 250],
[300, 600]
],
'bidId': '30b31c1838de1e',
'bidderRequestId': '22edbae2733bf6',
Expand Down