Skip to content

Commit

Permalink
Criteo bid adapter: Add video outstream renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
v.raybaud committed May 16, 2023
1 parent 1e25e29 commit 645a549
Show file tree
Hide file tree
Showing 2 changed files with 84 additions and 2 deletions.
41 changes: 39 additions & 2 deletions modules/criteoBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,11 @@ import { verify } from 'criteo-direct-rsa-validate/build/verify.js'; // ref#2
import { getStorageManager } from '../src/storageManager.js';
import { getRefererInfo } from '../src/refererDetection.js';
import { hasPurpose1Consent } from '../src/utils/gpdr.js';
import { Renderer } from '../src/Renderer.js';
import { OUTSTREAM } from '../src/video.js';

const GVLID = 91;
export const ADAPTER_VERSION = 35;
export const ADAPTER_VERSION = 36;
const BIDDER_CODE = 'criteo';
const CDB_ENDPOINT = 'https://bidder.criteo.com/cdb';
const PROFILE_ID_INLINE = 207;
Expand All @@ -29,6 +32,7 @@ export const FAST_BID_VERSION_CURRENT = 135;
const FAST_BID_VERSION_LATEST = 'latest';
const FAST_BID_VERSION_NONE = 'none';
const PUBLISHER_TAG_URL_TEMPLATE = 'https://static.criteo.net/js/ld/publishertag.prebid' + FAST_BID_VERSION_PLACEHOLDER + '.js';
const PUBLISHER_TAG_OUTSTREAM_SRC = 'https://static.criteo.net/js/ld/publishertag.renderer.js'
const FAST_BID_PUBKEY_E = 65537;
const FAST_BID_PUBKEY_N = 'ztQYwCE5BU7T9CDM5he6rKoabstXRmkzx54zFPZkWbK530dwtLBDeaWBMxHBUT55CYyboR/EZ4efghPi3CoNGfGWezpjko9P6p2EwGArtHEeS4slhu/SpSIFMjG6fdrpRoNuIAMhq1Z+Pr/+HOd1pThFKeGFr2/NhtAg+TXAzaU=';

Expand Down Expand Up @@ -243,6 +247,11 @@ export const spec = {
} else if (slot.video) {
bid.vastUrl = slot.displayurl;
bid.mediaType = VIDEO;
const context = deepAccess(bidRequest, 'mediaTypes.video.context');
// if outstream video, add a default render for it.
if (context === OUTSTREAM) {
bid.renderer = createOutstreamVideoRenderer(slot);
}
} else {
bid.ad = slot.creative;
}
Expand All @@ -252,7 +261,6 @@ export const spec = {

return bids;
},

/**
* @param {TimedOutBid} timeoutData
*/
Expand Down Expand Up @@ -706,6 +714,35 @@ export function getFastBidUrl(fastBidVersion) {
return PUBLISHER_TAG_URL_TEMPLATE.replace(FAST_BID_VERSION_PLACEHOLDER, version);
}

function createOutstreamVideoRenderer(slot) {
if (slot.ext.videoPlayerConfig === undefined || slot.ext.videoPlayerType === undefined) {
return undefined;
}

const config = {
documentResolver: (bid, sourceDocument, renderDocument) => {
return renderDocument ?? sourceDocument;
}
}

const render = (bid, renderDocument) => {
let payload = {
slotid: slot.impid,
vastUrl: slot.displayurl,
vastXml: slot.creative,
documentContext: renderDocument,
};

let outstreamConfig = slot.ext.videoPlayerConfig;

window.CriteoOutStream[slot.ext.videoPlayerType].play(payload, outstreamConfig)
};

const renderer = Renderer.install({url: PUBLISHER_TAG_OUTSTREAM_SRC, config: config});
renderer.setRender(render);
return renderer;
}

export function tryGetCriteoFastBid() {
// begin ref#1
try {
Expand Down
45 changes: 45 additions & 0 deletions test/spec/modules/criteoBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1695,6 +1695,51 @@ describe('The Criteo bidding adapter', function () {
expect(bids[0].mediaType).to.equal(VIDEO);
});

it('should properly parse a bid response with a outstream video', function () {
const response = {
body: {
slots: [{
impid: 'test-requestId',
bidId: 'abc123',
cpm: 1.23,
displayurl: 'http://test-ad',
width: 728,
height: 90,
zoneid: 123,
video: true,
ext: {
videoPlayerType: 'RadiantMediaPlayer',
videoPlayerConfig: {

}
}
}],
},
};
const request = {
bidRequests: [{
adUnitCode: 'test-requestId',
bidId: 'test-bidId',
params: {
zoneId: 123,
},
mediaTypes: {
video: {
context: 'outstream'
}
}
}]
};
const bids = spec.interpretResponse(response, request);
expect(bids).to.have.lengthOf(1);
expect(bids[0].requestId).to.equal('test-bidId');
expect(bids[0].cpm).to.equal(1.23);
expect(bids[0].vastUrl).to.equal('http://test-ad');
expect(bids[0].renderer.url).to.equal('https://static.criteo.net/js/ld/publishertag.renderer.js');
expect(typeof bids[0].renderer.config.documentResolver).to.equal('function');
expect(typeof bids[0].renderer._render).to.equal('function');
});

it('should properly parse a bid response with native', function () {
const response = {
body: {
Expand Down

0 comments on commit 645a549

Please sign in to comment.