From 4b5397f7efddff527c7aac6e2fd86af6610f7401 Mon Sep 17 00:00:00 2001 From: David M Date: Fri, 20 Jan 2017 14:37:49 -0800 Subject: [PATCH 1/2] GumGum adapter - set bid throttle by product --- src/adapters/gumgum.js | 44 +++++++++++++++++----- test/spec/adapters/gumgum_spec.js | 61 +++++++++++++++++++++---------- 2 files changed, 76 insertions(+), 29 deletions(-) diff --git a/src/adapters/gumgum.js b/src/adapters/gumgum.js index 7434444d570..f47cba5f3a6 100644 --- a/src/adapters/gumgum.js +++ b/src/adapters/gumgum.js @@ -13,6 +13,9 @@ const GumgumAdapter = function GumgumAdapter() { let topWindow; let topScreen; let pageViewId; + const requestCache = {}; + const throttleTable = {}; + const defaultThrottle = 3e4; try { topWindow = global.top; @@ -21,6 +24,10 @@ const GumgumAdapter = function GumgumAdapter() { return utils.logError(error); } + function _getTimeStamp() { + return new Date().getTime(); + } + function _callBids({ bids }) { const browserParams = { vw: topWindow.innerWidth, @@ -36,6 +43,7 @@ const GumgumAdapter = function GumgumAdapter() { , params = {} , placementCode } = bidRequest; + const timestamp = _getTimeStamp(); const trackingId = params.inScreen; const nativeId = params.native; const slotId = params.inSlot; @@ -52,6 +60,20 @@ const GumgumAdapter = function GumgumAdapter() { ', please check your implementation.' ); } + + /* throttle based on the latest request for this product */ + const productId = bid.pi; + const throttle = throttleTable[productId]; + const latestRequest = requestCache[productId]; + if (latestRequest && throttle && (timestamp - latestRequest) < throttle) { + return utils.logWarn( + `[GumGum] The refreshes for "${ placementCode }" with the params ` + + `${ JSON.stringify(params) } should be at least ${ throttle / 1e3 }s apart.` + ); + } + /* update the last request */ + requestCache[productId] = timestamp; + /* tracking id is required for in-image and in-screen */ if (trackingId) bid.t = trackingId; /* native ads require a native placement id */ @@ -75,26 +97,30 @@ const GumgumAdapter = function GumgumAdapter() { }); } - const _handleGumGumResponse = cachedBidRequest => bidResponse => { - const ad = bidResponse && bidResponse.ad; - const pag = bidResponse && bidResponse.pag; + const _handleGumGumResponse = cachedBidRequest => (bidResponse = {}) => { + const { pi: productId + } = cachedBidRequest; + const { ad = {} + , pag = {} + , thms: throttle + } = bidResponse; /* cache the pageViewId */ if (pag && pag.pvid) pageViewId = pag.pvid; - /* create the bid */ if (ad && ad.id) { + /* set the new throttle */ + throttleTable[productId] = throttle || defaultThrottle; + /* create the bid */ const bid = bidfactory.createBid(1); const { t: trackingId - , pi: productId - , placementCode - } = cachedBidRequest; - bidResponse.placementCode = placementCode; + } = pag; + bidResponse.request = cachedBidRequest; const encodedResponse = encodeURIComponent(JSON.stringify(bidResponse)); const gumgumAdLoader = `