Skip to content

Commit

Permalink
Next Millenium Bid Adapter: Added new parameter group_id (#8200)
Browse files Browse the repository at this point in the history
* changed name company

* changed name company in test

* Added processing of a new group_id parameter

* Added processing of a new group_id parameter

* changed check parameters

* fixed lint remarks

* added test

* fixed bug - lint

* changed test

* changed test - 2

* fixed bug - adapter
  • Loading branch information
mhlm authored Mar 30, 2022
1 parent 972ead0 commit 35e46cd
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 4 deletions.
38 changes: 36 additions & 2 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const spec = {

isBidRequestValid: function(bid) {
return !!(
bid.params.placement_id && isStr(bid.params.placement_id)
(bid.params.placement_id && isStr(bid.params.placement_id)) || (bid.params.group_id && isStr(bid.params.group_id))
);
},

Expand All @@ -28,9 +28,10 @@ export const spec = {
'ext': {
'prebid': {
'storedrequest': {
'id': getBidIdParameter('placement_id', bid.params)
'id': getPlacementId(bid)
}
},

'nextMillennium': {
'refresh_count': window.nmmRefreshCounts[bid.adUnitCode]++,
}
Expand All @@ -46,10 +47,12 @@ export const spec = {
if (uspConsent) {
postBody.regs.ext.us_privacy = uspConsent;
}

if (gdprConsent) {
if (typeof gdprConsent.gdprApplies !== 'undefined') {
postBody.regs.ext.gdpr = gdprConsent.gdprApplies ? 1 : 0;
}

if (typeof gdprConsent.consentString !== 'undefined') {
postBody.user = {
ext: { consent: gdprConsent.consentString }
Expand Down Expand Up @@ -91,6 +94,7 @@ export const spec = {
meta: {
advertiserDomains: bid.adomain || []
},

ad: bid.adm
});
});
Expand Down Expand Up @@ -125,4 +129,34 @@ export const spec = {
},
};

function getPlacementId(bid) {
const groupId = getBidIdParameter('group_id', bid.params)
const placementId = getBidIdParameter('placement_id', bid.params)
if (!groupId) return placementId

let windowTop = getTopWindow(window)
let size = []
if (bid.mediaTypes) {
if (bid.mediaTypes.banner) size = bid.mediaTypes.banner.sizes && bid.mediaTypes.banner.sizes[0]
if (bid.mediaTypes.video) size = bid.mediaTypes.video.playerSize
}

const host = (windowTop && windowTop.location && windowTop.location.host) || ''
return `g${groupId};${size.join('x')};${host}`
}

function getTopWindow(curWindow, nesting = 0) {
if (nesting > 10) {
return curWindow
}

try {
if (curWindow.parent.document) {
return getTopWindow(curWindow.parent.window, ++nesting)
}
} catch (err) {
return curWindow
}
}

registerBidder(spec);
5 changes: 3 additions & 2 deletions modules/nextMillenniumBidAdapter.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ Currently module supports only banner mediaType.
bids: [{
bidder: 'nextMillennium',
params: {
placement_id: '-1'
placement_id: '-1',
group_id: '6731'
}
}]
}];
```
```
51 changes: 51 additions & 0 deletions test/spec/modules/nextMillenniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,47 @@ describe('nextMillenniumBidAdapterTests', function() {
}
];

const bidRequestDataGI = [
{
adUnitCode: 'test-banner-gi',
bidId: 'bid1234',
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidder: 'nextMillennium',
params: { group_id: '1234' },
mediaTypes: {
banner: {
sizes: [[300, 250]]
}
},

sizes: [[300, 250]],
uspConsent: '1---',
gdprConsent: {
consentString: 'kjfdniwjnifwenrif3',
gdprApplies: true
}
},

{
adUnitCode: 'test-video-gi',
bidId: 'bid1234',
auctionId: 'b06c5141-fe8f-4cdf-9d7d-54415490a917',
bidder: 'nextMillennium',
params: { group_id: '1234' },
mediaTypes: {
video: {
playerSize: [640, 480],
}
},

uspConsent: '1---',
gdprConsent: {
consentString: 'kjfdniwjnifwenrif3',
gdprApplies: true
}
},
];

it('Request params check with GDPR and USP Consent', function () {
const request = spec.buildRequests(bidRequestData, bidRequestData[0]);
expect(JSON.parse(request[0].data).user.ext.consent).to.equal('kjfdniwjnifwenrif3');
Expand All @@ -38,6 +79,16 @@ describe('nextMillenniumBidAdapterTests', function() {
expect(JSON.parse(request[0].data).id).to.equal('b06c5141-fe8f-4cdf-9d7d-54415490a917');
});

it('use parameters group_id', function() {
for (let test of bidRequestDataGI) {
const request = spec.buildRequests([test]);
const requestData = JSON.parse(request[0].data);
const storeRequestId = requestData.ext.prebid.storedrequest.id;
const templateRE = /^g\d+;\d+x\d+;/;
expect(templateRE.test(storeRequestId)).to.be.true;
};
});

it('Check if refresh_count param is incremented', function() {
const request = spec.buildRequests(bidRequestData);
expect(JSON.parse(request[0].data).ext.nextMillennium.refresh_count).to.equal(3);
Expand Down

0 comments on commit 35e46cd

Please sign in to comment.