Skip to content

Commit

Permalink
Only send OpenX BO beacon once per page load (#2484)
Browse files Browse the repository at this point in the history
  • Loading branch information
haohany authored and jsnellbaker committed May 3, 2018
1 parent 59db2fe commit e247211
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
31 changes: 15 additions & 16 deletions modules/openxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ const BIDDER_CODE = 'openx';
const BIDDER_CONFIG = 'hb_pb';
const BIDDER_VERSION = '2.1.0';

let shouldSendBoPixel = true;
export function resetBoPixel() {
shouldSendBoPixel = true;
}

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: SUPPORTED_AD_TYPES,
Expand Down Expand Up @@ -63,11 +68,6 @@ function isVideoRequest(bidRequest) {
function createBannerBidResponses(oxResponseObj, {bids, startTime}) {
let adUnits = oxResponseObj.ads.ad;
let bidResponses = [];
let shouldSendBoPixel = bids[0].params.sendBoPixel;
if (shouldSendBoPixel === undefined) {
// Not specified, default to turned on
shouldSendBoPixel = true;
}
for (let i = 0; i < adUnits.length; i++) {
let adUnit = adUnits[i];
let adUnitIdx = parseInt(adUnit.idx, 10);
Expand Down Expand Up @@ -103,10 +103,9 @@ function createBannerBidResponses(oxResponseObj, {bids, startTime}) {
}
bidResponse.ts = adUnit.ts;

if (shouldSendBoPixel && adUnit.ts) {
registerBeacon(BANNER, adUnit, startTime);
}
bidResponses.push(bidResponse);

registerBeacon(BANNER, adUnit, startTime);
}
return bidResponses;
}
Expand Down Expand Up @@ -300,11 +299,6 @@ function generateVideoParameters(bid) {
}

function createVideoBidResponses(response, {bid, startTime}) {
let shouldSendBoPixel = bid.params.sendBoPixel;
if (shouldSendBoPixel === undefined) {
// Not specified, default to turned on
shouldSendBoPixel = true;
}
let bidResponses = [];

if (response !== undefined && response.vastUrl !== '' && response.pub_rev !== '') {
Expand All @@ -329,16 +323,21 @@ function createVideoBidResponses(response, {bid, startTime}) {
response.colo = vastQueryParams.colo;
response.ts = vastQueryParams.ts;

if (shouldSendBoPixel && response.ts) {
registerBeacon(VIDEO, response, startTime)
}
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) {
Expand Down
4 changes: 3 additions & 1 deletion test/spec/modules/openxBidAdapter_spec.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect} from 'chai';
import {spec} from 'modules/openxBidAdapter';
import {spec, resetBoPixel} from 'modules/openxBidAdapter';
import {newBidder} from 'src/adapters/bidderFactory';
import {userSync} from 'src/userSync';
import * as utils from 'src/utils';
Expand Down Expand Up @@ -586,6 +586,7 @@ describe('OpenxAdapter', () => {
});

it('should register a beacon', () => {
resetBoPixel();
spec.interpretResponse({body: bidResponse}, bidRequest);
sinon.assert.calledWith(userSync.registerSync, 'image', 'openx', sinon.match(new RegExp(`\/\/openx-d\.openx\.net.*\/bo\?.*ts=${adUnitOverride.ts}`)));
});
Expand Down Expand Up @@ -882,6 +883,7 @@ describe('OpenxAdapter', () => {
});

it('should register a beacon', () => {
resetBoPixel();
spec.interpretResponse({body: bidResponse}, bidRequestsWithMediaTypes);
sinon.assert.calledWith(userSync.registerSync, 'image', 'openx', sinon.match(/^\/\/test-colo\.com/))
sinon.assert.calledWith(userSync.registerSync, 'image', 'openx', sinon.match(/ph=test-ph/));
Expand Down

0 comments on commit e247211

Please sign in to comment.