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

Adform adapter: add renderer for outstream bids #4363

Merged
merged 1 commit into from
Oct 29, 2019
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
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') {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mike-chowla this if-test should have an extra condition: type === VIDEO

if (!bid.renderer && utils.deepAccess(bid, 'mediaTypes.video.context') === 'outstream' && type === VIDEO)

if you have a placement that has other mediaTypes (banner,native) than outstream it will add the rendrer either way, and cause the ad rendring to fail.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bratrahim it might be you that added this code and not @mike-chowla?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MonokkelFredrik You're right, that was me. Will prepare a pull request

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