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

PrebidServerBidAdapter CCPA (USP) Support #4501

Merged
merged 4 commits into from
Dec 4, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
52 changes: 36 additions & 16 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ export function resetSyncedStatus() {
/**
* @param {Array} bidderCodes list of bidders to request user syncs for.
*/
function queueSync(bidderCodes, gdprConsent) {
function queueSync(bidderCodes, gdprConsent, uspConsent) {
if (_synced) {
return;
}
Expand All @@ -147,6 +147,12 @@ function queueSync(bidderCodes, gdprConsent) {
payload.gdpr_consent = gdprConsent.consentString;
}
}

// US Privace (CCPA) support
if (uspConsent) {
payload.us_privacy = uspConsent;
}

const jsonPayload = JSON.stringify(payload);
ajax(_s2sConfig.syncEndpoint,
(response) => {
Expand Down Expand Up @@ -766,24 +772,33 @@ const OPEN_RTB_PROTOCOL = {
}
}

if (bidRequests && bidRequests[0].gdprConsent) {
// note - gdprApplies & consentString may be undefined in certain use-cases for consentManagement module
let gdprApplies;
if (typeof bidRequests[0].gdprConsent.gdprApplies === 'boolean') {
gdprApplies = bidRequests[0].gdprConsent.gdprApplies ? 1 : 0;
}
if (bidRequests) {
if (bidRequests[0].gdprConsent) {
// note - gdprApplies & consentString may be undefined in certain use-cases for consentManagement module
let gdprApplies;
if (typeof bidRequests[0].gdprConsent.gdprApplies === 'boolean') {
gdprApplies = bidRequests[0].gdprConsent.gdprApplies ? 1 : 0;
}

if (request.regs) {
if (request.regs.ext) {
request.regs.ext.gdpr = gdprApplies;
if (request.regs) {
idettman marked this conversation as resolved.
Show resolved Hide resolved
if (request.regs.ext) {
request.regs.ext.gdpr = gdprApplies;
} else {
request.regs.ext = { gdpr: gdprApplies };
}
} else {
request.regs.ext = { gdpr: gdprApplies };
request.regs = { ext: { gdpr: gdprApplies } };
}
} else {
request.regs = { ext: { gdpr: gdprApplies } };

utils.deepSetValue(request, 'user.ext.consent', bidRequests[0].gdprConsent.consentString);
}

utils.deepSetValue(request, 'user.ext.consent', bidRequests[0].gdprConsent.consentString);
// US Privacy (CCPA) support
if (bidRequests[0].us_privacy) {
request.regs = request.regs || {};
idettman marked this conversation as resolved.
Show resolved Hide resolved
request.regs.ext = request.regs.ext || {};
request.regs.ext.us_privacy = bidRequests[0].us_privacy;
}
}

if (getConfig('coppa') === true) {
Expand Down Expand Up @@ -984,12 +999,17 @@ export function PrebidServer() {
.filter(utils.uniques);

if (_s2sConfig && _s2sConfig.syncEndpoint) {
let consent = (Array.isArray(bidRequests) && bidRequests.length > 0) ? bidRequests[0].gdprConsent : undefined;
let gdprConsent, uspConsent;
if (Array.isArray(bidRequests) && bidRequests.length > 0) {
gdprConsent = bidRequests[0].gdprConsent;
uspConsent = bidRequests[0].us_privacy;
}

let syncBidders = _s2sConfig.bidders
.map(bidder => adapterManager.aliasRegistry[bidder] || bidder)
.filter((bidder, index, array) => (array.indexOf(bidder) === index));

queueSync(syncBidders, consent);
queueSync(syncBidders, gdprConsent, uspConsent);
}

const request = protocolAdapter().buildRequest(s2sBidRequest, bidRequests, validAdUnits);
Expand Down
103 changes: 103 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,109 @@ describe('S2S Adapter', function () {
});
});

describe('us_privacy (ccpa) consent data', function () {
afterEach(function () {
config.resetConfig();
$$PREBID_GLOBAL$$.requestBids.removeAll();
});

it('is added to ortb2 request when in bidRequest', function () {
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'
config.setConfig({ s2sConfig: ortb2Config });

let uspBidRequest = utils.deepClone(BID_REQUESTS);
uspBidRequest[0].us_privacy = '1NYN';

adapter.callBids(REQUEST, uspBidRequest, addBidResponse, done, ajax);
let requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.regs.ext.us_privacy).is.equal('1NYN');

config.resetConfig();
config.setConfig({ s2sConfig: CONFIG });

adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
requestBid = JSON.parse(requests[1].requestBody);

expect(requestBid.regs).to.not.exist;
});

it('is added to cookie_sync request when in bidRequest', function () {
let cookieSyncConfig = utils.deepClone(CONFIG);
cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync';
config.setConfig({ s2sConfig: cookieSyncConfig });

let uspBidRequest = utils.deepClone(BID_REQUESTS);
uspBidRequest[0].us_privacy = '1YNN';

adapter.callBids(REQUEST, uspBidRequest, addBidResponse, done, ajax);
let requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.us_privacy).is.equal('1YNN');
expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1);
expect(requestBid.account).is.equal('1');
});
});

describe('gdpr and us_privacy (ccpa) consent data', function () {
afterEach(function () {
config.resetConfig();
$$PREBID_GLOBAL$$.requestBids.removeAll();
});

it('is added to ortb2 request when in bidRequest', function () {
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction'
config.setConfig({ s2sConfig: ortb2Config });

let consentBidRequest = utils.deepClone(BID_REQUESTS);
consentBidRequest[0].us_privacy = '1NYN';
consentBidRequest[0].gdprConsent = {
consentString: 'abc123',
gdprApplies: true
};

adapter.callBids(REQUEST, consentBidRequest, addBidResponse, done, ajax);
let requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.regs.ext.us_privacy).is.equal('1NYN');
expect(requestBid.regs.ext.gdpr).is.equal(1);
expect(requestBid.user.ext.consent).is.equal('abc123');

config.resetConfig();
config.setConfig({ s2sConfig: CONFIG });

adapter.callBids(REQUEST, BID_REQUESTS, addBidResponse, done, ajax);
requestBid = JSON.parse(requests[1].requestBody);

expect(requestBid.regs).to.not.exist;
expect(requestBid.user).to.not.exist;
});

it('is added to cookie_sync request when in bidRequest', function () {
let cookieSyncConfig = utils.deepClone(CONFIG);
cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync';
config.setConfig({ s2sConfig: cookieSyncConfig });

let consentBidRequest = utils.deepClone(BID_REQUESTS);
consentBidRequest[0].us_privacy = '1YNN';
consentBidRequest[0].gdprConsent = {
consentString: 'abc123def',
gdprApplies: true
};

adapter.callBids(REQUEST, consentBidRequest, addBidResponse, done, ajax);
let requestBid = JSON.parse(requests[0].requestBody);

expect(requestBid.us_privacy).is.equal('1YNN');
expect(requestBid.gdpr).is.equal(1);
expect(requestBid.gdpr_consent).is.equal('abc123def');
expect(requestBid.bidders).to.contain('appnexus').and.to.have.lengthOf(1);
expect(requestBid.account).is.equal('1');
});
});

it('sets invalid cacheMarkup value to 0', function () {
const s2sConfig = Object.assign({}, CONFIG, {
cacheMarkup: 999
Expand Down