From 454ee44dc117d4af392af99c27213662da9882c7 Mon Sep 17 00:00:00 2001 From: Andrew Bowman Date: Tue, 20 Nov 2018 11:49:23 -0500 Subject: [PATCH 1/4] updating appnexus debug auction to be cookie-only --- modules/appnexusBidAdapter.js | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index cc0cac579da..9a52964a004 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -11,6 +11,7 @@ const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration', 'startdelay', 'skippable', 'playback_method', 'frameworks']; const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language']; const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately +const DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout']; const NATIVE_MAPPING = { body: 'description', cta: 'ctatext', @@ -77,6 +78,25 @@ export const spec = { }; } + let debugObj = {}; + let debugObjParams = {}; + const debugCookieName = 'apn_prebid_debug'; + const debugCookie = getCookie(debugCookieName) || null; + if (debugCookie) { + try { + debugObj = JSON.parse(debugCookie); + } catch (e) { + utils.logError('AppNexus Debug Auction Cookie Error:\n\n' + e); + } + } + if (debugObj && debugObj.enabled) { + Object.keys(debugObj) + .filter(param => includes(DEBUG_PARAMS, param)) + .forEach(param => { + debugObjParams[param] = debugObj[param]; + }); + } + const memberIdBid = find(bidRequests, hasMemberId); const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0; @@ -99,6 +119,11 @@ export const spec = { payload.app = appIdObj; } + if (debugObjParams.enabled) { + payload.debug = debugObjParams; + utils.logInfo('AppNexus Debug Auction Settings:\n\n' + JSON.stringify(debugObjParams, null, 4)); + } + if (bidderRequest && bidderRequest.gdprConsent) { // note - objects for impbus use underscore instead of camelCase payload.gdpr_consent = { @@ -154,6 +179,22 @@ export const spec = { } }); } + + if (serverResponse.debug && serverResponse.debug.debug_info) { + let debugHeader = 'AppNexus Debug Auction for Prebid\n\n' + let debugText = debugHeader + serverResponse.debug.debug_info + debugText = debugText + .replace(/(|)/gm, '\t') // Tables + .replace(/(<\/td>|<\/th>)/gm, '\n') // Tables + .replace(/^
/gm, '') // Remove leading
+ .replace(/(
\n|
)/gm, '\n') //
+ .replace(/

(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1 + .replace(/(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers + .replace(/(<([^>]+)>)/igm, ''); // Remove any other tags + utils.logMessage('https://console.appnexus.com/docs/understanding-the-debug-auction'); + utils.logMessage(debugText); + } + return bids; }, @@ -450,6 +491,11 @@ function hasAppId(bid) { return !!bid.params.app } +function getCookie(name) { + let m = window.document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]*)\\s*(;|$)'); + return m ? decodeURIComponent(m[2]) : null; +} + function getRtbBid(tag) { return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); } From 9615c67d855086a1455021625a8f4d0c1d708e41 Mon Sep 17 00:00:00 2001 From: Andrew Bowman Date: Mon, 3 Dec 2018 11:52:56 -0500 Subject: [PATCH 2/4] adding getCookie to utils --- modules/appnexusBidAdapter.js | 9 ++++++++- src/utils.js | 5 +++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 9a52964a004..b7c2ad84290 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -81,14 +81,21 @@ export const spec = { let debugObj = {}; let debugObjParams = {}; const debugCookieName = 'apn_prebid_debug'; - const debugCookie = getCookie(debugCookieName) || null; + const debugCookie = utils.getCookie(debugCookieName) || null; + if (debugCookie) { try { debugObj = JSON.parse(debugCookie); } catch (e) { utils.logError('AppNexus Debug Auction Cookie Error:\n\n' + e); } + } else { + const debugBidRequest = find(bidRequests, hasDebug); + if (debugBidRequest && debugBidRequest.debug) { + debugObj = debugBidRequest.debug; + } } + if (debugObj && debugObj.enabled) { Object.keys(debugObj) .filter(param => includes(DEBUG_PARAMS, param)) diff --git a/src/utils.js b/src/utils.js index 843c0c11c76..396d24138fe 100644 --- a/src/utils.js +++ b/src/utils.js @@ -844,6 +844,11 @@ export function cookiesAreEnabled() { return window.document.cookie.indexOf('prebid.cookieTest') != -1; } +export function getCookie(name) { + let m = window.document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]*)\\s*(;|$)'); + return m ? decodeURIComponent(m[2]) : null; +} + /** * Given a function, return a function which only executes the original after * it's been called numRequiredCalls times. From 0d7ed0e6c63152c4a66682dcd69a7b6a23cf166e Mon Sep 17 00:00:00 2001 From: Andrew Bowman Date: Mon, 3 Dec 2018 14:17:30 -0500 Subject: [PATCH 3/4] remove LGTM alert on getCookie --- modules/appnexusBidAdapter.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index b7c2ad84290..1e97f60085b 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -498,11 +498,6 @@ function hasAppId(bid) { return !!bid.params.app } -function getCookie(name) { - let m = window.document.cookie.match('(^|;)\\s*' + name + '\\s*=\\s*([^;]*)\\s*(;|$)'); - return m ? decodeURIComponent(m[2]) : null; -} - function getRtbBid(tag) { return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); } From be889659c4a5ded26dbaf8faa7dbec4ac9aad874 Mon Sep 17 00:00:00 2001 From: Andrew Bowman Date: Mon, 3 Dec 2018 14:28:18 -0500 Subject: [PATCH 4/4] fix failed tests --- modules/appnexusBidAdapter.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 1e97f60085b..b4bc18e791b 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -498,6 +498,10 @@ function hasAppId(bid) { return !!bid.params.app } +function hasDebug(bid) { + return !!bid.debug +} + function getRtbBid(tag) { return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb); }