Skip to content

Commit

Permalink
Appnexus Bid Adapter: add support for debug params via query string (#…
Browse files Browse the repository at this point in the history
…9091)

* appnexus bid adapter - add support for debug params via query string

* add unit test and some updates
  • Loading branch information
jsnellbaker authored Oct 12, 2022
1 parent 5e18b2d commit 3152217
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
21 changes: 19 additions & 2 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
getMinValueFromArray,
getParameterByName,
getUniqueIdentifierStr,
getWindowFromDocument,
isArray,
isArrayOfNums,
isEmpty,
Expand All @@ -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';
Expand All @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 3152217

Please sign in to comment.