From bf5113bcf8c6f44ba6eefbedae54ee83d5d3fd64 Mon Sep 17 00:00:00 2001 From: Isaac Dettman Date: Tue, 24 Apr 2018 11:25:57 -0700 Subject: [PATCH] Rubicon adapter GDPR support (#2406) * Merged gdpr tests for banner bid requests * Renamed the gdprConsent.consentRequired to gdprConsent.gdprApplies. Changed containing object used to access gdprConsent values (bidRequest -> bidderRequest) --- modules/rubiconBidAdapter.js | 15 +++- test/spec/modules/rubiconBidAdapter_spec.js | 97 ++++++++++++++++++--- 2 files changed, 97 insertions(+), 15 deletions(-) diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index dd716e6903b2..d3735f01d625 100644 --- a/modules/rubiconBidAdapter.js +++ b/modules/rubiconBidAdapter.js @@ -178,9 +178,9 @@ export const spec = { data.slots.push(slotData); - if (bidderRequest && bidRequest.gdprConsent) { - data.gdpr = bidRequest.gdprConsent.consentRequired ? 1 : 0; - data.gdpr_consent = bidRequest.gdprConsent.consentString; + if (bidderRequest && bidderRequest.gdprConsent) { + data.gdpr = bidderRequest.gdprConsent.gdprApplies ? 1 : 0; + data.gdpr_consent = bidderRequest.gdprConsent.consentString; } return { @@ -228,6 +228,15 @@ 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 (visitor !== null && typeof visitor === 'object') { utils._each(visitor, (item, key) => data.push(`tg_v.${key}`, item)); } diff --git a/test/spec/modules/rubiconBidAdapter_spec.js b/test/spec/modules/rubiconBidAdapter_spec.js index 971ce7848e62..cc996041aacd 100644 --- a/test/spec/modules/rubiconBidAdapter_spec.js +++ b/test/spec/modules/rubiconBidAdapter_spec.js @@ -15,20 +15,22 @@ describe('the rubicon adapter', () => { let sandbox, bidderRequest; + function addConsentManagement() { + bidderRequest.gdprConsent = { + 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', + 'gdprApplies': true + } + } + function createVideoBidderRequest() { - let bid = bidderRequest.bids[0]; + addConsentManagement(); + let bid = bidderRequest.bids[0]; bid.mediaTypes = { video: { context: 'instream' } }; - - bid.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'consentRequired': true - }; - bid.params.video = { 'language': 'en', 'p_aso.video.ext.skip': true, @@ -44,14 +46,11 @@ describe('the rubicon adapter', () => { } function createLegacyVideoBidderRequest() { - let bid = bidderRequest.bids[0]; + addConsentManagement(); + let bid = bidderRequest.bids[0]; // Legacy property (Prebid <1.0) bid.mediaType = 'video'; - bid.gdprConsent = { - 'consentString': 'BOJ/P2HOJ/P2HABABMAAAAAZ+A==', - 'consentRequired': true - }; bid.params.video = { 'language': 'en', 'p_aso.video.ext.skip': true, @@ -535,6 +534,80 @@ describe('the rubicon adapter', () => { expect(window.DigiTrust.getUser.calledOnce).to.equal(true); }); }); + + it('should send GDPR params when enabled', () => { + addConsentManagement(); + + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + consentManagement: { + cmp: 'iab', + waitForConsentTimeout: 4000, + lookUpFailureResolution: 'cancel' + } + }; + return config[key]; + }); + + 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 not send GDPR params if not enabled', () => { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = {}; + return config[key]; + }); + + 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 set in config', () => { + sandbox.stub(config, 'getConfig').callsFake((key) => { + var config = { + consentManagement: { + cmp: 'iab', + waitForConsentTimeout: 4000, + lookUpFailureResolution: 'cancel' + } + }; + return config[key]; + }); + + 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); + }); + }); }); describe('for video requests', () => {