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

RichAudience: Support userIDs + Prebid 3.0 #4504

Merged
merged 8 commits into from
Dec 10, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
112 changes: 74 additions & 38 deletions modules/richaudienceBidAdapter.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {BANNER, VIDEO} from '../src/mediaTypes';
import * as utils from '../src/utils';

const BIDDER_CODE = 'richaudience';
let REFERER = '';

export const spec = {
code: BIDDER_CODE,
Expand Down Expand Up @@ -39,22 +40,22 @@ export const spec = {
bidder: bid.bidder,
bidderRequestId: bid.bidderRequestId,
tagId: bid.adUnitCode,
sizes: bid.sizes.map(size => ({
w: size[0],
h: size[1],
})),
sizes: raiGetSizes(bid),
referer: (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null),
numIframes: (typeof bidderRequest.refererInfo.numIframes != 'undefined' ? bidderRequest.refererInfo.numIframes : null),
transactionId: bid.transactionId,
timeout: config.getConfig('bidderTimeout'),
user: raiSetEids(bid)
};

REFERER = (typeof bidderRequest.refererInfo.referer != 'undefined' ? encodeURIComponent(bidderRequest.refererInfo.referer) : null)

payload.gdpr_consent = '';
payload.gdpr = null;

if (bidderRequest && bidderRequest.gdprConsent) {
payload.gdpr_consent = bidderRequest.gdprConsent.consentString;
payload.gdpr = bidderRequest.gdprConsent.gdprApplies; // we're handling the undefined case server side
} else {
payload.gdpr_consent = '';
payload.gdpr = null;
payload.gdpr = bidderRequest.gdprConsent.gdprApplies;
}

var payloadString = JSON.stringify(payload);
Expand All @@ -76,34 +77,29 @@ export const spec = {
*/
interpretResponse: function (serverResponse, bidRequest) {
const bidResponses = [];

// try catch
var response = serverResponse.body;
if (response) {
var bidResponse = {
requestId: JSON.parse(bidRequest.data).bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creative_id,
mediaType: response.media_type,
netRevenue: response.netRevenue,
currency: response.currency,
ttl: response.ttl,
dealId: response.dealId,
};

try {
if (response) {
var bidResponse = {
requestId: JSON.parse(bidRequest.data).bidId,
cpm: response.cpm,
width: response.width,
height: response.height,
creativeId: response.creative_id,
mediaType: response.media_type,
netRevenue: response.netRevenue,
currency: response.currency,
ttl: response.ttl,
dealId: response.dealId,
};

if (response.media_type === 'video') {
bidResponse.vastXml = response.vastXML;
} else {
bidResponse.ad = response.adm
}

bidResponses.push(bidResponse);
if (response.media_type === 'video') {
bidResponse.vastXml = response.vastXML;
} else {
bidResponse.ad = response.adm
}
} catch (error) {
utils.logError('Error while parsing Rich Audience response', error);

bidResponses.push(bidResponse);
}
return bidResponses
},
Expand All @@ -121,20 +117,60 @@ export const spec = {
var rand = Math.floor(Math.random() * 9999999999);
var syncUrl = '';

if (gdprConsent && typeof gdprConsent.consentString === 'string') {
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString;
} else {
syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand;
}
gdprConsent && typeof gdprConsent.consentString === 'string' ? syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand + '&pubconsent=' + gdprConsent.consentString + '&euconsent=' + gdprConsent.consentString : syncUrl = 'https://sync.richaudience.com/dcf3528a0b8aa83634892d50e91c306e/?ord=' + rand;

if (syncOptions.iframeEnabled) {
syncs.push({
type: 'iframe',
url: syncUrl
});
} else if (syncOptions.pixelEnabled && REFERER != null) {
syncs.push({
type: 'image',
url: `https://sync.richaudience.com/bf7c142f4339da0278e83698a02b0854/?euconsent=${gdprConsent.consentString}&referrer=${REFERER}`
});
}
return syncs
},
};

registerBidder(spec);

function raiGetSizes(bid) {
let raiNewSizes;
if (bid.mediaTypes && bid.mediaTypes.banner && bid.mediaTypes.banner.sizes) {
raiNewSizes = bid.mediaTypes.banner.sizes
} else {
raiNewSizes = bid.sizes
}
if (raiNewSizes != null) {
return raiNewSizes.map(size => ({
w: size[0],
h: size[1]
}));
}
}

function raiSetEids(bid) {
let eids = [];

if (bid && bid.userId) {
raiSetUserId(bid, eids, 'id5-sync.com', utils.deepAccess(bid, `userId.id5id`));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in this method call, you're passing in 4 arguments (bid, eids, source, and value), however the method definition on line 161 also has a 5th argument for userId. I'm guessing the definition doesn't need the last argument, but wanted to point it out so you can fix.

raiSetUserId(bid, eids, 'pubcommon', utils.deepAccess(bid, `userId.pubcid`));
raiSetUserId(bid, eids, 'criteo.com', utils.deepAccess(bid, `userId.criteoId`));
raiSetUserId(bid, eids, 'liveramp.com', utils.deepAccess(bid, `userId.idl_env`));
raiSetUserId(bid, eids, 'liveintent.com', utils.deepAccess(bid, `userId.lipb.lipbid`));
raiSetUserId(bid, eids, 'adserver.org', utils.deepAccess(bid, `userId.tdid`));
}

return eids;
}

function raiSetUserId(bid, eids, source, value) {
if (utils.isStr(value)) {
eids.push({
userId: value,
source: source
});
}
}
Loading