From 43680d4aca77aa129955f9e9657d51a0834298f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9onard=20Labat?= Date: Wed, 17 Apr 2024 16:21:01 +0200 Subject: [PATCH] Criteo Bid Adapter : Add support of pixel based user sync (#11303) --- modules/criteoBidAdapter.js | 50 +++++++++++++--- test/spec/modules/criteoBidAdapter_spec.js | 69 ++++++++++++++++++++-- 2 files changed, 106 insertions(+), 13 deletions(-) diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index 968a847708e..defe2c081e3 100644 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -55,16 +55,18 @@ export const spec = { gvlid: GVLID, supportedMediaTypes: [BANNER, VIDEO, NATIVE], - getUserSyncs: function (syncOptions, _, gdprConsent, uspConsent) { - const fastBidVersion = config.getConfig('criteo.fastBidVersion'); - if (canFastBid(fastBidVersion)) { - return []; - } - - const refererInfo = getRefererInfo(); - const origin = 'criteoPrebidAdapter'; + getUserSyncs: function (syncOptions, _, gdprConsent, uspConsent, gppConsent = {}) { + let { gppString = '', applicableSections = [] } = gppConsent; if (syncOptions.iframeEnabled && hasPurpose1Consent(gdprConsent)) { + const fastBidVersion = config.getConfig('criteo.fastBidVersion'); + if (canFastBid(fastBidVersion)) { + return []; + } + + const refererInfo = getRefererInfo(); + const origin = 'criteoPrebidAdapter'; + const queryParams = []; queryParams.push(`origin=${origin}`); queryParams.push(`topUrl=${refererInfo.domain}`); @@ -79,6 +81,12 @@ export const spec = { if (uspConsent) { queryParams.push(`us_privacy=${uspConsent}`); } + queryParams.push(`gpp=${gppString}`); + if (Array.isArray(applicableSections)) { + for (const applicableSection of applicableSections) { + queryParams.push(`gpp_sid=${applicableSection}`); + } + } const requestId = Math.random().toString(); @@ -126,6 +134,32 @@ export const spec = { type: 'iframe', url: `https://gum.criteo.com/syncframe?${queryParams.join('&')}#${jsonHashSerialized}` }]; + } else if (syncOptions.pixelEnabled && hasPurpose1Consent(gdprConsent)) { + const queryParams = []; + queryParams.push(`profile=207`); + if (gdprConsent) { + if (gdprConsent.gdprApplies === true) { + queryParams.push(`gdprapplies=true`); + } + if (gdprConsent.consentString) { + queryParams.push(`gdpr=${gdprConsent.consentString}`); + } + } + if (uspConsent) { + queryParams.push(`ccpa=${uspConsent}`); + } + queryParams.push(`gpp=${gppString}`); + if (Array.isArray(applicableSections)) { + for (const applicableSection of applicableSections) { + queryParams.push(`gpp_sid=${applicableSection}`); + } + } + // gpp + // gpp_sid + return [{ + type: 'image', + url: `https://ssp-sync.criteo.com/user-sync/redirect?${queryParams.join('&')}` + }]; } return []; }, diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index 083ae368afb..c460b451193 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -38,7 +38,66 @@ describe('The Criteo bidding adapter', function () { ajaxStub.restore(); }); - describe('getUserSyncs', function () { + describe('getUserSyncs in pixel mode', function () { + const syncOptions = { + pixelEnabled: true + }; + + it('should not trigger sync if publisher did not enable pixel based syncs', function () { + const userSyncs = spec.getUserSyncs({ + iframeEnabled: false + }, undefined, undefined, undefined); + + expect(userSyncs).to.eql([]); + }); + + it('should not trigger sync if purpose one is not granted', function () { + const gdprConsent = { + gdprApplies: true, + consentString: 'ABC', + vendorData: { + purpose: { + consents: { + 1: false + } + } + } + }; + const userSyncs = spec.getUserSyncs(syncOptions, undefined, gdprConsent, undefined); + + expect(userSyncs).to.eql([]); + }); + + it('should trigger sync with consent data', function () { + const usPrivacy = 'usp_string'; + + const gppConsent = { + gppString: 'gpp_string', + applicableSections: [ 1, 2 ] + }; + + const gdprConsent = { + gdprApplies: true, + consentString: 'ABC', + vendorData: { + purpose: { + consents: { + 1: true + } + } + } + }; + + const userSyncs = spec.getUserSyncs(syncOptions, undefined, gdprConsent, usPrivacy, gppConsent); + + expect(userSyncs).to.eql([{ + type: 'image', + url: 'https://ssp-sync.criteo.com/user-sync/redirect?profile=207&gdprapplies=true&gdpr=ABC&ccpa=usp_string&gpp=gpp_string&gpp_sid=1&gpp_sid=2' + }]); + }); + }); + + describe('getUserSyncs in iframe mode', function () { const syncOptionsIframeEnabled = { iframeEnabled: true }; @@ -151,7 +210,7 @@ describe('The Criteo bidding adapter', function () { expect(userSyncs).to.eql([{ type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com#${JSON.stringify(expectedHashWithCookieData, Object.keys(expectedHashWithCookieData).sort()).replace(/"/g, '%22')}` + url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gpp=#${JSON.stringify(expectedHashWithCookieData, Object.keys(expectedHashWithCookieData).sort()).replace(/"/g, '%22')}` }]); }); @@ -175,7 +234,7 @@ describe('The Criteo bidding adapter', function () { expect(userSyncs).to.eql([{ type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com#${JSON.stringify(expectedHashWithLocalStorageData, Object.keys(expectedHashWithLocalStorageData).sort()).replace(/"/g, '%22')}` + url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gpp=#${JSON.stringify(expectedHashWithLocalStorageData, Object.keys(expectedHashWithLocalStorageData).sort()).replace(/"/g, '%22')}` }]); }); @@ -195,7 +254,7 @@ describe('The Criteo bidding adapter', function () { expect(userSyncs).to.eql([{ type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gdpr=1&gdpr_consent=ABC#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` + url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&gdpr=1&gdpr_consent=ABC&gpp=#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` }]); }); @@ -204,7 +263,7 @@ describe('The Criteo bidding adapter', function () { expect(userSyncs).to.eql([{ type: 'iframe', - url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&us_privacy=ABC#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` + url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&us_privacy=ABC&gpp=#${JSON.stringify(expectedHash).replace(/"/g, '%22')}` }]); });