Skip to content

Commit

Permalink
Audience Network: Add 'pbv' and 'cb' query params (#2252)
Browse files Browse the repository at this point in the history
* 'pbv' is for the Prebid version to aid with debugging
* 'cb' is for a Safari-only cachebuster
  • Loading branch information
lovell authored and mike-chowla committed Mar 17, 2018
1 parent 717b439 commit 7d10bc7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
9 changes: 7 additions & 2 deletions modules/audienceNetworkBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import { registerBidder } from 'src/adapters/bidderFactory';
import { config } from 'src/config';
import { formatQS } from 'src/url';
import { getTopWindowUrl } from 'src/utils';
import { generateUUID, getTopWindowUrl, isSafariBrowser } from 'src/utils';
import findIndex from 'core-js/library/fn/array/find-index';
import includes from 'core-js/library/fn/array/includes';

Expand All @@ -15,6 +15,7 @@ const url = 'https://an.facebook.com/v2/placementbid.json';
const supportedMediaTypes = ['banner', 'video'];
const netRevenue = true;
const hb_bidder = 'fan';
const pbv = '$prebid.version$';

/**
* Does this bid request contain valid parameters?
Expand Down Expand Up @@ -164,12 +165,16 @@ const buildRequests = bids => {
adformats,
testmode,
pageurl,
sdk
sdk,
pbv
};
const video = findIndex(adformats, isVideo);
if (video !== -1) {
[search.playerwidth, search.playerheight] = expandSize(sizes[video]);
}
if (isSafariBrowser()) {
search.cb = generateUUID();
}
const data = formatQS(search);

return [{ adformats, data, method, requestIds, sizes, url }];
Expand Down
29 changes: 25 additions & 4 deletions test/spec/modules/audienceNetworkBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const placementId = 'test-placement-id';
const playerwidth = 320;
const playerheight = 180;
const requestId = 'test-request-id';
const pbv = '$prebid.version$';

describe('AudienceNetwork adapter', () => {
describe('Public API', () => {
Expand Down Expand Up @@ -128,7 +129,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['300x250'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=300x250&testmode=false&pageurl=&sdk[]=5.5.web'
data: `placementids[]=test-placement-id&adformats[]=300x250&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

Expand All @@ -147,7 +148,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['640x480'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=video&testmode=false&pageurl=&sdk[]=&playerwidth=640&playerheight=480'
data: `placementids[]=test-placement-id&adformats[]=video&testmode=false&pageurl=&sdk[]=&pbv=${pbv}&playerwidth=640&playerheight=480`
}]);
});

Expand All @@ -166,7 +167,7 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['728x90'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=native&testmode=false&pageurl=&sdk[]=5.5.web'
data: `placementids[]=test-placement-id&adformats[]=native&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

Expand All @@ -185,9 +186,29 @@ describe('AudienceNetwork adapter', () => {
requestIds: [requestId],
sizes: ['300x250'],
url: 'https://an.facebook.com/v2/placementbid.json',
data: 'placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=&sdk[]=5.5.web'
data: `placementids[]=test-placement-id&adformats[]=fullwidth&testmode=false&pageurl=&sdk[]=5.5.web&pbv=${pbv}`
}]);
});

it('can build URL on Safari that includes a cachebuster param', () => {
const { userAgent } = navigator;
Object.defineProperty(navigator, 'userAgent', {
value: 'safari',
writable: true
});

expect(buildRequests([{
bidder,
bidId: requestId,
sizes: [[300, 250]],
params: { placementId }
}])[0].data).to.contain('&cb=');

Object.defineProperty(navigator, 'userAgent', {
value: userAgent,
writable: false
});
});
});

describe('interpretResponse', () => {
Expand Down

0 comments on commit 7d10bc7

Please sign in to comment.