Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Appnexus Bid Adapter: add support for debug params via query string #9091

Merged
merged 2 commits into from
Oct 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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