Skip to content

Commit 30d8c5a

Browse files
idettmandluxemburg
authored andcommitted
Rubicon Adapter GDPR Update for gdprApplies flag (prebid#2456)
* 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
1 parent 71e7e6c commit 30d8c5a

File tree

2 files changed

+57
-77
lines changed

2 files changed

+57
-77
lines changed

modules/rubiconBidAdapter.js

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ export const spec = {
134134

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

137+
// GDPR reference, for use by 'banner' and 'video'
138+
const gdprConsent = bidderRequest.gdprConsent;
139+
137140
if (spec.hasVideoMediaType(bidRequest)) {
138141
let params = bidRequest.params;
139142
let size = parseSizes(bidRequest);
@@ -178,9 +181,12 @@ export const spec = {
178181

179182
data.slots.push(slotData);
180183

181-
if (bidderRequest && bidderRequest.gdprConsent) {
182-
data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0;
183-
data.gdpr_consent = bidderRequest.gdprConsent.consentString;
184+
if (gdprConsent) {
185+
// add 'gdpr' only if 'gdprApplies' is defined
186+
if (typeof gdprConsent.gdprApplies === 'boolean') {
187+
data.gdpr = Number(gdprConsent.gdprApplies);
188+
}
189+
data.gdpr_consent = gdprConsent.consentString;
184190
}
185191

186192
return {
@@ -228,13 +234,12 @@ export const spec = {
228234
'tk_user_key', userId
229235
];
230236

231-
// add GDPR properties if enabled
232-
if (config.getConfig('consentManagement') &&
233-
bidderRequest && bidderRequest.gdprConsent && typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') {
234-
data.push(
235-
'gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0,
236-
'gdpr_consent', bidderRequest.gdprConsent.consentString
237-
);
237+
if (gdprConsent) {
238+
// add 'gdpr' only if 'gdprApplies' is defined
239+
if (typeof gdprConsent.gdprApplies === 'boolean') {
240+
data.push('gdpr', Number(gdprConsent.gdprApplies));
241+
}
242+
data.push('gdpr_consent', gdprConsent.consentString);
238243
}
239244

240245
if (visitor !== null && typeof visitor === 'object') {

test/spec/modules/rubiconBidAdapter_spec.js

Lines changed: 42 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,24 @@ describe('the rubicon adapter', () => {
1515
let sandbox,
1616
bidderRequest;
1717

18-
function addConsentManagement() {
19-
bidderRequest.gdprConsent = {
20-
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
21-
'gdprApplies': true
18+
/**
19+
* @param {boolean} [gdprApplies]
20+
*/
21+
function createGdprBidderRequest(gdprApplies) {
22+
if (typeof gdprApplies === 'boolean') {
23+
bidderRequest.gdprConsent = {
24+
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==',
25+
'gdprApplies': gdprApplies
26+
};
27+
} else {
28+
bidderRequest.gdprConsent = {
29+
'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
30+
};
2231
}
2332
}
2433

2534
function createVideoBidderRequest() {
26-
addConsentManagement();
35+
createGdprBidderRequest(true);
2736

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

4857
function createLegacyVideoBidderRequest() {
49-
addConsentManagement();
58+
createGdprBidderRequest(true);
5059

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

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

541-
sandbox.stub(config, 'getConfig').callsFake((key) => {
542-
var config = {
543-
consentManagement: {
544-
cmp: 'iab',
545-
waitForConsentTimeout: 4000,
546-
lookUpFailureResolution: 'cancel'
547-
}
548-
};
549-
return config[key];
553+
expect(data['gdpr']).to.equal('1');
554+
expect(data['gdpr_consent']).to.equal('BOJ/P2HOJ/P2HABABMAAAAAZ+A==');
550555
});
551556

552-
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
553-
let data = parseQuery(request.data);
554-
let expectedQuery = {
555-
'gdpr': '1',
556-
'gdpr_consent': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A=='
557-
};
558-
559-
// test that all values above are both present and correct
560-
Object.keys(expectedQuery).forEach(key => {
561-
let value = expectedQuery[key];
562-
expect(data[key]).to.equal(value);
563-
});
564-
});
557+
it('should send only "gdpr_consent", when gdprConsent defines only consentString', () => {
558+
createGdprBidderRequest();
559+
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
560+
let data = parseQuery(request.data);
565561

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

572-
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
573-
let data = parseQuery(request.data);
574-
let expectedQuery = {
575-
'gdpr': undefined,
576-
'gdpr_consent': undefined
577-
};
578-
579-
// test that all values above are both present and correct
580-
Object.keys(expectedQuery).forEach(key => {
581-
let value = expectedQuery[key];
582-
expect(data[key]).to.equal(value);
583-
});
584-
});
566+
it('should not send GDPR params if gdprConsent is not defined', () => {
567+
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
568+
let data = parseQuery(request.data);
585569

586-
it('should not send GDPR params if gdprConsent is not set in config', () => {
587-
sandbox.stub(config, 'getConfig').callsFake((key) => {
588-
var config = {
589-
consentManagement: {
590-
cmp: 'iab',
591-
waitForConsentTimeout: 4000,
592-
lookUpFailureResolution: 'cancel'
593-
}
594-
};
595-
return config[key];
570+
expect(data['gdpr']).to.equal(undefined);
571+
expect(data['gdpr_consent']).to.equal(undefined);
596572
});
597573

598-
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
599-
let data = parseQuery(request.data);
600-
let expectedQuery = {
601-
'gdpr': undefined,
602-
'gdpr_consent': undefined
603-
};
574+
it('should set "gdpr" value as 1 or 0, using "gdprApplies" value of either true/false', () => {
575+
createGdprBidderRequest(true);
576+
let [request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
577+
let data = parseQuery(request.data);
578+
expect(data['gdpr']).to.equal('1');
604579

605-
// test that all values above are both present and correct
606-
Object.keys(expectedQuery).forEach(key => {
607-
let value = expectedQuery[key];
608-
expect(data[key]).to.equal(value);
580+
createGdprBidderRequest(false);
581+
[request] = spec.buildRequests(bidderRequest.bids, bidderRequest);
582+
data = parseQuery(request.data);
583+
expect(data['gdpr']).to.equal('0');
609584
});
610585
});
611586
});

0 commit comments

Comments
 (0)