Skip to content

Commit

Permalink
Adds support for additional consent (#5600)
Browse files Browse the repository at this point in the history
* add addtlConsent consent to consent object

* add unit test for additional consent

* Update consentManagement.js

* Update index.js

* Update prebidServerBidAdapter_spec.js

* condense else if
  • Loading branch information
patmmccann authored Aug 17, 2020
1 parent 952e0fb commit 7696428
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion modules/consentManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ function cmpFailed(errMsg, hookConfig, extraArgs) {
}

/**
* Stores CMP data locally in module and then invokes gdprDataHandler.setConsentData() to make information available in adaptermanger.js for later in the auction
* Stores CMP data locally in module and then invokes gdprDataHandler.setConsentData() to make information available in adaptermanager.js for later in the auction
* @param {object} cmpConsentObject required; an object representing user's consent choices (can be undefined in certain use-cases for this function only)
*/
function storeConsentData(cmpConsentObject) {
Expand All @@ -387,6 +387,9 @@ function storeConsentData(cmpConsentObject) {
vendorData: (cmpConsentObject) || undefined,
gdprApplies: cmpConsentObject && typeof cmpConsentObject.gdprApplies === 'boolean' ? cmpConsentObject.gdprApplies : gdprScope
};
if (cmpConsentObject.addtlConsent && utils.isStr(cmpConsentObject.addtlConsent)) {
consentData.addtlConsent = cmpConsentObject.addtlConsent;
};
}
consentData.apiVersion = cmpVersion;
gdprDataHandler.setConsentData(consentData);
Expand Down
3 changes: 3 additions & 0 deletions modules/prebidServerBidAdapter/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,9 @@ const OPEN_RTB_PROTOCOL = {
}
utils.deepSetValue(request, 'regs.ext.gdpr', gdprApplies);
utils.deepSetValue(request, 'user.ext.consent', firstBidRequest.gdprConsent.consentString);
if (firstBidRequest.gdprConsent.addtlConsent && typeof firstBidRequest.gdprConsent.addtlConsent === 'string') {
utils.deepSetValue(request, 'user.ext.ConsentedProvidersSettings.consented_providers', firstBidRequest.gdprConsent.addtlConsent);
}
}

// US Privacy (CCPA) support
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/consentManagement_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,32 @@ describe('consentManagement', function () {
expect(consent.apiVersion).to.equal(2);
});

it('performs lookup check and stores consentData for a valid existing user with additional consent', function () {
let testConsentData = {
tcString: 'abc12345234',
addtlConsent: 'superduperstring',
gdprApplies: true,
purposeOneTreatment: false,
eventStatus: 'tcloaded'
};
cmpStub = sinon.stub(window, '__tcfapi').callsFake((...args) => {
args[2](testConsentData, true);
});

setConsentConfig(goodConfigWithAllowAuction);

requestBidsHook(() => {
didHookReturn = true;
}, {});
let consent = gdprDataHandler.getConsentData();
sinon.assert.notCalled(utils.logError);
expect(didHookReturn).to.be.true;
expect(consent.consentString).to.equal(testConsentData.tcString);
expect(consent.addtlConsent).to.equal(testConsentData.addtlConsent);
expect(consent.gdprApplies).to.be.true;
expect(consent.apiVersion).to.equal(2);
});

it('throws an error when processCmpData check fails + does not call requestBids callbcack even when allowAuction is true', function () {
let testConsentData = {};
let bidsBackHandlerReturn = false;
Expand Down
31 changes: 31 additions & 0 deletions test/spec/modules/prebidServerBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,37 @@ describe('S2S Adapter', function () {
expect(requestBid.user).to.not.exist;
});

it('adds additional consent information to ortb2 request depending on presence of module', function () {
let ortb2Config = utils.deepClone(CONFIG);
ortb2Config.endpoint = 'https://prebid.adnxs.com/pbs/v1/openrtb2/auction';

let consentConfig = { consentManagement: { cmpApi: 'iab' }, s2sConfig: ortb2Config };
config.setConfig(consentConfig);

let gdprBidRequest = utils.deepClone(BID_REQUESTS);
gdprBidRequest[0].gdprConsent = {
consentString: 'abc123',
addtlConsent: 'superduperconsent',
gdprApplies: true
};

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

expect(requestBid.regs.ext.gdpr).is.equal(1);
expect(requestBid.user.ext.consent).is.equal('abc123');
expect(requestBid.user.ext.ConsentedProvidersSettings.consented_providers).is.equal('superduperconsent');

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

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

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

it('check gdpr info gets added into cookie_sync request: have consent data', function () {
let cookieSyncConfig = utils.deepClone(CONFIG);
cookieSyncConfig.syncEndpoint = 'https://prebid.adnxs.com/pbs/v1/cookie_sync';
Expand Down

0 comments on commit 7696428

Please sign in to comment.