Skip to content

Commit c281fc7

Browse files
Criteo adapter: add onDataDeletionRequest method (#10236)
Add support of US Privacy data deletion request method.
1 parent bb24bdb commit c281fc7

File tree

2 files changed

+49
-3
lines changed

2 files changed

+49
-3
lines changed

modules/criteoBidAdapter.js

+18
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { getRefererInfo } from '../src/refererDetection.js';
1010
import { hasPurpose1Consent } from '../src/utils/gpdr.js';
1111
import { Renderer } from '../src/Renderer.js';
1212
import { OUTSTREAM } from '../src/video.js';
13+
import { ajax } from '../src/ajax.js';
1314

1415
const GVLID = 91;
1516
export const ADAPTER_VERSION = 36;
@@ -306,6 +307,23 @@ export const spec = {
306307
adapter.handleSetTargeting(bid);
307308
}
308309
},
310+
311+
/**
312+
* @param {BidRequest[]} bidRequests
313+
*/
314+
onDataDeletionRequest: (bidRequests) => {
315+
const id = readFromAllStorages(BUNDLE_COOKIE_NAME);
316+
if (id) {
317+
deleteFromAllStorages(BUNDLE_COOKIE_NAME);
318+
}
319+
ajax('https://privacy.criteo.com/api/privacy/datadeletionrequest',
320+
null,
321+
JSON.stringify({ publisherUserId: id }),
322+
{
323+
contentType: 'application/json',
324+
method: 'POST'
325+
});
326+
}
309327
};
310328

311329
function readFromAllStorages(name) {

test/spec/modules/criteoBidAdapter_spec.js

+31-3
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ import {
99
} from 'modules/criteoBidAdapter.js';
1010
import * as utils from 'src/utils.js';
1111
import * as refererDetection from 'src/refererDetection.js';
12+
import * as ajax from 'src/ajax.js';
1213
import { config } from '../../../src/config.js';
1314
import { BANNER, NATIVE, VIDEO } from '../../../src/mediaTypes.js';
1415

1516
describe('The Criteo bidding adapter', function () {
16-
let utilsMock, sandbox;
17+
let utilsMock, sandbox, ajaxStub;
1718

1819
beforeEach(function () {
1920
$$PREBID_GLOBAL$$.bidderSettings = {
@@ -26,13 +27,15 @@ describe('The Criteo bidding adapter', function () {
2627
utilsMock = sinon.mock(utils);
2728

2829
sandbox = sinon.sandbox.create();
30+
ajaxStub = sandbox.stub(ajax, 'ajax');
2931
});
3032

3133
afterEach(function () {
3234
$$PREBID_GLOBAL$$.bidderSettings = {};
3335
global.Criteo = undefined;
3436
utilsMock.restore();
3537
sandbox.restore();
38+
ajaxStub.restore();
3639
});
3740

3841
describe('getUserSyncs', function () {
@@ -56,7 +59,9 @@ describe('The Criteo bidding adapter', function () {
5659
cookiesAreEnabledStub,
5760
localStorageIsEnabledStub,
5861
getCookieStub,
59-
getDataFromLocalStorageStub;
62+
setCookieStub,
63+
getDataFromLocalStorageStub,
64+
removeDataFromLocalStorageStub;
6065

6166
beforeEach(function () {
6267
getConfigStub = sinon.stub(config, 'getConfig');
@@ -75,8 +80,10 @@ describe('The Criteo bidding adapter', function () {
7580
localStorageIsEnabledStub = sinon.stub(storage, 'localStorageIsEnabled');
7681
localStorageIsEnabledStub.returns(true);
7782

78-
getCookieStub = sinon.stub(storage, 'getCookie')
83+
getCookieStub = sinon.stub(storage, 'getCookie');
84+
setCookieStub = sinon.stub(storage, 'setCookie');
7985
getDataFromLocalStorageStub = sinon.stub(storage, 'getDataFromLocalStorage');
86+
removeDataFromLocalStorageStub = sinon.stub(storage, 'removeDataFromLocalStorage');
8087
});
8188

8289
afterEach(function () {
@@ -86,7 +93,9 @@ describe('The Criteo bidding adapter', function () {
8693
cookiesAreEnabledStub.restore();
8794
localStorageIsEnabledStub.restore();
8895
getCookieStub.restore();
96+
setCookieStub.restore();
8997
getDataFromLocalStorageStub.restore();
98+
removeDataFromLocalStorageStub.restore();
9099
});
91100

92101
it('should not trigger sync if publisher is using fast bid', function () {
@@ -198,6 +207,25 @@ describe('The Criteo bidding adapter', function () {
198207
url: `https://gum.criteo.com/syncframe?origin=criteoPrebidAdapter&topUrl=www.abc.com&us_privacy=ABC#${JSON.stringify(expectedHash).replace(/"/g, '%22')}`
199208
}]);
200209
});
210+
211+
it('should delete user data when calling onDataDeletionRequest', () => {
212+
const cookieData = {
213+
'cto_bundle': 'a'
214+
};
215+
const lsData = {
216+
'cto_bundle': 'a'
217+
}
218+
getCookieStub.callsFake(cookieName => cookieData[cookieName]);
219+
setCookieStub.callsFake((cookieName, value, expires) => cookieData[cookieName] = value);
220+
removeDataFromLocalStorageStub.callsFake(name => lsData[name] = '');
221+
spec.onDataDeletionRequest([]);
222+
expect(getCookieStub.calledOnce).to.equal(true);
223+
expect(setCookieStub.calledOnce).to.equal(true);
224+
expect(removeDataFromLocalStorageStub.calledOnce).to.equal(true);
225+
expect(cookieData.cto_bundle).to.equal('');
226+
expect(lsData.cto_bundle).to.equal('');
227+
expect(ajaxStub.calledOnce).to.equal(true);
228+
});
201229
});
202230

203231
describe('isBidRequestValid', function () {

0 commit comments

Comments
 (0)