Skip to content

Commit

Permalink
Rubicon Adapter GDPR Update for gdprApplies flag (#2456)
Browse files Browse the repository at this point in the history
* Merged gdpr tests for banner bid requests

* Renamed the gdprConsent.consentRequired to gdprConsent.gdprApplies. Changed containing object used to access gdprConsent values (bidRequest -> bidderRequest)

* Added compatibility for CMP 1.0 and 1.1
  • Loading branch information
idettman authored and jsnellbaker committed Apr 27, 2018
1 parent fae4048 commit e82c58a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 77 deletions.
25 changes: 15 additions & 10 deletions modules/rubiconBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@ export const spec = {

page_url = bidRequest.params.secure ? page_url.replace(/^http:/i, 'https:') : page_url;

// GDPR reference, for use by 'banner' and 'video'
const gdprConsent = bidderRequest.gdprConsent;

if (spec.hasVideoMediaType(bidRequest)) {
let params = bidRequest.params;
let size = parseSizes(bidRequest);
Expand Down Expand Up @@ -178,9 +181,12 @@ export const spec = {

data.slots.push(slotData);

if (bidderRequest && bidderRequest.gdprConsent) {
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
data.gdpr_consent = bidderRequest.gdprConsent.consentString;
if (gdprConsent) {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
data.gdpr = Number(gdprConsent.gdprApplies);
}
data.gdpr_consent = gdprConsent.consentString;
}

return {
Expand Down Expand Up @@ -228,13 +234,12 @@ export const spec = {
'tk_user_key', userId
];

// add GDPR properties if enabled
if (config.getConfig('consentManagement') &&
bidderRequest && bidderRequest.gdprConsent && typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
data.push(
'gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
'gdpr_consent', bidderRequest.gdprConsent.consentString
);
if (gdprConsent) {
// add 'gdpr' only if 'gdprApplies' is defined
if (typeof gdprConsent.gdprApplies === 'boolean') {
data.push('gdpr', Number(gdprConsent.gdprApplies));
}
data.push('gdpr_consent', gdprConsent.consentString);
}

if (visitor !== null && typeof visitor === 'object') {
Expand Down
109 changes: 42 additions & 67 deletions test/spec/modules/rubiconBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,24 @@ describe('the rubicon adapter', () => {
let sandbox,
bidderRequest;

function addConsentManagement() {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'gdprApplies': true
/**
* @param {boolean} [gdprApplies]
*/
function createGdprBidderRequest(gdprApplies) {
if (typeof gdprApplies === 'boolean') {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
'gdprApplies': gdprApplies
};
} else {
bidderRequest.gdprConsent = {
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
};
}
}

function createVideoBidderRequest() {
addConsentManagement();
createGdprBidderRequest(true);

let bid = bidderRequest.bids[0];
bid.mediaTypes = {
Expand All @@ -46,7 +55,7 @@ describe('the rubicon adapter', () => {
}

function createLegacyVideoBidderRequest() {
addConsentManagement();
createGdprBidderRequest(true);

let bid = bidderRequest.bids[0];
// Legacy property (Prebid <1.0)
Expand Down Expand Up @@ -535,77 +544,43 @@ describe('the rubicon adapter', () => {
});
});

it('should send GDPR params when enabled', () => {
addConsentManagement();
describe('GDPR consent config', () => {
it('should send "gdpr" and "gdpr_consent", when gdprConsent defines consentString and gdprApplies', () => {
createGdprBidderRequest(true);
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
consentManagement: {
cmp: 'iab',
waitForConsentTimeout: 4000,
lookUpFailureResolution: 'cancel'
}
};
return config[key];
expect(data['gdpr']).to.equal('1');
expect(data['gdpr_consent']).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': '1',
'gdpr_consent': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
};

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});
it('should send only "gdpr_consent", when gdprConsent defines only consentString', () => {
createGdprBidderRequest();
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

it('should not send GDPR params if not enabled', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {};
return config[key];
expect(data['gdpr_consent']).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
expect(data['gdpr']).to.equal(undefined);
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': undefined,
'gdpr_consent': undefined
};

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
});
});
it('should not send GDPR params if gdprConsent is not defined', () => {
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);

it('should not send GDPR params if gdprConsent is not set in config', () => {
sandbox.stub(config, 'getConfig').callsFake((key) => {
var config = {
consentManagement: {
cmp: 'iab',
waitForConsentTimeout: 4000,
lookUpFailureResolution: 'cancel'
}
};
return config[key];
expect(data['gdpr']).to.equal(undefined);
expect(data['gdpr_consent']).to.equal(undefined);
});

let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
let expectedQuery = {
'gdpr': undefined,
'gdpr_consent': undefined
};
it('should set "gdpr" value as 1 or 0, using "gdprApplies" value of either true/false', () => {
createGdprBidderRequest(true);
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
let data = parseQuery(request.data);
expect(data['gdpr']).to.equal('1');

// test that all values above are both present and correct
Object.keys(expectedQuery).forEach(key => {
let value = expectedQuery[key];
expect(data[key]).to.equal(value);
createGdprBidderRequest(false);
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
data = parseQuery(request.data);
expect(data['gdpr']).to.equal('0');
});
});
});
Expand Down

0 comments on commit e82c58a

Please sign in to comment.