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 AST Debug Auction #3025

Closed
wants to merge 3 commits into from
Closed
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
70 changes: 70 additions & 0 deletions modules/appnexusBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ 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 AST_DEBUG_URL = ['ast_debug', 'ast_dongle', 'ast_debug_member', 'ast_debug_timeout']
const AST_DEBUG_PARAMS = ['enabled', 'dongle', 'member_id', 'debug_timeout']
const NATIVE_MAPPING = {
body: 'description',
cta: 'ctatext',
Expand Down Expand Up @@ -77,6 +79,38 @@ export const spec = {
};
}

let debugObj = {};
const debugObjParams = find(bidRequests, hasDebug);
if (debugObjParams && debugObjParams.debug) {
Object.keys(debugObjParams.debug)
.filter(param => includes(AST_DEBUG_PARAMS, param))
.forEach(param => {
debugObj['debug'] = debugObj['debug'] || {};
debugObj.debug[param] = debugObjParams.debug[param]
});
}

const debugUrlParams = getURLparams();
if (debugUrlParams && debugUrlParams.params) {
Object.keys(debugUrlParams.params)
.filter(param => includes(AST_DEBUG_URL, param))
.forEach(param => {
debugObj['debug'] = debugObj['debug'] || {};
if (param == 'ast_debug') {
debugObj['debug']['enabled'] = (debugUrlParams.params[param] === 'true');
}
if (param == 'ast_dongle') {
debugObj['debug']['dongle'] = debugUrlParams.params[param];
}
if (param == 'ast_debug_member') {
debugObj['debug']['member_id'] = parseInt(debugUrlParams.params[param], 10);
}
if (param == 'ast_debug_timeout') {
debugObj['debug']['debug_timeout'] = parseInt(debugUrlParams.params[param], 10);
}
});
}

const memberIdBid = find(bidRequests, hasMemberId);
const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0;

Expand All @@ -99,6 +133,10 @@ export const spec = {
payload.app = appIdObj;
}

if (debugObj && debugObj.debug) {
payload.debug = debugObj.debug
}

if (bidderRequest && bidderRequest.gdprConsent) {
// note - objects for impbus use underscore instead of camelCase
payload.gdpr_consent = {
Expand Down Expand Up @@ -144,6 +182,21 @@ 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(/(<td>|<th>)/gm, '\t') // Tables
.replace(/(<\/td>|<\/th>)/gm, '\n') // Tables
.replace(/^<br>/gm, '') // Remove leading <br>
.replace(/(<br>\n|<br>)/gm, '\n') // <br>
.replace(/<h1>(.*)<\/h1>/gm, '\n\n===== $1 =====\n\n') // Header H1
.replace(/<h[2-6]>(.*)<\/h[2-6]>/gm, '\n\n*** $1 ***\n\n') // Headers
.replace(/(<([^>]+)>)/igm, ''); // Remove any other tags
utils.logMessage(debugText);
}

return bids;
},

Expand Down Expand Up @@ -419,6 +472,23 @@ function hasAppId(bid) {
return !!bid.params.app
}

function hasDebug(bid) {
return !!bid.debug
}

function getURLparams() {
let obj = {};
if (utils.getTopWindowLocation() && utils.getTopWindowLocation().search) {
obj['params'] = {};
utils.getTopWindowLocation().search.substr(1).split('&').forEach(keyvalue => {
let key = keyvalue.split('=')[0];
let val = keyvalue.split('=')[1];
obj['params'][key] = val
});
}
return obj
}

function getRtbBid(tag) {
return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb);
}
Expand Down
26 changes: 26 additions & 0 deletions test/spec/modules/appnexusBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,32 @@ describe('AppNexusAdapter', () => {
lng: -75.3009142
});
});

it('sends a debug auction', () => {
let debugRequest = Object.assign({},
bidRequests[0],
{
params: {
placementId: '10433394'
},
debug: {
enabled: true,
dongle: 'QWERTY',
member_id: 958,
debug_timeout: 1000
}
}
);
const request = spec.buildRequests([debugRequest]);
const payload = JSON.parse(request.data);
expect(payload.debug).to.exist;
expect(payload.debug).to.deep.equal({
enabled: true,
dongle: 'QWERTY',
member_id: 958,
debug_timeout: 1000
});
});
})

describe('interpretResponse', () => {
Expand Down