Skip to content

Commit

Permalink
Adform adapter: add renderer for outstream bids (#4363)
Browse files Browse the repository at this point in the history
  • Loading branch information
bratrahim authored and Mike Chowla committed Oct 29, 2019
1 parent be48754 commit dcdd457
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
20 changes: 18 additions & 2 deletions modules/adformBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use strict';

import {registerBidder} from '../src/adapters/bidderFactory';
import { registerBidder } from '../src/adapters/bidderFactory';
import { config } from '../src/config';
import { BANNER, VIDEO } from '../src/mediaTypes';
import { Renderer } from '../src/Renderer';
import * as utils from '../src/utils';

const OUTSTREAM_RENDERER_URL = 'https://s2.adform.net/banners/scripts/video/outstream/render.js';

const BIDDER_CODE = 'adform';
export const spec = {
Expand All @@ -18,7 +22,7 @@ export const spec = {
var request = [];
var globalParams = [ [ 'adxDomain', 'adx.adform.net' ], [ 'fd', 1 ], [ 'url', null ], [ 'tid', null ] ];
var bids = JSON.parse(JSON.stringify(validBidRequests));
var bidder = (bids[0] && bids[0].bidder) || BIDDER_CODE
var bidder = (bids[0] && bids[0].bidder) || BIDDER_CODE;
for (i = 0, l = bids.length; i < l; i++) {
bid = bids[i];
if ((bid.params.priceType === 'net') || (bid.params.pt === 'net')) {
Expand Down Expand Up @@ -112,6 +116,12 @@ export const spec = {
vastXml: response.vast_content,
mediaType: type
};

if (!bid.renderer && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream') {
bidObject.renderer = Renderer.install({id: bid.bidId, url: OUTSTREAM_RENDERER_URL});
bidObject.renderer.setRender(renderer);
}

if (bidRequest.gdpr) {
bidObject.gdpr = bidRequest.gdpr.gdpr;
bidObject.gdpr_consent = bidRequest.gdpr.gdpr_consent;
Expand All @@ -121,6 +131,12 @@ export const spec = {
}
return bidRespones;

function renderer(bid) {
bid.renderer.push(() => {
window.Adform.renderOutstream(bid);
});
}

function verifySize(adItem, validSizes) {
for (var j = 0, k = validSizes.length; j < k; j++) {
if (adItem.width == validSizes[j][0] &&
Expand Down
9 changes: 9 additions & 0 deletions test/spec/modules/adformBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,13 @@ describe('Adform adapter', function () {
};
});

it('should set a renderer for an outstream context', function () {
serverResponse.body = [serverResponse.body[3]];
bidRequest.bids = [bidRequest.bids[6]];
let result = spec.interpretResponse(serverResponse, bidRequest);
assert.ok(result[0].renderer);
});

describe('verifySizes', function () {
it('should respond with empty response when sizes doesn\'t match', function () {
serverResponse.body[0].response = 'banner';
Expand Down Expand Up @@ -309,6 +316,7 @@ describe('Adform adapter', function () {

let sizes = [[250, 300], [300, 250], [300, 600]];
let placementCode = ['div-01', 'div-02', 'div-03', 'div-04', 'div-05'];
let mediaTypes = [{video: {context: 'outstream'}}];
let params = [{ mid: 1, url: 'some// there' }, {adxDomain: null, mid: 2, someVar: 'someValue', pt: 'gross'}, { adxDomain: null, mid: 3, pdom: 'home' }, {mid: 5, pt: 'net'}, {mid: 6, pt: 'gross'}];
bids = [
{
Expand Down Expand Up @@ -388,6 +396,7 @@ describe('Adform adapter', function () {
params: params[4],
placementCode: placementCode[2],
sizes: [],
mediaTypes: mediaTypes[0],
transactionId: '5f33781f-9552-7ev3'
}
];
Expand Down

0 comments on commit dcdd457

Please sign in to comment.