From 31522176dda74a1e962f192af6a30defc071808c Mon Sep 17 00:00:00 2001 From: jsnellbaker <31102355+jsnellbaker@users.noreply.github.com> Date: Wed, 12 Oct 2022 09:20:02 -0400 Subject: [PATCH] Appnexus Bid Adapter: add support for debug params via query string (#9091) * appnexus bid adapter - add support for debug params via query string * add unit test and some updates --- modules/appnexusBidAdapter.js | 21 +++++++++++++++-- test/spec/modules/appnexusBidAdapter_spec.js | 24 ++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/modules/appnexusBidAdapter.js b/modules/appnexusBidAdapter.js index 7b59ce4ee3b..cabbb448960 100644 --- a/modules/appnexusBidAdapter.js +++ b/modules/appnexusBidAdapter.js @@ -11,6 +11,7 @@ import { getMinValueFromArray, getParameterByName, getUniqueIdentifierStr, + getWindowFromDocument, isArray, isArrayOfNums, isEmpty, @@ -23,8 +24,7 @@ import { logMessage, logWarn, mergeDeep, - transformBidderParamKeywords, - getWindowFromDocument + transformBidderParamKeywords } from '../src/utils.js'; import {Renderer} from '../src/Renderer.js'; import {config} from '../src/config.js'; @@ -47,6 +47,11 @@ const VIDEO_RTB_TARGETING = ['minduration', 'maxduration', 'skip', 'skipafter', const USER_PARAMS = ['age', 'externalUid', '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 DEBUG_QUERY_PARAM_MAP = { + 'apn_debug_dongle': 'dongle', + 'apn_debug_member_id': 'member_id', + 'apn_debug_timeout': 'debug_timeout' +}; const VIDEO_MAPPING = { playback_method: { 'unknown': 0, @@ -184,6 +189,18 @@ export const spec = { logError('AppNexus Debug Auction Cookie Error:\n\n' + e); } } else { + Object.keys(DEBUG_QUERY_PARAM_MAP).forEach(qparam => { + let qval = getParameterByName(qparam); + if (isStr(qval) && qval !== '') { + debugObj[DEBUG_QUERY_PARAM_MAP[qparam]] = qval; + debugObj.enabled = true; + } + }); + debugObj = convertTypes({ + 'member_id': 'number', + 'debug_timeout': 'number' + }, debugObj); + const debugBidRequest = find(bidRequests, hasDebug); if (debugBidRequest && debugBidRequest.debug) { debugObj = debugBidRequest.debug; diff --git a/test/spec/modules/appnexusBidAdapter_spec.js b/test/spec/modules/appnexusBidAdapter_spec.js index 87a4a0fbe2d..5cd189da9a1 100644 --- a/test/spec/modules/appnexusBidAdapter_spec.js +++ b/test/spec/modules/appnexusBidAdapter_spec.js @@ -4,6 +4,7 @@ import { newBidder } from 'src/adapters/bidderFactory.js'; import * as bidderFactory from 'src/adapters/bidderFactory.js'; import { auctionManager } from 'src/auctionManager.js'; import { deepClone } from 'src/utils.js'; +import * as utils from 'src/utils.js'; import { config } from 'src/config.js'; const ENDPOINT = 'https://ib.adnxs.com/ut/v3/prebid'; @@ -370,6 +371,29 @@ describe('AppNexusAdapter', function () { }); }); + it('should add debug params from query', function () { + let getParamStub = sinon.stub(utils, 'getParameterByName').callsFake(function(par) { + if (par === 'apn_debug_dongle') return 'abcdef'; + if (par === 'apn_debug_member_id') return '1234'; + if (par === 'apn_debug_timeout') return '1000'; + + return ''; + }); + + let bidRequest = deepClone(bidRequests[0]); + const request = spec.buildRequests([bidRequest]); + const payload = JSON.parse(request.data); + + expect(payload.debug).to.exist.and.to.deep.equal({ + 'dongle': 'abcdef', + 'enabled': true, + 'member_id': 1234, + 'debug_timeout': 1000 + }); + + getParamStub.restore(); + }); + it('should attach reserve param when either bid param or getFloor function exists', function () { let getFloorResponse = { currency: 'USD', floor: 3 }; let request, payload = null;