Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Criteo bid adapter: add video outstream renderer #9955

Merged
merged 1 commit into from
May 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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