From 645a5496846652541a5c18bf1f1c95792e435999 Mon Sep 17 00:00:00 2001 From: "v.raybaud" Date: Wed, 26 Apr 2023 15:10:25 +0200 Subject: [PATCH] Criteo bid adapter: Add video outstream renderer --- modules/criteoBidAdapter.js | 41 +++++++++++++++++++- test/spec/modules/criteoBidAdapter_spec.js | 45 ++++++++++++++++++++++ 2 files changed, 84 insertions(+), 2 deletions(-) diff --git a/modules/criteoBidAdapter.js b/modules/criteoBidAdapter.js index edb718ec953..a2a095878ad 100644 --- a/modules/criteoBidAdapter.js +++ b/modules/criteoBidAdapter.js @@ -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; @@ -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='; @@ -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; } @@ -252,7 +261,6 @@ export const spec = { return bids; }, - /** * @param {TimedOutBid} timeoutData */ @@ -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 { diff --git a/test/spec/modules/criteoBidAdapter_spec.js b/test/spec/modules/criteoBidAdapter_spec.js index d88e70a6cdc..c9f3219e5a3 100755 --- a/test/spec/modules/criteoBidAdapter_spec.js +++ b/test/spec/modules/criteoBidAdapter_spec.js @@ -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: {