From 3dab9a4a3bfbaba1f5f79f380a730c7c48c0bc7c Mon Sep 17 00:00:00 2001 From: Lovell Fuller Date: Fri, 9 Mar 2018 21:32:49 +0000 Subject: [PATCH] Audience Network: Add 'pbv' and 'cb' query params * 'pbv' is for the Prebid version to aid with debugging * 'cb' is for a Safari-only cachebuster --- modules/audienceNetworkBidAdapter.js | 9 ++++-- .../modules/audienceNetworkBidAdapter_spec.js | 29 ++++++++++++++++--- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/modules/audienceNetworkBidAdapter.js b/modules/audienceNetworkBidAdapter.js index ed78f336102..263edba878a 100644 --- a/modules/audienceNetworkBidAdapter.js +++ b/modules/audienceNetworkBidAdapter.js @@ -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'; @@ -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? @@ -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 }]; diff --git a/test/spec/modules/audienceNetworkBidAdapter_spec.js b/test/spec/modules/audienceNetworkBidAdapter_spec.js index d92597c913c..7626780afb3 100644 --- a/test/spec/modules/audienceNetworkBidAdapter_spec.js +++ b/test/spec/modules/audienceNetworkBidAdapter_spec.js @@ -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', () => { @@ -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}` }]); }); @@ -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` }]); }); @@ -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}` }]); }); @@ -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', () => {