Skip to content

Commit bb015bd

Browse files
vedantsetaAmbuj Gupta
and
Ambuj Gupta
authored
adding user-id support in medianet adapter (#4925)
Co-authored-by: Ambuj Gupta <[email protected]>
1 parent f5b0e4e commit bb015bd

File tree

2 files changed

+155
-21
lines changed

2 files changed

+155
-21
lines changed

modules/medianetBidAdapter.js

+14-21
Original file line numberDiff line numberDiff line change
@@ -132,27 +132,20 @@ function getCoordinates(id) {
132132
return null;
133133
}
134134

135-
function extParams(params, gdpr, uspConsent) {
136-
let ext = {
137-
customer_id: params.cid,
138-
prebid_version: $$PREBID_GLOBAL$$.version
139-
};
140-
ext.gdpr_applies = !!(gdpr && gdpr.gdprApplies);
141-
if (ext.gdpr_applies) {
142-
ext.gdpr_consent_string = gdpr.consentString || '';
143-
}
144-
145-
ext.usp_applies = !!(uspConsent);
146-
if (ext.usp_applies) {
147-
ext.usp_consent_string = uspConsent || '';
148-
}
149-
135+
function extParams(params, gdpr, uspConsent, userId) {
150136
let windowSize = spec.getWindowSize();
151-
if (windowSize.w !== -1 && windowSize.h !== -1) {
152-
ext.screen = windowSize;
153-
}
154-
155-
return ext;
137+
let gdprApplies = !!(gdpr && gdpr.gdprApplies);
138+
let uspApplies = !!(uspConsent);
139+
return Object.assign({},
140+
{ customer_id: params.cid },
141+
{ prebid_version: $$PREBID_GLOBAL$$.version },
142+
{ gdpr_applies: gdprApplies },
143+
(gdprApplies) && { gdpr_consent_string: gdpr.consentString || '' },
144+
{ usp_applies: uspApplies },
145+
uspApplies && { usp_consent_string: uspConsent || '' },
146+
windowSize.w !== -1 && windowSize.h !== -1 && { screen: windowSize },
147+
userId && { user_id: userId }
148+
);
156149
}
157150

158151
function slotParams(bidRequest) {
@@ -247,7 +240,7 @@ function normalizeCoordinates(coordinates) {
247240
function generatePayload(bidRequests, bidderRequests) {
248241
return {
249242
site: siteDetails(bidRequests[0].params.site),
250-
ext: extParams(bidRequests[0].params, bidderRequests.gdprConsent, bidderRequests.uspConsent),
243+
ext: extParams(bidRequests[0].params, bidderRequests.gdprConsent, bidderRequests.uspConsent, bidRequests[0].userId),
251244
id: bidRequests[0].auctionId,
252245
imp: bidRequests.map(request => slotParams(request)),
253246
tmax: bidderRequests.timeout || config.getConfig('bidderTimeout')

test/spec/modules/medianetBidAdapter_spec.js

+141
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,52 @@ let VALID_BID_REQUEST = [{
8787
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
8888
'bidRequestsCount': 1
8989
}],
90+
VALID_BID_REQUEST_WITH_USERID = [{
91+
'bidder': 'medianet',
92+
'params': {
93+
'crid': 'crid',
94+
'cid': 'customer_id',
95+
'site': {
96+
'page': 'http://media.net/prebidtest',
97+
'domain': 'media.net',
98+
'ref': 'http://media.net/prebidtest',
99+
'isTop': true
100+
}
101+
},
102+
userId: {
103+
britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911'
104+
},
105+
'adUnitCode': 'div-gpt-ad-1460505748561-0',
106+
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
107+
'mediaTypes': {
108+
'banner': {
109+
'sizes': [[300, 250]],
110+
}
111+
},
112+
'bidId': '28f8f8130a583e',
113+
'bidderRequestId': '1e9b1f07797c1c',
114+
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
115+
'bidRequestsCount': 1
116+
}, {
117+
'bidder': 'medianet',
118+
'params': {
119+
'crid': 'crid',
120+
'cid': 'customer_id',
121+
'site': {
122+
'page': 'http://media.net/prebidtest',
123+
'domain': 'media.net',
124+
'ref': 'http://media.net/prebidtest',
125+
'isTop': true
126+
}
127+
},
128+
'adUnitCode': 'div-gpt-ad-1460505748561-123',
129+
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
130+
'sizes': [[300, 251]],
131+
'bidId': '3f97ca71b1e5c2',
132+
'bidderRequestId': '1e9b1f07797c1c',
133+
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
134+
'bidRequestsCount': 1
135+
}],
90136

91137
VALID_BID_REQUEST_INVALID_BIDFLOOR = [{
92138
'bidder': 'medianet',
@@ -503,6 +549,96 @@ let VALID_BID_REQUEST = [{
503549
}],
504550
'tmax': config.getConfig('bidderTimeout')
505551
},
552+
VALID_PAYLOAD_WITH_USERID = {
553+
'site': {
554+
'page': 'http://media.net/prebidtest',
555+
'domain': 'media.net',
556+
'ref': 'http://media.net/prebidtest',
557+
'isTop': true
558+
},
559+
'ext': {
560+
'customer_id': 'customer_id',
561+
'prebid_version': $$PREBID_GLOBAL$$.version,
562+
'gdpr_applies': false,
563+
'user_id': {
564+
britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911'
565+
},
566+
'usp_applies': false,
567+
'screen': {
568+
'w': 1000,
569+
'h': 1000
570+
}
571+
},
572+
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
573+
'imp': [{
574+
'id': '28f8f8130a583e',
575+
'tagid': 'crid',
576+
'ext': {
577+
'dfp_id': 'div-gpt-ad-1460505748561-0',
578+
'visibility': 1,
579+
'viewability': 1,
580+
'coordinates': {
581+
'top_left': {
582+
x: 50,
583+
y: 50
584+
},
585+
'bottom_right': {
586+
x: 100,
587+
y: 100
588+
}
589+
},
590+
'display_count': 1
591+
},
592+
'banner': [{
593+
'w': 300,
594+
'h': 250
595+
}],
596+
'all': {
597+
'cid': 'customer_id',
598+
'crid': 'crid',
599+
'site': {
600+
'page': 'http://media.net/prebidtest',
601+
'domain': 'media.net',
602+
'ref': 'http://media.net/prebidtest',
603+
'isTop': true
604+
}
605+
}
606+
}, {
607+
'id': '3f97ca71b1e5c2',
608+
'tagid': 'crid',
609+
'ext': {
610+
'dfp_id': 'div-gpt-ad-1460505748561-123',
611+
'visibility': 1,
612+
'viewability': 1,
613+
'coordinates': {
614+
'top_left': {
615+
x: 50,
616+
y: 50
617+
},
618+
'bottom_right': {
619+
x: 100,
620+
y: 100
621+
}
622+
},
623+
'display_count': 1
624+
},
625+
'banner': [{
626+
'w': 300,
627+
'h': 251
628+
}],
629+
'all': {
630+
'cid': 'customer_id',
631+
'crid': 'crid',
632+
'site': {
633+
'page': 'http://media.net/prebidtest',
634+
'domain': 'media.net',
635+
'ref': 'http://media.net/prebidtest',
636+
'isTop': true
637+
}
638+
}
639+
}],
640+
'tmax': config.getConfig('bidderTimeout')
641+
},
506642
VALID_PAYLOAD_WITH_CRID = {
507643
'site': {
508644
'page': 'http://media.net/prebidtest',
@@ -1017,6 +1153,11 @@ describe('Media.net bid adapter', function () {
10171153
expect(JSON.parse(bidreq.data)).to.deep.equal(VALID_PAYLOAD_WITH_CRID);
10181154
});
10191155

1156+
it('should have userid in bid request', function () {
1157+
let bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_USERID, VALID_AUCTIONDATA);
1158+
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_WITH_USERID);
1159+
});
1160+
10201161
describe('build requests: when page meta-data is available', () => {
10211162
beforeEach(() => {
10221163
spec.clearMnData();

0 commit comments

Comments
 (0)