Skip to content

Commit b5d034a

Browse files
leonardlabatrjvelicaria
authored andcommitted
Criteo : added first party data mapping to bidder request (prebid#4954)
1 parent 5084fcf commit b5d034a

File tree

2 files changed

+129
-4
lines changed

2 files changed

+129
-4
lines changed

modules/criteoBidAdapter.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
99
import { getStorageManager } from '../src/storageManager.js';
1010

1111
const GVLID = 91;
12-
export const ADAPTER_VERSION = 26;
12+
export const ADAPTER_VERSION = 27;
1313
const BIDDER_CODE = 'criteo';
1414
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
1515
const CRITEO_VENDOR_ID = 91;
@@ -58,7 +58,11 @@ export const spec = {
5858
let url;
5959
let data;
6060

61-
Object.assign(bidderRequest, { ceh: config.getConfig('criteo.ceh') });
61+
Object.assign(bidderRequest, {
62+
publisherExt: config.getConfig('fpd.context'),
63+
userExt: config.getConfig('fpd.user'),
64+
ceh: config.getConfig('criteo.ceh')
65+
});
6266

6367
// If publisher tag not already loaded try to get it from fast bid
6468
if (!publisherTagAvailable()) {
@@ -252,6 +256,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
252256
const request = {
253257
publisher: {
254258
url: context.url,
259+
ext: bidderRequest.publisherExt
255260
},
256261
slots: bidRequests.map(bidRequest => {
257262
networkId = bidRequest.params.networkId || networkId;
@@ -264,6 +269,12 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
264269
if (bidRequest.params.zoneId) {
265270
slot.zoneid = bidRequest.params.zoneId;
266271
}
272+
if (bidRequest.fpd && bidRequest.fpd.context) {
273+
slot.ext = bidRequest.fpd.context;
274+
}
275+
if (bidRequest.params.ext) {
276+
slot.ext = Object.assign({}, slot.ext, bidRequest.params.ext);
277+
}
267278
if (bidRequest.params.publisherSubId) {
268279
slot.publishersubid = bidRequest.params.publisherSubId;
269280
}
@@ -293,7 +304,9 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
293304
if (networkId) {
294305
request.publisher.networkid = networkId;
295306
}
296-
request.user = {};
307+
request.user = {
308+
ext: bidderRequest.userExt
309+
};
297310
if (bidderRequest && bidderRequest.ceh) {
298311
request.user.ceh = bidderRequest.ceh;
299312
}

test/spec/modules/criteoBidAdapter_spec.js

Lines changed: 113 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,20 @@ import { config } from '../../../src/config.js';
77
import { NATIVE, VIDEO } from '../../../src/mediaTypes.js';
88

99
describe('The Criteo bidding adapter', function () {
10-
let utilsMock;
10+
let utilsMock, sandbox;
1111

1212
beforeEach(function () {
1313
// Remove FastBid to avoid side effects
1414
localStorage.removeItem('criteo_fast_bid');
1515
utilsMock = sinon.mock(utils);
16+
17+
sandbox = sinon.sandbox.create();
1618
});
1719

1820
afterEach(function() {
1921
global.Criteo = undefined;
2022
utilsMock.restore();
23+
sandbox.restore();
2124
});
2225

2326
describe('isBidRequestValid', function () {
@@ -705,6 +708,115 @@ describe('The Criteo bidding adapter', function () {
705708
expect(request.data.user).to.not.be.null;
706709
expect(request.data.user.ceh).to.equal('hashedemail');
707710
});
711+
712+
it('should properly build a request without first party data', function () {
713+
const bidRequests = [
714+
{
715+
bidder: 'criteo',
716+
adUnitCode: 'bid-123',
717+
transactionId: 'transaction-123',
718+
sizes: [[728, 90]],
719+
params: {
720+
zoneId: 123
721+
}
722+
},
723+
];
724+
725+
sandbox.stub(config, 'getConfig').callsFake(key => {
726+
const config = {
727+
};
728+
return utils.deepAccess(config, key);
729+
});
730+
731+
const request = spec.buildRequests(bidRequests, bidderRequest);
732+
expect(request.data.publisher.ext).to.equal(undefined);
733+
expect(request.data.user.ext).to.equal(undefined);
734+
expect(request.data.slots[0].ext).to.equal(undefined);
735+
});
736+
737+
it('should properly build a request with criteo specific ad unit first party data', function () {
738+
const bidRequests = [
739+
{
740+
bidder: 'criteo',
741+
adUnitCode: 'bid-123',
742+
transactionId: 'transaction-123',
743+
sizes: [[728, 90]],
744+
params: {
745+
zoneId: 123,
746+
ext: {
747+
bidfloor: 0.75
748+
}
749+
}
750+
},
751+
];
752+
753+
sandbox.stub(config, 'getConfig').callsFake(key => {
754+
const config = {
755+
};
756+
return utils.deepAccess(config, key);
757+
});
758+
759+
const request = spec.buildRequests(bidRequests, bidderRequest);
760+
expect(request.data.slots[0].ext).to.deep.equal({
761+
bidfloor: 0.75,
762+
});
763+
});
764+
765+
it('should properly build a request with first party data', function () {
766+
const contextData = {
767+
keywords: ['power tools'],
768+
data: {
769+
pageType: 'article'
770+
}
771+
};
772+
const userData = {
773+
gender: 'M',
774+
data: {
775+
registered: true
776+
}
777+
};
778+
const bidRequests = [
779+
{
780+
bidder: 'criteo',
781+
adUnitCode: 'bid-123',
782+
transactionId: 'transaction-123',
783+
sizes: [[728, 90]],
784+
params: {
785+
zoneId: 123,
786+
ext: {
787+
bidfloor: 0.75
788+
}
789+
},
790+
fpd: {
791+
context: {
792+
data: {
793+
someContextAttribute: 'abc'
794+
}
795+
}
796+
}
797+
},
798+
];
799+
800+
sandbox.stub(config, 'getConfig').callsFake(key => {
801+
const config = {
802+
fpd: {
803+
context: contextData,
804+
user: userData
805+
}
806+
};
807+
return utils.deepAccess(config, key);
808+
});
809+
810+
const request = spec.buildRequests(bidRequests, bidderRequest);
811+
expect(request.data.publisher.ext).to.deep.equal(contextData);
812+
expect(request.data.user.ext).to.deep.equal(userData);
813+
expect(request.data.slots[0].ext).to.deep.equal({
814+
bidfloor: 0.75,
815+
data: {
816+
someContextAttribute: 'abc'
817+
}
818+
});
819+
});
708820
});
709821

710822
describe('interpretResponse', function () {

0 commit comments

Comments
 (0)