From 21dcd5aff5529ab966ebf337f9c818d8692e5208 Mon Sep 17 00:00:00 2001 From: Paul Yang Date: Tue, 10 Dec 2019 17:46:23 -0800 Subject: [PATCH] Conversant adapter CCPA support (#4569) --- modules/conversantBidAdapter.js | 22 +++++----- .../spec/modules/conversantBidAdapter_spec.js | 40 +++++++++++++++++-- 2 files changed, 48 insertions(+), 14 deletions(-) diff --git a/modules/conversantBidAdapter.js b/modules/conversantBidAdapter.js index 3ffc54bbe80..bb11b1f87cb 100644 --- a/modules/conversantBidAdapter.js +++ b/modules/conversantBidAdapter.js @@ -122,16 +122,18 @@ export const spec = { let userExt = {}; - // Add GDPR flag and consent string - if (bidderRequest && bidderRequest.gdprConsent) { - userExt.consent = bidderRequest.gdprConsent.consentString; - - if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { - payload.regs = { - ext: { - gdpr: (bidderRequest.gdprConsent.gdprApplies ? 1 : 0) - } - }; + if (bidderRequest) { + // Add GDPR flag and consent string + if (bidderRequest.gdprConsent) { + userExt.consent = bidderRequest.gdprConsent.consentString; + + if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { + utils.deepSetValue(payload, 'regs.ext.gdpr', bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + } + } + + if (bidderRequest.uspConsent) { + utils.deepSetValue(payload, 'regs.ext.us_privacy', bidderRequest.uspConsent); } } diff --git a/test/spec/modules/conversantBidAdapter_spec.js b/test/spec/modules/conversantBidAdapter_spec.js index ca6890ceedb..67dd721a059 100644 --- a/test/spec/modules/conversantBidAdapter_spec.js +++ b/test/spec/modules/conversantBidAdapter_spec.js @@ -404,31 +404,63 @@ describe('Conversant adapter tests', function() { it('Verify GDPR bid request', function() { // add gdpr info - const bidRequest = { + const bidderRequest = { gdprConsent: { consentString: 'BOJObISOJObISAABAAENAA4AAAAAoAAA', gdprApplies: true } }; - const payload = spec.buildRequests(bidRequests, bidRequest).data; + const payload = spec.buildRequests(bidRequests, bidderRequest).data; expect(payload).to.have.deep.nested.property('user.ext.consent', 'BOJObISOJObISAABAAENAA4AAAAAoAAA'); expect(payload).to.have.deep.nested.property('regs.ext.gdpr', 1); }); it('Verify GDPR bid request without gdprApplies', function() { // add gdpr info - const bidRequest = { + const bidderRequest = { gdprConsent: { consentString: '' } }; - const payload = spec.buildRequests(bidRequests, bidRequest).data; + const payload = spec.buildRequests(bidRequests, bidderRequest).data; expect(payload).to.have.deep.nested.property('user.ext.consent', ''); expect(payload).to.not.have.deep.nested.property('regs.ext.gdpr'); }); + describe('CCPA', function() { + it('should have us_privacy', function() { + const bidderRequest = { + uspConsent: '1NYN' + }; + + const payload = spec.buildRequests(bidRequests, bidderRequest).data; + expect(payload).to.have.deep.nested.property('regs.ext.us_privacy', '1NYN'); + expect(payload).to.not.have.deep.nested.property('regs.ext.gdpr'); + }); + + it('should have no us_privacy', function() { + const payload = spec.buildRequests(bidRequests, {}).data; + expect(payload).to.not.have.deep.nested.property('regs.ext.us_privacy'); + }); + + it('should have both gdpr and us_privacy', function() { + const bidderRequest = { + gdprConsent: { + consentString: 'BOJObISOJObISAABAAENAA4AAAAAoAAA', + gdprApplies: true + }, + uspConsent: '1NYN' + }; + + const payload = spec.buildRequests(bidRequests, bidderRequest).data; + expect(payload).to.have.deep.nested.property('user.ext.consent', 'BOJObISOJObISAABAAENAA4AAAAAoAAA'); + expect(payload).to.have.deep.nested.property('regs.ext.gdpr', 1); + expect(payload).to.have.deep.nested.property('regs.ext.us_privacy', '1NYN'); + }); + }); + describe('Extended ID', function() { it('Verify unifiedid and liveramp', function() { // clone bidRequests