Skip to content

Commit

Permalink
Criteo Bid Adapter : Add support of pixel based user sync (#11303)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardlabat authored Apr 17, 2024
1 parent 122a72a commit 43680d4
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 13 deletions.
50 changes: 42 additions & 8 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand All @@ -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();

Expand Down Expand Up @@ -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 [];
},
Expand Down
69 changes: 64 additions & 5 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
};
Expand Down Expand Up @@ -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')}`
}]);
});

Expand All @@ -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')}`
}]);
});

Expand All @@ -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')}`
}]);
});

Expand All @@ -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')}`
}]);
});

Expand Down

0 comments on commit 43680d4

Please sign in to comment.