diff --git a/modules/aardvarkBidAdapter.js b/modules/aardvarkBidAdapter.js index 02a2ebd5408..79e82e1ff90 100644 --- a/modules/aardvarkBidAdapter.js +++ b/modules/aardvarkBidAdapter.js @@ -19,7 +19,7 @@ export const spec = { isBidRequestValid: function(bid) { return ((typeof bid.params.ai === 'string') && !!bid.params.ai.length && - (typeof bid.params.sc === 'string') && !!bid.params.sc.length); + (typeof bid.params.sc === 'string') && !!bid.params.sc.length); }, buildRequests: function(validBidRequests, bidderRequest) { @@ -82,7 +82,7 @@ export const spec = { }); } - if (bidderRequest && bidderRequest.gdprConsent) { + if (bidderRequest.gdprConsent) { rMap.payload.gdpr = false; if (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') { rMap.payload.gdpr = bidderRequest.gdprConsent.gdprApplies; @@ -96,11 +96,15 @@ export const spec = { auctionCodes.push(b.params.ai); } + if (bidderRequest.uspConsent) { + rMap.payload.us_privacy = bidderRequest.uspConsent + } + rMap.shortCodes.push(b.params.sc); rMap.payload[b.params.sc] = b.bidId; if ((typeof b.params.host === 'string') && b.params.host.length && - (b.params.host !== rMap.endpoint)) { + (b.params.host !== rMap.endpoint)) { rMap.endpoint = b.params.host; } }); @@ -166,28 +170,42 @@ export const spec = { return bidResponses; }, - getUserSyncs: function(syncOptions, serverResponses, gdprConsent) { + getUserSyncs: function(syncOptions, serverResponses, gdprConsent, uspConsent) { const syncs = []; - var url = 'https://' + SYNC_ENDPOINT + '/cs'; + const params = []; var gdprApplies = false; if (gdprConsent && (typeof gdprConsent.gdprApplies === 'boolean')) { gdprApplies = gdprConsent.gdprApplies; } - if (syncOptions.iframeEnabled) { - if (!hasSynced) { - hasSynced = true; - if (gdprApplies) { - url = url + '?g=1&c=' + encodeURIComponent(gdprConsent.consentString); - } - syncs.push({ - type: 'iframe', - url: url - }); - } - } else { + if (!syncOptions.iframeEnabled) { utils.logWarn('Aardvark: Please enable iframe based user sync.'); + return syncs; + } + + if (hasSynced) { + return syncs; + } + + hasSynced = true; + if (gdprApplies) { + params.push(['g', '1']); + params.push(['c', gdprConsent.consentString]); + } + + if (uspConsent) { + params.push(['us_privacy', uspConsent]); } + + var queryStr = ''; + if (params.length) { + queryStr = '?' + params.map(p => p[0] + '=' + encodeURIComponent(p[1])).join('&') + } + + syncs.push({ + type: 'iframe', + url: `https://${SYNC_ENDPOINT}/cs${queryStr}` + }); return syncs; }, diff --git a/test/spec/modules/aardvarkBidAdapter_spec.js b/test/spec/modules/aardvarkBidAdapter_spec.js index b8d147644f9..324607f825e 100644 --- a/test/spec/modules/aardvarkBidAdapter_spec.js +++ b/test/spec/modules/aardvarkBidAdapter_spec.js @@ -229,6 +229,54 @@ describe('aardvarkAdapterTest', function () { }); }); + describe('CCPA conformity', function () { + const bidRequests = [{ + bidder: 'aardvark', + params: { + ai: 'xiby', + sc: 'TdAx', + }, + adUnitCode: 'aaa', + transactionId: '1b8389fe-615c-482d-9f1a-177fb8f7d5b0', + sizes: [300, 250], + bidId: '1abgs362e0x48a8', + bidderRequestId: '70deaff71c281d', + auctionId: '5c66da22-426a-4bac-b153-77360bef5337' + }]; + + it('should transmit us_privacy data', function () { + const usp = '1NY-'; + const bidderRequest = { + gdprConsent: { + consentString: 'awefasdfwefasdfasd', + gdprApplies: true + }, + refererInfo: { + referer: 'http://example.com' + }, + uspConsent: usp + }; + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests.length).to.equal(1); + expect(requests[0].data.gdpr).to.equal(true); + expect(requests[0].data.consent).to.equal('awefasdfwefasdfasd'); + expect(requests[0].data.us_privacy).to.equal(usp); + }); + + it('should not send us_privacy', function () { + const bidderRequest = { + refererInfo: { + referer: 'http://example.com' + } + }; + const requests = spec.buildRequests(bidRequests, bidderRequest); + expect(requests.length).to.equal(1); + expect(requests[0].data.gdpr).to.be.undefined; + expect(requests[0].data.consent).to.be.undefined; + expect(requests[0].data.us_privacy).to.be.undefined; + }); + }); + describe('interpretResponse', function () { it('should handle bid responses', function () { const serverResponse = { @@ -343,6 +391,15 @@ describe('aardvarkAdapterTest', function () { expect(syncs[0].type).to.equal('iframe'); expect(syncs[0].url).to.equal('https://sync.rtk.io/cs?g=1&c=BOEFEAyOEFEAyAHABDENAI4AAAB9vABAASA'); }); + + it('should produce sync url with ccpa params', function () { + resetUserSync(); + + const syncs = spec.getUserSyncs(syncOptions, null, {}, '1YYN'); + expect(syncs.length).to.equal(1); + expect(syncs[0].type).to.equal('iframe'); + expect(syncs[0].url).to.equal('https://sync.rtk.io/cs?us_privacy=1YYN'); + }); }); describe('reading window.top properties', function () {