diff --git a/modules/rubiconBidAdapter.js b/modules/rubiconBidAdapter.js index dd716e6903b..d3735f01d62 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 971ce7848e6..cc996041aac 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', () => {