From 5d7fdc4f67431a3786cd163d8ed331d6a7d94e63 Mon Sep 17 00:00:00 2001 From: ahubertcriteo <31441781+ahubertcriteo@users.noreply.github.com> Date: Wed, 2 May 2018 15:04:48 +0200 Subject: [PATCH] GDPR support in Criteo adapter (#4) GDPR support in Criteo adapter --- modules/criteoBidAdapter.js | 13 +++++++-- test/spec/modules/criteoBidAdapter_spec.js | 32 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index a391af8e9ff..d713b5263f8 100755 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -9,6 +9,7 @@ var events = require('src/events'); const ADAPTER_VERSION = 4; const BIDDER_CODE = 'criteo'; const CDB_ENDPOINT = '//bidder.criteo.com/cdb'; +const CRITEO_VENDOR_ID = 91; const INTEGRATION_MODES = { 'amp': 1, }; @@ -60,7 +61,7 @@ export const spec = { } else { const context = buildContext(bidRequests); url = buildCdbUrl(context); - data = buildCdbRequest(context, bidRequests); + data = buildCdbRequest(context, bidRequests, bidderRequest); } if (data) { @@ -181,7 +182,7 @@ function buildCdbUrl(context) { * @param {BidRequest[]} bidRequests * @return {*} */ -function buildCdbRequest(context, bidRequests) { +function buildCdbRequest(context, bidRequests, bidderRequest) { let networkId; const request = { publisher: { @@ -210,6 +211,14 @@ function buildCdbRequest(context, bidRequests) { if (networkId) { request.publisher.networkid = networkId; } + if (bidderRequest && bidderRequest.gdprConsent) { + request.gdprConsent = { + gdprApplies: !!(bidderRequest.gdprConsent.gdprApplies), + consentData: bidderRequest.gdprConsent.consentString, + consentGiven: !!(bidderRequest.gdprConsent.vendorData && bidderRequest.gdprConsent.vendorData.vendorConsents && + bidderRequest.gdprConsent.vendorData.vendorConsents[ CRITEO_VENDOR_ID.toString(10) ]), + }; + } return request; } diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index c8a0b235fac..a253dc93404 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -48,7 +48,17 @@ describe('The Criteo bidding adapter', () => { }); describe('buildRequests', () => { - const bidderRequest = { timeout: 3000 }; + const bidderRequest = { timeout: 3000, + gdprConsent: { + gdprApplies: 1, + consentString: 'concentDataString', + vendorData: { + vendorConsents: { + '1': 1 + }, + }, + }, + }; it('should properly build a zoneId request', () => { const bidRequests = [ @@ -73,9 +83,24 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.slots[0].sizes).to.have.lengthOf(1); expect(ortbRequest.slots[0].sizes[0]).to.equal('728x90'); expect(ortbRequest.slots[0].zoneid).to.equal(123); + expect(ortbRequest.gdprConsent.consentData).to.equal('concentDataString'); + expect(ortbRequest.gdprConsent.gdprApplies).to.equal(true); + expect(ortbRequest.gdprConsent.consentGiven).to.equal(true); }); it('should properly build a networkId request', () => { + const bidderRequest = { + timeout: 3000, + gdprConsent: { + gdprApplies: 0, + consentString: undefined, + vendorData: { + vendorConsents: { + '1': 0 + }, + }, + }, + }; const bidRequests = [ { bidder: 'criteo', @@ -99,9 +124,13 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.slots[0].sizes).to.have.lengthOf(2); expect(ortbRequest.slots[0].sizes[0]).to.equal('300x250'); expect(ortbRequest.slots[0].sizes[1]).to.equal('728x90'); + expect(ortbRequest.gdprConsent.consentData).to.equal(undefined); + expect(ortbRequest.gdprConsent.gdprApplies).to.equal(false); + expect(ortbRequest.gdprConsent.consentGiven).to.equal(false); }); it('should properly build a mixed request', () => { + const bidderRequest = { timeout: 3000 }; const bidRequests = [ { bidder: 'criteo', @@ -138,6 +167,7 @@ describe('The Criteo bidding adapter', () => { expect(ortbRequest.slots[1].sizes).to.have.lengthOf(2); expect(ortbRequest.slots[1].sizes[0]).to.equal('300x250'); expect(ortbRequest.slots[1].sizes[1]).to.equal('728x90'); + expect(ortbRequest.gdprConsent).to.equal(undefined); }); });