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 #4385

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
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
134 changes: 70 additions & 64 deletions modules/sovrnBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as utils from '../src/utils'
import {parse} from '../src/url'
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 +23,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 +58,29 @@ export const spec = {
bidfloor: utils.getBidIdParameter('bidfloor', bid.params)
});
});

const page = bidderRequest.refererInfo.referer

// clever trick to get the domain
const domain = parse(page).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: 'https://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'))
.reduce((acc, resp) => acc.concat(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