Skip to content

Commit

Permalink
Sovrn adapter updates: schain, digitrust, pixel syncing, and 3.0 upgr…
Browse files Browse the repository at this point in the history
…ades (prebid#4335)

* schain and digitrust

* pixel beacons

* unit tests and fixes from testing

* Prebid 3.0 updates

* review fix
  • Loading branch information
aprakash-sovrn authored and msm0504 committed Oct 23, 2019
1 parent 02f6cbc commit 6114a3d
Show file tree
Hide file tree
Showing 2 changed files with 248 additions and 172 deletions.
134 changes: 70 additions & 64 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import * as utils from '../src/utils'
import { registerBidder } from '../src/adapters/bidderFactory'
import { BANNER } from '../src/mediaTypes'
const errorUrl = 'https://pcb.aws.lijit.com/c'
let errorpxls = []

export const spec = {
code: 'sovrn',
Expand All @@ -24,14 +22,30 @@ export const spec = {
*/
buildRequests: function(bidReqs, bidderRequest) {
try {
const loc = utils.getTopWindowLocation();
let sovrnImps = [];
let iv;
let schain;
let digitrust;

utils._each(bidReqs, function (bid) {
if (!digitrust) {
const bidRequestDigitrust = utils.deepAccess(bid, 'userId.digitrustid.data');
if (bidRequestDigitrust && (!bidRequestDigitrust.privacy || !bidRequestDigitrust.privacy.optout)) {
digitrust = {
id: bidRequestDigitrust.id,
keyv: bidRequestDigitrust.keyv
}
}
}
if (bid.schain) {
schain = schain || bid.schain;
}
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)}))

let bidSizes = (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) || bid.sizes;
bidSizes = ((utils.isArray(bidSizes) && utils.isArray(bidSizes[0])) ? bidSizes : [bidSizes])
bidSizes = bidSizes.filter(size => utils.isArray(size))
const processedSizes = bidSizes.map(size => ({w: parseInt(size[0], 10), h: parseInt(size[1], 10)}))
sovrnImps.push({
id: bid.bidId,
banner: {
Expand All @@ -43,15 +57,30 @@ export const spec = {
bidfloor: utils.getBidIdParameter('bidfloor', bid.params)
});
});

const page = bidderRequest.refererInfo.referer
// clever trick to get the domain
const el = document.createElement('a');
el.href = page;
const domain = el.hostname;

const sovrnBidReq = {
id: utils.getUniqueIdentifierStr(),
imp: sovrnImps,
site: {
domain: loc.host,
page: loc.host + loc.pathname + loc.search + loc.hash
page,
domain
}
};

if (schain) {
sovrnBidReq.source = {
ext: {
schain
}
};
}

if (bidderRequest && bidderRequest.gdprConsent) {
sovrnBidReq.regs = {
ext: {
Expand All @@ -63,7 +92,14 @@ export const spec = {
}};
}

let url = `//ap.lijit.com/rtb/bid?` +
if (digitrust) {
utils.deepSetValue(sovrnBidReq, 'user.ext.digitrust', {
id: digitrust.id,
keyv: digitrust.keyv
})
}

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

Expand All @@ -74,7 +110,8 @@ export const spec = {
options: {contentType: 'text/plain'}
}
} catch (e) {
new LogError(e, {bidReqs, bidderRequest}).append()
console.log('error in build:')
console.log(e)
}
},

Expand Down Expand Up @@ -109,74 +146,43 @@ export const spec = {
}
return sovrnBidResponses
} catch (e) {
new LogError(e, {id, seatbid}).append()
console.log('error in interpret:')
console.log(e)
}
},

getUserSyncs: function(syncOptions, serverResponses, gdprConsent) {
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 (serverResponses && serverResponses.length !== 0) {
if (syncOptions.iframeEnabled) {
let iidArr = serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.iid'))
.map(resp => resp.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 (iidArr[0]) {
tracks.push({
type: 'iframe',
url: '//ap.lijit.com/beacon?informer=' + iidArr[0] + '&gdpr_consent=' + consentString,
});

if (syncOptions.pixelEnabled) {
serverResponses.filter(resp => utils.deepAccess(resp, 'body.ext.sync.pixels'))
.flatMap(resp => resp.body.ext.sync.pixels)
.map(pixel => pixel.url)
.forEach(url => tracks.push({ type: 'image', url }))
}
}
if (errorpxls.length && syncOptions.pixelEnabled) {
tracks = tracks.concat(errorpxls)
}

return tracks
} catch (e) {
if (syncOptions.pixelEnabled) {
return errorpxls
}
return []
}
},
}

export 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)
}
static getErrPxls() {
return errorpxls
}
}

registerBidder(spec);
Loading

0 comments on commit 6114a3d

Please sign in to comment.