From 20cabbace0ca3b387ef242e658009f81321fce16 Mon Sep 17 00:00:00 2001 From: CathyH Date: Mon, 23 Jul 2018 22:59:37 -0700 Subject: [PATCH] C1X Adapter GDPR Support (#2821) * C1X Adapter GDPR Support * remove the redundant userSync * fixed keyword spacing issue --- modules/c1xBidAdapter.js | 22 +++++++++++++++++----- test/spec/modules/c1xBidAdapter_spec.js | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/modules/c1xBidAdapter.js b/modules/c1xBidAdapter.js index af1de3739853..ff1b011f7871 100644 --- a/modules/c1xBidAdapter.js +++ b/modules/c1xBidAdapter.js @@ -14,7 +14,7 @@ const LOG_MSG = { /** * Adapter for requesting bids from C1X header tag server. - * v3.0 (c) C1X Inc., 2017 + * v3.1 (c) C1X Inc., 2018 */ export const c1xAdapter = { @@ -29,9 +29,10 @@ export const c1xAdapter = { return !!(bid.adUnitCode && siteId); }, - buildRequests: function(bidRequests) { + buildRequests: function(bidRequests, bidderRequest) { let payload = {}; let tagObj = {}; + let pixelUrl = ''; const adunits = bidRequests.length; const rnd = new Date().getTime(); const c1xTags = bidRequests.map(bidToTag); @@ -48,15 +49,26 @@ export const c1xAdapter = { response: 'json', compress: 'gzip' } - Object.assign(payload, tagObj); - let payloadString = stringifyPayload(payload); + // for GDPR support + if (bidderRequest && bidderRequest.gdprConsent) { + payload['consent_string'] = bidderRequest.gdprConsent.consentString; + payload['consent_required'] = (typeof bidderRequest.gdprConsent.gdprApplies === 'boolean') ? bidderRequest.gdprConsent.gdprApplies.toString() : 'true' + ; + } if (pixelId) { - const pixelUrl = (useSSL ? 'https:' : 'http:') + PIXEL_ENDPOINT + pixelId; + pixelUrl = (useSSL ? 'https:' : 'http:') + PIXEL_ENDPOINT + pixelId; + if (payload.consent_required) { + pixelUrl += '&gdpr=' + (bidderRequest.gdprConsent.gdprApplies ? 1 : 0); + pixelUrl += '&consent=' + encodeURIComponent(bidderRequest.gdprConsent.consentString || ''); + } userSync.registerSync('image', BIDDER_CODE, pixelUrl); } + Object.assign(payload, tagObj); + + let payloadString = stringifyPayload(payload); // ServerRequest object return { method: 'GET', diff --git a/test/spec/modules/c1xBidAdapter_spec.js b/test/spec/modules/c1xBidAdapter_spec.js index 0517668ea0dc..bd7fa5df669a 100644 --- a/test/spec/modules/c1xBidAdapter_spec.js +++ b/test/spec/modules/c1xBidAdapter_spec.js @@ -114,6 +114,24 @@ describe('C1XAdapter', () => { const payloadObj = JSON.parse(originalPayload); expect(payloadObj.pageurl).to.equal('http://c1exchange.com/'); }); + + it('should convert GDPR Consent to proper form and attach to request', () => { + let consentString = 'BOP2gFWOQIFovABABAENBGAAAAAAMw'; + let bidderRequest = { + 'bidderCode': 'c1x', + 'gdprConsent': { + 'consentString': consentString, + 'gdprApplies': true + } + } + bidderRequest.bids = bidRequests; + + const request = c1xAdapter.buildRequests(bidRequests, bidderRequest); + const originalPayload = parseRequest(request.data); + const payloadObj = JSON.parse(originalPayload); + expect(payloadObj['consent_string']).to.equal('BOP2gFWOQIFovABABAENBGAAAAAAMw'); + expect(payloadObj['consent_required']).to.equal('true'); + }); }); describe('interpretResponse', () => {