Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TCFv2 consent data in Criteo Id module #5073

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions modules/criteoIdSystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,18 +56,19 @@ function getCriteoDataFromAllStorages() {
}
}

function buildCriteoUsersyncUrl(topUrl, domain, bundle, areCookiesWriteable, isPublishertagPresent) {
function buildCriteoUsersyncUrl(topUrl, domain, bundle, areCookiesWriteable, isPublishertagPresent, gdprString) {
const url = 'https://gum.criteo.com/sid/json?origin=prebid' +
`${topUrl ? '&topUrl=' + encodeURIComponent(topUrl) : ''}` +
`${domain ? '&domain=' + encodeURIComponent(domain) : ''}` +
`${bundle ? '&bundle=' + encodeURIComponent(bundle) : ''}` +
`${gdprString ? '&gdprString=' + encodeURIComponent(gdprString) : ''}` +
`${areCookiesWriteable ? '&cw=1' : ''}` +
`${isPublishertagPresent ? '&pbt=1' : ''}`

return url;
}

function callCriteoUserSync(parsedCriteoData) {
function callCriteoUserSync(parsedCriteoData, gdprString) {
const cw = areCookiesWriteable();
const topUrl = extractProtocolHost(getRefererInfo().referer);
const domain = extractProtocolHost(document.location.href, true);
Expand All @@ -78,7 +79,8 @@ function callCriteoUserSync(parsedCriteoData) {
domain,
parsedCriteoData.bundle,
cw,
isPublishertagPresent
isPublishertagPresent,
gdprString
);

ajax.ajaxBuilder()(
Expand Down Expand Up @@ -119,11 +121,16 @@ export const criteoIdSubmodule = {
/**
* get the Criteo Id from local storages and initiate a new user sync
* @function
* @param {SubmoduleParams} [configParams]
* @param {ConsentData} [consentData]
* @returns {{id: {criteoId: string} | undefined}}}
*/
getId() {
getId(configParams, consentData) {
const hasGdprData = consentData && typeof consentData.gdprApplies === 'boolean' && consentData.gdprApplies;
const gdprConsentString = hasGdprData ? consentData.consentString : undefined;

let localData = getCriteoDataFromAllStorages();
callCriteoUserSync(localData);
callCriteoUserSync(localData, gdprConsentString);

return { id: localData.bidId ? { criteoId: localData.bidId } : undefined }
}
Expand Down
22 changes: 22 additions & 0 deletions test/spec/modules/criteoIdSystem_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,4 +132,26 @@ describe('CriteoId module', function () {
}
});
}));

const gdprConsentTestCases = [
{ consentData: { gdprApplies: true, consentString: 'expectedConsentString' }, expected: 'expectedConsentString' },
{ consentData: { gdprApplies: false, consentString: 'expectedConsentString' }, expected: undefined },
{ consentData: { gdprApplies: true, consentString: undefined }, expected: undefined },
{ consentData: { gdprApplies: 'oui', consentString: 'expectedConsentString' }, expected: undefined },
{ consentData: undefined, expected: undefined }
];

gdprConsentTestCases.forEach(testCase => it('should call user sync url with the gdprConsent', function () {
const emptyObj = '{}';
let ajaxStub = sinon.stub().callsFake((url, callback) => callback(emptyObj));
ajaxBuilderStub.callsFake(mockResponse(undefined, ajaxStub))

criteoIdSubmodule.getId(undefined, testCase.consentData);

if (testCase.expected) {
expect(ajaxStub.calledWithMatch(`gdprString=${testCase.expected}`)).to.be.true;
} else {
expect(ajaxStub.calledWithMatch('gdprString')).not.to.be.true;
}
}));
});