Skip to content

Commit

Permalink
Criteo - partially restore adapter before PR #4518 following performa…
Browse files Browse the repository at this point in the history
…nce issues (#5376)

* Criteo - partially restore adapter before PR #4518 following performance issues

* Criteo - Fix error in onTimeout callback

* Apply review feedback (compatibility with IE)

* Feedback review (check that input is a valid array)
  • Loading branch information
leonardlabat authored Jul 8, 2020
1 parent 66d9e77 commit 3920e1a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
23 changes: 13 additions & 10 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { verify } from 'criteo-direct-rsa-validate/build/verify.js';
import { getStorageManager } from '../src/storageManager.js';

const GVLID = 91;
export const ADAPTER_VERSION = 31;
export const ADAPTER_VERSION = 32;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const PROFILE_ID_INLINE = 207;
Expand Down Expand Up @@ -156,18 +156,24 @@ export const spec = {
* @param {TimedOutBid} timeoutData
*/
onTimeout: (timeoutData) => {
if (publisherTagAvailable()) {
// eslint-disable-next-line no-undef
const adapter = Criteo.PubTag.Adapters.Prebid.GetAdapter(timeoutData.auctionId);
adapter.handleBidTimeout();
if (publisherTagAvailable() && Array.isArray(timeoutData)) {
var auctionsIds = [];
timeoutData.forEach((bid) => {
if (auctionsIds.indexOf(bid.auctionId) === -1) {
auctionsIds.push(bid.auctionId);
// eslint-disable-next-line no-undef
const adapter = Criteo.PubTag.Adapters.Prebid.GetAdapter(bid.auctionId);
adapter.handleBidTimeout();
}
});
}
},

/**
* @param {Bid} bid
*/
onBidWon: (bid) => {
if (publisherTagAvailable()) {
if (publisherTagAvailable() && bid) {
// eslint-disable-next-line no-undef
const adapter = Criteo.PubTag.Adapters.Prebid.GetAdapter(bid.auctionId);
adapter.handleBidWon(bid);
Expand Down Expand Up @@ -471,10 +477,7 @@ export function tryGetCriteoFastBid() {

if (verify(publisherTag, publisherTagHash, FAST_BID_PUBKEY_N, FAST_BID_PUBKEY_E)) {
utils.logInfo('Using Criteo FastBid');
const script = document.createElement('script');
script.type = 'text/javascript';
script.text = publisherTag;
utils.insertElement(script);
eval(publisherTag); // eslint-disable-line no-eval
} else {
utils.logWarn('Invalid Criteo FastBid found');
storage.removeDataFromLocalStorage(fastBidStorageKey);
Expand Down
5 changes: 2 additions & 3 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1173,7 +1173,6 @@ describe('The Criteo bidding adapter', function () {
utilsMock.expects('logInfo').withExactArgs('Using Criteo FastBid').once();
utilsMock.expects('logWarn').withExactArgs('No hash found in FastBid').never();
utilsMock.expects('logWarn').withExactArgs('Invalid Criteo FastBid found').never();
utilsMock.expects('insertElement').once();

tryGetCriteoFastBid();

Expand Down Expand Up @@ -1419,14 +1418,14 @@ describe('The Criteo bidding adapter', function () {
});

it('should forward bid to pubtag when calling onTimeout', () => {
const timeoutData = { auctionId: 123 };
const timeoutData = [{ auctionId: 123 }];

const adapter = { handleBidTimeout: function() {} };
const adapterMock = sinon.mock(adapter);
adapterMock.expects('handleBidTimeout').once();
const prebidAdapter = { GetAdapter: function() {} };
const prebidAdapterMock = sinon.mock(prebidAdapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(timeoutData.auctionId).once().returns(adapter);
prebidAdapterMock.expects('GetAdapter').withExactArgs(timeoutData[0].auctionId).once().returns(adapter);

global.Criteo = {
PubTag: {
Expand Down

0 comments on commit 3920e1a

Please sign in to comment.