Skip to content

Commit

Permalink
Criteo : added first party data mapping to bidder request
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardlabat committed Apr 2, 2020
1 parent d88e808 commit 67f0b5d
Show file tree
Hide file tree
Showing 2 changed files with 129 additions and 4 deletions.
19 changes: 16 additions & 3 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
import { getStorageManager } from '../src/storageManager.js';

const GVLID = 91;
export const ADAPTER_VERSION = 26;
export const ADAPTER_VERSION = 27;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const CRITEO_VENDOR_ID = 91;
Expand Down Expand Up @@ -58,7 +58,11 @@ export const spec = {
let url;
let data;

Object.assign(bidderRequest, { ceh: config.getConfig('criteo.ceh') });
Object.assign(bidderRequest, {
publisherExt: config.getConfig('fpd.context'),
userExt: config.getConfig('fpd.user'),
ceh: config.getConfig('criteo.ceh')
});

// If publisher tag not already loaded try to get it from fast bid
if (!publisherTagAvailable()) {
Expand Down Expand Up @@ -252,6 +256,7 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
const request = {
publisher: {
url: context.url,
ext: bidderRequest.publisherExt
},
slots: bidRequests.map(bidRequest => {
networkId = bidRequest.params.networkId || networkId;
Expand All @@ -264,6 +269,12 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (bidRequest.params.zoneId) {
slot.zoneid = bidRequest.params.zoneId;
}
if (bidRequest.fpd && bidRequest.fpd.context) {
slot.ext = bidRequest.fpd.context;
}
if (bidRequest.params.ext) {
slot.ext = Object.assign({}, slot.ext, bidRequest.params.ext);
}
if (bidRequest.params.publisherSubId) {
slot.publishersubid = bidRequest.params.publisherSubId;
}
Expand Down Expand Up @@ -293,7 +304,9 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (networkId) {
request.publisher.networkid = networkId;
}
request.user = {};
request.user = {
ext: bidderRequest.userExt
};
if (bidderRequest && bidderRequest.ceh) {
request.user.ceh = bidderRequest.ceh;
}
Expand Down
114 changes: 113 additions & 1 deletion test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,20 @@ import { config } from '../../../src/config.js';
import { NATIVE, VIDEO } from '../../../src/mediaTypes.js';

describe('The Criteo bidding adapter', function () {
let utilsMock;
let utilsMock, sandbox;

beforeEach(function () {
// Remove FastBid to avoid side effects
localStorage.removeItem('criteo_fast_bid');
utilsMock = sinon.mock(utils);

sandbox = sinon.sandbox.create();
});

afterEach(function() {
global.Criteo = undefined;
utilsMock.restore();
sandbox.restore();
});

describe('isBidRequestValid', function () {
Expand Down Expand Up @@ -705,6 +708,115 @@ describe('The Criteo bidding adapter', function () {
expect(request.data.user).to.not.be.null;
expect(request.data.user.ceh).to.equal('hashedemail');
});

it('should properly build a request without first party data', function () {
const bidRequests = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123
}
},
];

sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
};
return utils.deepAccess(config, key);
});

const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.publisher.ext).to.equal(undefined);
expect(request.data.user.ext).to.equal(undefined);
expect(request.data.slots[0].ext).to.equal(undefined);
});

it('should properly build a request with criteo specific ad unit first party data', function () {
const bidRequests = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123,
ext: {
bidfloor: 0.75
}
}
},
];

sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
};
return utils.deepAccess(config, key);
});

const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.slots[0].ext).to.deep.equal({
bidfloor: 0.75,
});
});

it('should properly build a request with first party data', function () {
const contextData = {
keywords: ['power tools'],
data: {
pageType: 'article'
}
};
const userData = {
gender: 'M',
data: {
registered: true
}
};
const bidRequests = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123,
ext: {
bidfloor: 0.75
}
},
fpd: {
context: {
data: {
someContextAttribute: 'abc'
}
}
}
},
];

sandbox.stub(config, 'getConfig').callsFake(key => {
const config = {
fpd: {
context: contextData,
user: userData
}
};
return utils.deepAccess(config, key);
});

const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.publisher.ext).to.deep.equal(contextData);
expect(request.data.user.ext).to.deep.equal(userData);
expect(request.data.slots[0].ext).to.deep.equal({
bidfloor: 0.75,
data: {
someContextAttribute: 'abc'
}
});
});
});

describe('interpretResponse', function () {
Expand Down

0 comments on commit 67f0b5d

Please sign in to comment.