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

NextMillennium Bid Adapter : sending a request with several imp objects #12244

Merged
merged 29 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
7fc2b34
added support for gpp consent string
mhlm Nov 22, 2023
72e2101
changed test for nextMillenniumBidAdapter
mhlm Nov 23, 2023
d897b6b
Merge pull request #4 from nextmillenniummedia/PB-1373-feature/add-su…
mhlm Nov 23, 2023
93f578e
added some tests
mhlm Nov 24, 2023
bd51f48
Merge branch 'master' of github.com:nextmillenniummedia/Prebid.js
mhlm Nov 24, 2023
97396e2
added site.pagecat, site.content.cat and site.content.language to req…
mhlm Nov 25, 2023
a108dad
lint fix
mhlm Nov 25, 2023
b6865e7
formated code
mhlm Nov 25, 2023
763721a
formated code
mhlm Nov 25, 2023
03ffd76
formated code
mhlm Nov 27, 2023
9b7c16b
pachage-lock with prebid
mhlm Dec 1, 2023
281dd54
pachage-lock with prebid
mhlm Dec 1, 2023
d33f078
formatted code
mhlm Dec 1, 2023
c54ffca
Merge branch 'prebid:master' into master
mhlm Dec 4, 2023
28ccc93
added device.sua, user.eids
mhlm Dec 9, 2023
66f0bfb
Merge branch 'prebid:master' into master
mhlm Dec 9, 2023
ca85907
formatted
mhlm Dec 11, 2023
5577fdf
Merge branch 'master' of github.com:nextmillenniummedia/Prebid.js
mhlm Dec 11, 2023
6c1be2d
fixed tests
mhlm Dec 11, 2023
19b4db5
fixed bug functio getSua
mhlm Dec 11, 2023
ade3d69
Merge branch 'prebid:master' into master
mhlm Dec 12, 2023
f0df78e
Merge branch 'prebid:master' into master
mhlm Dec 22, 2023
2199ee2
Merge branch 'prebid:master' into master
mhlm Jan 31, 2024
0cab253
Merge branch 'prebid:master' into master
mhlm Feb 23, 2024
43ee73d
Merge branch 'prebid:master' into master
mhlm Mar 14, 2024
b650159
Merge branch 'prebid:master' into master
mhlm Mar 19, 2024
4edb2c6
Merge branch 'prebid:master' into master
mhlm Aug 16, 2024
bfc6bbe
Merge branch 'master' of github.com:nextmillenniummedia/Prebid.js
mhlm Sep 16, 2024
d42ae4d
NextMillennium: Sending a request with several imp objects.
mhlm Sep 16, 2024
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
169 changes: 80 additions & 89 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ import {
} from '../src/utils.js';
import {getAd} from '../libraries/targetVideoUtils/bidderUtils.js';

import {getGlobal} from '../src/prebidGlobal.js';
import { EVENTS } from '../src/constants.js';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getRefererInfo} from '../src/refererDetection.js';

const NM_VERSION = '3.1.0';
const NM_VERSION = '4.0.0';
const PBJS_VERSION = 'v$prebid.version$';
const GVLID = 1060;
const BIDDER_CODE = 'nextMillennium';
const ENDPOINT = 'https://pbs.nextmillmedia.com/openrtb2/auction';
Expand Down Expand Up @@ -81,65 +81,46 @@ export const spec = {
buildRequests: function(validBidRequests, bidderRequest) {
const requests = [];
window.nmmRefreshCounts = window.nmmRefreshCounts || {};
const site = getSiteObj();
const device = getDeviceObj();

_each(validBidRequests, (bid) => {
window.nmmRefreshCounts[bid.adUnitCode] = window.nmmRefreshCounts[bid.adUnitCode] || 0;
const id = getPlacementId(bid);
const auctionId = bid.auctionId;
const bidId = bid.bidId;

const site = getSiteObj();
const device = getDeviceObj();
const {cur, mediaTypes} = getCurrency(bid);
const postBody = {
id: bidderRequest?.bidderRequestId,
ext: {
next_mil_imps: [],
},

const postBody = {
id: bidderRequest?.bidderRequestId,
cur,
ext: {
prebid: {
storedrequest: {
id,
},
},
device,
site,
imp: [],
};

nextMillennium: {
nm_version: NM_VERSION,
pbjs_version: getGlobal()?.version || undefined,
refresh_count: window.nmmRefreshCounts[bid.adUnitCode]++,
elOffsets: getBoundingClient(bid),
scrollTop: window.pageYOffset || document.documentElement.scrollTop,
},
},
setConsentStrings(postBody, bidderRequest);
setOrtb2Parameters(postBody, bidderRequest?.ortb2);

device,
site,
imp: [],
};
const urlParameters = parseUrl(getWindowTop().location.href).search;
const isTest = urlParameters['pbs'] && urlParameters['pbs'] === 'test';
setEids(postBody, validBidRequests);

_each(validBidRequests, (bid, i) => {
window.nmmRefreshCounts[bid.adUnitCode] = window.nmmRefreshCounts[bid.adUnitCode] || 0;
const id = getPlacementId(bid);
const {cur, mediaTypes} = getCurrency(bid);
if (i === 0) postBody.cur = cur;
postBody.imp.push(getImp(bid, id, mediaTypes));
setConsentStrings(postBody, bidderRequest);
setOrtb2Parameters(postBody, bidderRequest?.ortb2);
setEids(postBody, bid);

const urlParameters = parseUrl(getWindowTop().location.href).search;
const isTest = urlParameters['pbs'] && urlParameters['pbs'] === 'test';
const params = bid.params;

requests.push({
method: 'POST',
url: isTest ? TEST_ENDPOINT : ENDPOINT,
data: JSON.stringify(postBody),
options: {
contentType: 'text/plain',
withCredentials: true,
},
postBody.ext.next_mil_imps.push(getExtNextMilImp(bid));
});

bidId,
params,
auctionId,
});
this.getUrlPixelMetric(EVENTS.BID_REQUESTED, validBidRequests);

this.getUrlPixelMetric(EVENTS.BID_REQUESTED, bid);
requests.push({
method: 'POST',
url: isTest ? TEST_ENDPOINT : ENDPOINT,
data: JSON.stringify(postBody),
options: {
contentType: 'text/plain',
withCredentials: true,
},
});

return requests;
Expand All @@ -149,16 +130,15 @@ export const spec = {
const response = serverResponse.body;
const bidResponses = [];

const bids = [];
_each(response.seatbid, (resp) => {
_each(resp.bid, (bid) => {
const requestId = bidRequest.bidId;
const params = bidRequest.params;

const {ad, adUrl, vastUrl, vastXml} = getAd(bid);

const bidResponse = {
requestId,
params,
cpm: bid.price,
width: bid.w,
height: bid.h,
Expand All @@ -182,11 +162,13 @@ export const spec = {
};

bidResponses.push(bidResponse);

this.getUrlPixelMetric(EVENTS.BID_RESPONSE, bid);
});

bids.push(resp.bid);
});

this.getUrlPixelMetric(EVENTS.BID_RESPONSE, bids.flat());

return bidResponses;
},

Expand Down Expand Up @@ -226,22 +208,26 @@ export const spec = {
triggerPixel(url);
},

_getUrlPixelMetric(eventName, bid) {
const bidder = bid.bidder || bid.bidderCode;
_getUrlPixelMetric(eventName, bids) {
if (!Array.isArray(bids)) bids = [bids];

const bidder = bids[0]?.bidder || bids[0]?.bidderCode;
if (bidder != BIDDER_CODE) return;

let params;
if (bid.params) {
params = Array.isArray(bid.params) ? bid.params : [bid.params];
} else {
if (Array.isArray(bid.bids)) params = bid.bids.map(bidI => bidI.params);
};
let params = [];
_each(bids, bid => {
if (bid.params) {
params.push(bid.params);
} else {
if (Array.isArray(bid.bids)) params.push(bid.bids.map(bidI => bidI.params));
};
});

if (!params.length) return;

const placementIdsArray = [];
const groupIdsArray = [];
params.forEach(paramsI => {
params.flat().forEach(paramsI => {
if (paramsI.group_id) {
groupIdsArray.push(paramsI.group_id);
} else {
Expand All @@ -252,9 +238,7 @@ export const spec = {
const placementIds = (placementIdsArray.length && `&placements=${placementIdsArray.join(';')}`) || '';
const groupIds = (groupIdsArray.length && `&groups=${groupIdsArray.join(';')}`) || '';

if (!(groupIds || placementIds)) {
return;
};
if (!(groupIds || placementIds)) return;

const url = `${REPORT_ENDPOINT}?event=${eventName}&bidder=${bidder}&source=pbjs${groupIds}${placementIds}`;

Expand All @@ -268,6 +252,21 @@ export const spec = {
},
};

function getExtNextMilImp(bid) {
if (typeof window?.nmmRefreshCounts[bid.adUnitCode] === 'number') ++window.nmmRefreshCounts[bid.adUnitCode];
const nextMilImp = {
impId: bid.adUnitCode,
nextMillennium: {
nm_version: NM_VERSION,
pbjs_version: PBJS_VERSION,
refresh_count: window?.nmmRefreshCounts[bid.adUnitCode] || 0,
scrollTop: window.pageYOffset || document.documentElement.scrollTop,
},
};

return nextMilImp;
}

export function getImp(bid, id, mediaTypes) {
const {banner, video} = mediaTypes;
const imp = {
Expand Down Expand Up @@ -362,10 +361,16 @@ export function setOrtb2Parameters(postBody, ortb2 = {}) {
}
}

export function setEids(postBody, bid) {
if (!isArray(bid.userIdAsEids) || !bid.userIdAsEids.length) return;
export function setEids(postBody = {}, bids = []) {
let isFind = false;
_each(bids, bid => {
if (isFind || !isArray(bid.userIdAsEids) || !bid.userIdAsEids.length) return;

deepSetValue(postBody, 'user.eids', bid.userIdAsEids);
if (bid.userIdAsEids.length) {
deepSetValue(postBody, 'user.eids', bid.userIdAsEids);
isFind = true;
};
});
}

export function replaceUsersyncMacros(url, gdprConsent = {}, uspConsent = '', gppConsent = {}, type = '') {
Expand Down Expand Up @@ -411,30 +416,16 @@ function getCurrency(bid = {}) {
return {cur, mediaTypes};
}

function getAdEl(bid) {
// best way I could think of to get El, is by matching adUnitCode to google slots...
const slot = window.googletag && window.googletag.pubads && window.googletag.pubads().getSlots().find(slot => slot.getAdUnitPath() === bid.adUnitCode);
const slotElementId = slot && slot.getSlotElementId();
if (!slotElementId) return null;
return document.querySelector('#' + slotElementId);
}

function getBoundingClient(bid) {
const el = getAdEl(bid);
if (!el) return {};
return el.getBoundingClientRect();
}

function getPlacementId(bid) {
export 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 sizes = [];
if (bid.mediaTypes) {
if (bid.mediaTypes.banner) sizes = bid.mediaTypes.banner.sizes;
if (bid.mediaTypes.video) sizes = [bid.mediaTypes.video.playerSize];
if (bid.mediaTypes.banner) sizes = [...bid.mediaTypes.banner.sizes];
if (bid.mediaTypes.video) sizes.push(bid.mediaTypes.video.playerSize);
};

const host = (windowTop && windowTop.location && windowTop.location.host) || '';
Expand Down
Loading