Skip to content

Commit 65df3bb

Browse files
aneuway2mkendall07
authored andcommitted
Appnexus adaptor - Added App parameters for hybrid apps. (#2973)
* Added hybrid app parameters and debug url parameters * Fix test for app parameters. removed debugging * added defensive code per review from @jaiminpanchal27 * simplified if/then statements * fix JS lint issue
1 parent 18bf1a1 commit 65df3bb

File tree

3 files changed

+120
-3
lines changed

3 files changed

+120
-3
lines changed

modules/appnexusBidAdapter.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ const URL = '//ib.adnxs.com/ut/v3/prebid';
1010
const VIDEO_TARGETING = ['id', 'mimes', 'minduration', 'maxduration',
1111
'startdelay', 'skippable', 'playback_method', 'frameworks'];
1212
const USER_PARAMS = ['age', 'external_uid', 'segments', 'gender', 'dnt', 'language'];
13+
const APP_DEVICE_PARAMS = ['geo', 'device_id']; // appid is collected separately
1314
const NATIVE_MAPPING = {
1415
body: 'description',
1516
cta: 'ctatext',
@@ -59,6 +60,23 @@ export const spec = {
5960
.forEach(param => userObj[param] = userObjBid.params.user[param]);
6061
}
6162

63+
const appDeviceObjBid = find(bidRequests, hasAppDeviceInfo);
64+
let appDeviceObj;
65+
if (appDeviceObjBid && appDeviceObjBid.params && appDeviceObjBid.params.app) {
66+
appDeviceObj = {};
67+
Object.keys(appDeviceObjBid.params.app)
68+
.filter(param => includes(APP_DEVICE_PARAMS, param))
69+
.forEach(param => appDeviceObj[param] = appDeviceObjBid.params.app[param]);
70+
}
71+
72+
const appIdObjBid = find(bidRequests, hasAppId);
73+
let appIdObj;
74+
if (appIdObjBid && appIdObjBid.params && appDeviceObjBid.params.app && appDeviceObjBid.params.app.id) {
75+
appIdObj = {
76+
appid: appIdObjBid.params.app.id
77+
};
78+
}
79+
6280
const memberIdBid = find(bidRequests, hasMemberId);
6381
const member = memberIdBid ? parseInt(memberIdBid.params.member, 10) : 0;
6482

@@ -74,6 +92,13 @@ export const spec = {
7492
payload.member_id = member;
7593
}
7694

95+
if (appDeviceObjBid) {
96+
payload.device = appDeviceObj
97+
}
98+
if (appIdObjBid) {
99+
payload.app = appIdObj;
100+
}
101+
77102
if (bidderRequest && bidderRequest.gdprConsent) {
78103
// note - objects for impbus use underscore instead of camelCase
79104
payload.gdpr_consent = {
@@ -381,6 +406,19 @@ function hasMemberId(bid) {
381406
return !!parseInt(bid.params.member, 10);
382407
}
383408

409+
function hasAppDeviceInfo(bid) {
410+
if (bid.params) {
411+
return !!bid.params.app
412+
}
413+
}
414+
415+
function hasAppId(bid) {
416+
if (bid.params && bid.params.app) {
417+
return !!bid.params.app.id
418+
}
419+
return !!bid.params.app
420+
}
421+
384422
function getRtbBid(tag) {
385423
return tag && tag.ads && tag.ads.length && find(tag.ads, ad => ad.rtb);
386424
}

modules/appnexusBidAdapter.md

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,13 @@ Appnexus bid adapter supports Banner, Video (instream and outstream) and Native.
1717
var adUnits = [
1818
// Banner adUnit
1919
{
20-
code: 'banner-div',
21-
sizes: [[300, 250], [300,600]],
22-
bids: [{
20+
code: 'banner-div',
21+
mediaTypes: {
22+
banner: {
23+
sizes: [[300, 250], [300,600]]
24+
}
25+
}
26+
bids: [{
2327
bidder: 'appnexus',
2428
params: {
2529
placementId: '10433394'
@@ -98,6 +102,37 @@ var adUnits = [
98102
}
99103
}
100104
]
105+
},
106+
// Banner adUnit in a App Webview
107+
// Only use this for situations where prebid.js is in a webview of an App
108+
// See Prebid Mobile for displaying ads via an SDK
109+
{
110+
code: 'banner-div',
111+
mediaTypes: {
112+
banner: {
113+
sizes: [[300, 250], [300,600]]
114+
}
115+
}
116+
bids: [{
117+
bidder: 'appnexus',
118+
params: {
119+
placementId: '10433394',
120+
app: {
121+
id: "B1O2W3M4AN.com.prebid.webview",
122+
geo: {
123+
lat: 40.0964439,
124+
lng: -75.3009142
125+
},
126+
device_id: {
127+
idfa: "4D12078D-3246-4DA4-AD5E-7610481E7AE", // Apple advertising identifier
128+
aaid: "38400000-8cf0-11bd-b23e-10b96e40000d", // Android advertising identifier
129+
md5udid: "5756ae9022b2ea1e47d84fead75220c8", // MD5 hash of the ANDROID_ID
130+
sha1udid: "4DFAA92388699AC6539885AEF1719293879985BF", // SHA1 hash of the ANDROID_ID
131+
windowsadid: "750c6be243f1c4b5c9912b95a5742fc5" // Windows advertising identifier
132+
}
133+
}
134+
}
135+
}]
101136
}
102137
];
103138
```

test/spec/modules/appnexusBidAdapter_spec.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,50 @@ describe('AppNexusAdapter', () => {
326326
expect(payload.gdpr_consent.consent_string).to.exist.and.to.equal(consentString);
327327
expect(payload.gdpr_consent.consent_required).to.exist.and.to.be.true;
328328
});
329+
330+
it('supports sending hybrid mobile app parameters', () => {
331+
let appRequest = Object.assign({},
332+
bidRequests[0],
333+
{
334+
params: {
335+
placementId: '10433394',
336+
app: {
337+
id: 'B1O2W3M4AN.com.prebid.webview',
338+
geo: {
339+
lat: 40.0964439,
340+
lng: -75.3009142
341+
},
342+
device_id: {
343+
idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE', // Apple advertising identifier
344+
aaid: '38400000-8cf0-11bd-b23e-10b96e40000d', // Android advertising identifier
345+
md5udid: '5756ae9022b2ea1e47d84fead75220c8', // MD5 hash of the ANDROID_ID
346+
sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF', // SHA1 hash of the ANDROID_ID
347+
windowsadid: '750c6be243f1c4b5c9912b95a5742fc5' // Windows advertising identifier
348+
}
349+
}
350+
}
351+
}
352+
);
353+
const request = spec.buildRequests([appRequest]);
354+
const payload = JSON.parse(request.data);
355+
expect(payload.app).to.exist;
356+
expect(payload.app).to.deep.equal({
357+
appid: 'B1O2W3M4AN.com.prebid.webview'
358+
});
359+
expect(payload.device.device_id).to.exist;
360+
expect(payload.device.device_id).to.deep.equal({
361+
aaid: '38400000-8cf0-11bd-b23e-10b96e40000d',
362+
idfa: '4D12078D-3246-4DA4-AD5E-7610481E7AE',
363+
md5udid: '5756ae9022b2ea1e47d84fead75220c8',
364+
sha1udid: '4DFAA92388699AC6539885AEF1719293879985BF',
365+
windowsadid: '750c6be243f1c4b5c9912b95a5742fc5'
366+
});
367+
expect(payload.device.geo).to.exist;
368+
expect(payload.device.geo).to.deep.equal({
369+
lat: 40.0964439,
370+
lng: -75.3009142
371+
});
372+
});
329373
})
330374

331375
describe('interpretResponse', () => {

0 commit comments

Comments
 (0)