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

Media.net : adds user id support #4925

Merged
merged 1 commit into from
Mar 10, 2020
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
35 changes: 14 additions & 21 deletions modules/medianetBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,20 @@ function getCoordinates(id) {
return null;
}

function extParams(params, gdpr, uspConsent) {
let ext = {
customer_id: params.cid,
prebid_version: $$PREBID_GLOBAL$$.version
};
ext.gdpr_applies = !!(gdpr && gdpr.gdprApplies);
if (ext.gdpr_applies) {
ext.gdpr_consent_string = gdpr.consentString || '';
}

ext.usp_applies = !!(uspConsent);
if (ext.usp_applies) {
ext.usp_consent_string = uspConsent || '';
}

function extParams(params, gdpr, uspConsent, userId) {
let windowSize = spec.getWindowSize();
if (windowSize.w !== -1 && windowSize.h !== -1) {
ext.screen = windowSize;
}

return ext;
let gdprApplies = !!(gdpr && gdpr.gdprApplies);
let uspApplies = !!(uspConsent);
return Object.assign({},
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think technically this first param {} is not needed since the next ones will always return something.

But no big deal.

{ customer_id: params.cid },
{ prebid_version: $$PREBID_GLOBAL$$.version },
{ gdpr_applies: gdprApplies },
(gdprApplies) && { gdpr_consent_string: gdpr.consentString || '' },
{ usp_applies: uspApplies },
uspApplies && { usp_consent_string: uspConsent || '' },
windowSize.w !== -1 && windowSize.h !== -1 && { screen: windowSize },
userId && { user_id: userId }
);
}

function slotParams(bidRequest) {
Expand Down Expand Up @@ -247,7 +240,7 @@ function normalizeCoordinates(coordinates) {
function generatePayload(bidRequests, bidderRequests) {
return {
site: siteDetails(bidRequests[0].params.site),
ext: extParams(bidRequests[0].params, bidderRequests.gdprConsent, bidderRequests.uspConsent),
ext: extParams(bidRequests[0].params, bidderRequests.gdprConsent, bidderRequests.uspConsent, bidRequests[0].userId),
id: bidRequests[0].auctionId,
imp: bidRequests.map(request => slotParams(request)),
tmax: bidderRequests.timeout || config.getConfig('bidderTimeout')
Expand Down
141 changes: 141 additions & 0 deletions test/spec/modules/medianetBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,52 @@ let VALID_BID_REQUEST = [{
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1
}],
VALID_BID_REQUEST_WITH_USERID = [{
'bidder': 'medianet',
'params': {
'crid': 'crid',
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
userId: {
britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911'
},
'adUnitCode': 'div-gpt-ad-1460505748561-0',
'transactionId': '277b631f-92f5-4844-8b19-ea13c095d3f1',
'mediaTypes': {
'banner': {
'sizes': [[300, 250]],
}
},
'bidId': '28f8f8130a583e',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1
}, {
'bidder': 'medianet',
'params': {
'crid': 'crid',
'cid': 'customer_id',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest',
'isTop': true
}
},
'adUnitCode': 'div-gpt-ad-1460505748561-123',
'transactionId': 'c52a5c62-3c2b-4b90-9ff8-ec1487754822',
'sizes': [[300, 251]],
'bidId': '3f97ca71b1e5c2',
'bidderRequestId': '1e9b1f07797c1c',
'auctionId': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'bidRequestsCount': 1
}],

VALID_BID_REQUEST_INVALID_BIDFLOOR = [{
'bidder': 'medianet',
Expand Down Expand Up @@ -503,6 +549,96 @@ let VALID_BID_REQUEST = [{
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD_WITH_USERID = {
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest',
'isTop': true
},
'ext': {
'customer_id': 'customer_id',
'prebid_version': $$PREBID_GLOBAL$$.version,
'gdpr_applies': false,
'user_id': {
britepoolid: '82efd5e1-816b-4f87-97f8-044f407e2911'
},
'usp_applies': false,
'screen': {
'w': 1000,
'h': 1000
}
},
'id': 'aafabfd0-28c0-4ac0-aa09-99689e88b81d',
'imp': [{
'id': '28f8f8130a583e',
'tagid': 'crid',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-0',
'visibility': 1,
'viewability': 1,
'coordinates': {
'top_left': {
x: 50,
y: 50
},
'bottom_right': {
x: 100,
y: 100
}
},
'display_count': 1
},
'banner': [{
'w': 300,
'h': 250
}],
'all': {
'cid': 'customer_id',
'crid': 'crid',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}, {
'id': '3f97ca71b1e5c2',
'tagid': 'crid',
'ext': {
'dfp_id': 'div-gpt-ad-1460505748561-123',
'visibility': 1,
'viewability': 1,
'coordinates': {
'top_left': {
x: 50,
y: 50
},
'bottom_right': {
x: 100,
y: 100
}
},
'display_count': 1
},
'banner': [{
'w': 300,
'h': 251
}],
'all': {
'cid': 'customer_id',
'crid': 'crid',
'site': {
'page': 'http://media.net/prebidtest',
'domain': 'media.net',
'ref': 'http://media.net/prebidtest',
'isTop': true
}
}
}],
'tmax': config.getConfig('bidderTimeout')
},
VALID_PAYLOAD_WITH_CRID = {
'site': {
'page': 'http://media.net/prebidtest',
Expand Down Expand Up @@ -1017,6 +1153,11 @@ describe('Media.net bid adapter', function () {
expect(JSON.parse(bidreq.data)).to.deep.equal(VALID_PAYLOAD_WITH_CRID);
});

it('should have userid in bid request', function () {
let bidReq = spec.buildRequests(VALID_BID_REQUEST_WITH_USERID, VALID_AUCTIONDATA);
expect(JSON.parse(bidReq.data)).to.deep.equal(VALID_PAYLOAD_WITH_USERID);
});

describe('build requests: when page meta-data is available', () => {
beforeEach(() => {
spec.clearMnData();
Expand Down