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

Sovrn adapter updates: schain, digitrust, pixel syncing, and 3.0 upgrades #4335

Merged
merged 10 commits into from
Oct 23, 2019
136 changes: 72 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,16 @@ export const spec = {
}};
}

let url = `//ap.lijit.com/rtb/bid?` +
if (digitrust) {
sovrnBidReq.user = sovrnBidReq.user || {};
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
sovrnBidReq.user.ext = sovrnBidReq.user.ext || {}
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 +112,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 +148,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 => resp.body && resp.body.ext && resp.body.ext.iid)
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
.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 => resp.body && resp.body.ext && resp.body.ext.sync && resp.body.ext.sync.pixels)
msm0504 marked this conversation as resolved.
Show resolved Hide resolved
.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