From 68755ddbba78f0816d61c5f3e4d3501339aabaad Mon Sep 17 00:00:00 2001 From: Alex Khmelnitsky Date: Thu, 2 Jan 2020 12:58:04 +0200 Subject: [PATCH] cedato adapter gdpr and usp compliance --- modules/cedatoBidAdapter.js | 41 ++++++------------- test/spec/modules/cedatoBidAdapter_spec.js | 46 +++++++++++++++++++++- 2 files changed, 56 insertions(+), 31 deletions(-) diff --git a/modules/cedatoBidAdapter.js b/modules/cedatoBidAdapter.js index a9e7814842c..9d6f3642f3e 100644 --- a/modules/cedatoBidAdapter.js +++ b/modules/cedatoBidAdapter.js @@ -3,10 +3,8 @@ import { registerBidder } from '../src/adapters/bidderFactory'; import { BANNER, VIDEO } from '../src/mediaTypes'; const BIDDER_CODE = 'cedato'; -const BID_URL = '//h.cedatoplayer.com/hb'; -const SYNC_URL = '//h.cedatoplayer.com/hb_usync?uid={UUID}'; -const COOKIE_NAME = 'hb-cedato-id'; -const UUID_LEN = 36; +const BID_URL = 'https://h.cedatoplayer.com/hb'; +const SYNC_URL = 'https://h.cedatoplayer.com/hb_usync'; const TTL = 10000; const CURRENCY = 'USD'; const FIRST_PRICE = 1; @@ -32,7 +30,6 @@ export const spec = { const at = FIRST_PRICE; const site = { id: params.player_id, domain: document.domain }; const device = { ua: navigator.userAgent }; - const user = { id: getUserID() } const currency = CURRENCY; const tmax = bidderRequest.timeout; const auctionId = bidderRequest.auctionId; @@ -46,6 +43,7 @@ export const spec = { const bidId = req.bidId; const adUnitCode = req.adUnitCode; const bidRequestsCount = req.bidRequestsCount; + const bidderWinsCount = req.bidderWinsCount; const transactionId = req.transactionId; return { @@ -55,6 +53,7 @@ export const spec = { adUnitCode, bidfloor, bidRequestsCount, + bidderWinsCount, transactionId }; }); @@ -64,7 +63,6 @@ export const spec = { at, site, device, - user, imp, currency, tmax, @@ -75,6 +73,8 @@ export const spec = { if (bidderRequest) { payload.referer_info = bidderRequest.refererInfo; + payload.us_privacy = bidderRequest.uspConsent; + if (bidderRequest.gdprConsent) { payload.gdpr_consent = { consent_string: bidderRequest.gdprConsent.consentString, @@ -108,12 +108,12 @@ export const spec = { return bids; }, - getUserSyncs: function(syncOptions, resps, gdprConsent) { + getUserSyncs: function(syncOptions, resps, gdprConsent, uspConsent) { const syncs = []; if (syncOptions.iframeEnabled) { - syncs.push(getSync('iframe', gdprConsent)); + syncs.push(getSync('iframe', gdprConsent, uspConsent)); } else if (syncOptions.pixelEnabled) { - syncs.push(getSync('image', gdprConsent)); + syncs.push(getSync('image', gdprConsent, uspConsent)); } return syncs; } @@ -186,10 +186,9 @@ function newBid(serverBid, bidderRequest) { return bid; } -const getSync = (type, gdprConsent) => { - const uuid = getUserID(); +const getSync = (type, gdprConsent, uspConsent = '') => { const syncUrl = SYNC_URL; - let params = '&type=' + type; + let params = '&type=' + type + '&us_privacy=' + uspConsent; if (gdprConsent && typeof gdprConsent.consentString === 'string') { if (typeof gdprConsent.gdprApplies === 'boolean') { params += `&gdpr=${Number(gdprConsent.gdprApplies)}&gdpr_consent=${gdprConsent.consentString}`; @@ -199,26 +198,10 @@ const getSync = (type, gdprConsent) => { } return { type: type, - url: syncUrl.replace('{UUID}', uuid) + params, + url: syncUrl + params, }; } -const getUserID = () => { - const cookieName = COOKIE_NAME; - const uuidLen = UUID_LEN; - - const i = document.cookie.indexOf(cookieName); - - if (i === -1) { - const uuid = utils.generateUUID(); - document.cookie = `${cookieName}=${uuid}; path=/`; - return uuid; - } - - const j = i + cookieName.length + 1; - return document.cookie.substring(j, j + uuidLen); -}; - const getFormats = arr => arr.map((s) => { return { w: s[0], h: s[1] }; }); diff --git a/test/spec/modules/cedatoBidAdapter_spec.js b/test/spec/modules/cedatoBidAdapter_spec.js index 969c06a64a2..0cf6d14147a 100644 --- a/test/spec/modules/cedatoBidAdapter_spec.js +++ b/test/spec/modules/cedatoBidAdapter_spec.js @@ -33,18 +33,35 @@ describe('the cedato adapter', function () { expect(result).to.equal(false); }); }); + describe('buildRequests', function() { var bid, bidRequestObj; beforeEach(function() { bid = getValidBidObject(); - bidRequestObj = {refererInfo: {referer: 'prebid.js'}}; + bidRequestObj = { + refererInfo: {referer: 'prebid.js'}, + gdprConsent: { + consentString: 'test-string', + gdprApplies: true + }, + uspConsent: '1NYN' + }; }); it('should build a very basic request', function() { var request = spec.buildRequests([bid], bidRequestObj); expect(request.method).to.equal('POST'); }); + + it('should pass gdpr and usp strings to server', function() { + var request = spec.buildRequests([bid], bidRequestObj); + var payload = JSON.parse(request.data); + expect(payload.gdpr_consent).to.not.be.undefined; + expect(payload.gdpr_consent.consent_string).to.equal(bidRequestObj.gdprConsent.consentString); + expect(payload.gdpr_consent.consent_required).to.equal(bidRequestObj.gdprConsent.gdprApplies); + expect(payload.us_privacy).to.equal(bidRequestObj.uspConsent); + }); }); describe('interpretResponse', function() { @@ -68,7 +85,7 @@ describe('the cedato adapter', function () { adomain: 'cedato.com', uuid: bid.bidId, crid: '1450133326', - adm: "
\n\n\n", + adm: "
\n\n\n", h: 250, w: 300, price: '0.1' @@ -88,4 +105,29 @@ describe('the cedato adapter', function () { expect(responses).to.be.an('array').with.length(1); }); }); + + describe('getUserSyncs', function() { + var bid; + + beforeEach(function() { + bid = getValidBidObject(); + }); + + it('should sync with iframe', function() { + var syncs = spec.getUserSyncs({ iframeEnabled: true }, null, { + consentString: '', + gdprApplies: true + }); + + expect(syncs).to.be.an('array').with.length(1); + expect(syncs[0].type).to.equal('iframe'); + }); + + it('should sync with image', function() { + var syncs = spec.getUserSyncs({ pixelEnabled: true }); + + expect(syncs).to.be.an('array').with.length(1); + expect(syncs[0].type).to.equal('image'); + }); + }); });