Skip to content

Commit

Permalink
OpenX Adapter: Prebid 3.0 Compatibility Update
Browse files Browse the repository at this point in the history
* Removed usage of deprecated functions
* Removed beacons
* Banner sizes now reads from bidRequest.mediaTypes.banner.sizes instead of bidRequest.sizes
* Updated tests to reflect changes.
  • Loading branch information
Jimmy Tu committed Nov 1, 2019
1 parent 4f9ee48 commit 42c7040
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 224 deletions.
73 changes: 4 additions & 69 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@
import {config} from '../src/config';
import {registerBidder} from '../src/adapters/bidderFactory';
import * as utils from '../src/utils';
import {userSync} from '../src/userSync';
import {BANNER, VIDEO} from '../src/mediaTypes';
import {parse} from '../src/url';

const SUPPORTED_AD_TYPES = [BANNER, VIDEO];
const BIDDER_CODE = 'openx';
const BIDDER_CONFIG = 'hb_pb';
const BIDDER_VERSION = '2.1.9';
const BIDDER_VERSION = '3.0.0';

const USER_ID_CODE_TO_QUERY_ARG = {
idl_env: 'lre', // liveramp
pubcid: 'pubcid', // publisher common id
tdid: 'ttduuid' // the trade desk
};

let shouldSendBoPixel = true;

export function resetBoPixel() {
shouldSendBoPixel = true;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_AD_TYPES,
Expand Down Expand Up @@ -132,24 +125,10 @@ function createBannerBidResponses(oxResponseObj, {bids, startTime}) {
}

bidResponses.push(bidResponse);

registerBeacon(BANNER, adUnit, startTime);
}
return bidResponses;
}

function buildQueryStringFromParams(params) {
for (let key in params) {
if (params.hasOwnProperty(key)) {
if (!params[key]) {
delete params[key];
}
}
}
return utils._map(Object.keys(params), key => `${key}=${params[key]}`)
.join('&');
}

function getViewportDimensions(isIfr) {
let width;
let height;
Expand Down Expand Up @@ -210,8 +189,7 @@ function buildCommonQueryParamsFromBids(bids, bidderRequest) {
let defaultParams;

defaultParams = {
ju: config.getConfig('pageUrl') || utils.getTopWindowUrl(),
jr: utils.getTopWindowReferrer(),
ju: config.getConfig('pageUrl') || bidderRequest.refererInfo.referer,
ch: document.charSet || document.characterSet,
res: `${screen.width}x${screen.height}x${screen.colorDepth}`,
ifr: isInIframe,
Expand Down Expand Up @@ -285,7 +263,8 @@ function buildOXBannerRequest(bids, bidderRequest) {
let hasCustomParam = false;
let queryParams = buildCommonQueryParamsFromBids(bids, bidderRequest);
let auids = utils._map(bids, bid => bid.params.unit);
queryParams.aus = utils._map(bids, bid => utils.parseSizesInput(bid.sizes).join(',')).join('|');

queryParams.aus = utils._map(bids, bid => utils.parseSizesInput(bid.mediaTypes.banner.sizes).join(',')).join('|');
queryParams.divIds = utils._map(bids, bid => encodeURIComponent(bid.adUnitCode)).join(',');

if (auids.some(auid => auid)) {
Expand Down Expand Up @@ -425,53 +404,9 @@ function createVideoBidResponses(response, {bid, startTime}) {
response.ts = vastQueryParams.ts;

bidResponses.push(bidResponse);

registerBeacon(VIDEO, response, startTime)
}

return bidResponses;
}

function registerBeacon(mediaType, adUnit, startTime) {
// only register beacon once
if (!shouldSendBoPixel) {
return;
}
shouldSendBoPixel = false;

let bt = config.getConfig('bidderTimeout');
let beaconUrl;
if (window.PREBID_TIMEOUT) {
bt = Math.min(window.PREBID_TIMEOUT, bt);
}

let beaconParams = {
bd: +(new Date()) - startTime,
bp: adUnit.pub_rev,
br: '0', // may be 0, t, or p
bs: utils.getTopWindowLocation().hostname,
bt: bt,
ts: adUnit.ts
};

beaconParams.br = beaconParams.bt < beaconParams.bd ? 't' : 'p';

if (mediaType === VIDEO) {
let url = parse(adUnit.colo);
beaconParams.ph = adUnit.ph;
beaconUrl = `https://${url.hostname}/w/1.0/bo?${buildQueryStringFromParams(beaconParams)}`
} else {
let recordPixel = utils.deepAccess(adUnit, 'creative.0.tracking.impression');
let boBase = recordPixel.match(/([^?]+\/)ri\?/);

if (boBase && boBase.length > 1) {
beaconUrl = `${boBase[1]}bo?${buildQueryStringFromParams(beaconParams)}`;
}
}

if (beaconUrl) {
userSync.registerSync('image', BIDDER_CODE, beaconUrl);
}
}

registerBidder(spec);
7 changes: 3 additions & 4 deletions modules/openxoutstreamBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { BANNER } from '../src/mediaTypes';
const SUPPORTED_AD_TYPES = [BANNER];
const BIDDER_CODE = 'openxoutstream';
const BIDDER_CONFIG = 'hb_pb_ym';
const BIDDER_VERSION = '1.0.0';
const BIDDER_VERSION = '1.0.1';
const CURRENCY = 'USD';
const NET_REVENUE = true;
const TIME_TO_LIVE = 300;
Expand Down Expand Up @@ -70,8 +70,7 @@ function buildCommonQueryParamsFromBids(bid, bidderRequest) {
const width = '414';
const aus = '304x184%7C412x184%7C375x184%7C414x184';
defaultParams = {
ju: config.getConfig('pageUrl') || utils.getTopWindowUrl(),
jr: utils.getTopWindowReferrer(),
ju: config.getConfig('pageUrl') || bidderRequest.refererInfo.referer,
ch: document.charSet || document.characterSet,
res: `${screen.width}x${screen.height}x${screen.colorDepth}`,
ifr: isInIframe,
Expand Down Expand Up @@ -118,7 +117,7 @@ function buildOXBannerRequest(bid, bidderRequest) {
queryParams.tfcd = 1;
}

let url = `https://${bid.params.delDomain}/v/1.0/avjp`
let url = `https://${bid.params.delDomain}/v/1.0/avjp`;
return {
method: 'GET',
url: url,
Expand Down
Loading

0 comments on commit 42c7040

Please sign in to comment.