Skip to content

Commit

Permalink
Added 'ceh' config property in Criteo bid adapter (prebid#3969)
Browse files Browse the repository at this point in the history
* Added 'ceh' config property and mapped it to CDB request

Added 'ceh' config property and mapped it to CDB request

* Added config.resetConfig() to ensure that call to setConfig won't have an impact on any other test

* Missed the ';'
  • Loading branch information
leonardlabat authored and sa1omon committed Nov 28, 2019
1 parent 3fdc91d commit 3252a7f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 1 deletion.
9 changes: 8 additions & 1 deletion modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import * as utils from '../src/utils';
import find from 'core-js/library/fn/array/find';
import JSEncrypt from 'jsencrypt/bin/jsencrypt';
import sha256 from 'crypto-js/sha256';
import { config } from '../src/config';

const ADAPTER_VERSION = 16;
const ADAPTER_VERSION = 17;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = '//bidder.criteo.com/cdb';
const CRITEO_VENDOR_ID = 91;
Expand Down Expand Up @@ -47,6 +48,8 @@ export const spec = {
let url;
let data;

Object.assign(bidderRequest, { ceh: config.getConfig('criteo.ceh') });

// If publisher tag not already loaded try to get it from fast bid
if (!publisherTagAvailable()) {
window.Criteo = window.Criteo || {};
Expand Down Expand Up @@ -239,6 +242,10 @@ function buildCdbRequest(context, bidRequests, bidderRequest) {
if (networkId) {
request.publisher.networkid = networkId;
}
request.user = {};
if (bidderRequest && bidderRequest.ceh) {
request.user.ceh = bidderRequest.ceh;
}
if (bidderRequest && bidderRequest.gdprConsent) {
request.gdprConsent = {};
if (typeof bidderRequest.gdprConsent.gdprApplies !== 'undefined') {
Expand Down
10 changes: 10 additions & 0 deletions modules/criteoBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,13 @@ Module that connects to Criteo's demand sources.
}
];
```

# Additional Config (Optional)
Set the "ceh" property to provides the user's hashed email if available
```
pbjs.setConfig({
criteo: {
ceh: 'hashed mail'
}
});
```
28 changes: 28 additions & 0 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ import { cryptoVerify, spec, FAST_BID_PUBKEY } from 'modules/criteoBidAdapter';
import { createBid } from 'src/bidfactory';
import CONSTANTS from 'src/constants.json';
import * as utils from 'src/utils';
import { config } from '../../../src/config';

describe('The Criteo bidding adapter', function () {
beforeEach(function () {
// Remove FastBid to avoid side effects.
localStorage.removeItem('criteo_fast_bid');
});

describe('isBidRequestValid', function () {
it('should return false when given an invalid bid', function () {
const bid = {
Expand Down Expand Up @@ -66,6 +68,10 @@ describe('The Criteo bidding adapter', function () {
},
};

afterEach(function () {
config.resetConfig();
});

it('should properly build a zoneId request', function () {
const bidRequests = [
{
Expand Down Expand Up @@ -198,6 +204,28 @@ describe('The Criteo bidding adapter', function () {
expect(ortbRequest.gdprConsent.gdprApplies).to.equal(undefined);
expect(ortbRequest.gdprConsent.consentGiven).to.equal(undefined);
});

it('should properly build a request with ceh', function () {
const bidRequests = [
{
bidder: 'criteo',
adUnitCode: 'bid-123',
transactionId: 'transaction-123',
sizes: [[728, 90]],
params: {
zoneId: 123,
},
},
];
config.setConfig({
criteo: {
ceh: 'hashedemail'
}
});
const request = spec.buildRequests(bidRequests, bidderRequest);
expect(request.data.user).to.not.be.null;
expect(request.data.user.ceh).to.equal('hashedemail');
});
});

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

0 comments on commit 3252a7f

Please sign in to comment.