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: removed the use of the events module #11141

Merged
merged 27 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 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
957fa96
deleted deprecated code wurl
mhlm Feb 25, 2024
8e89e86
removed the use of the events module
mhlm Feb 25, 2024
38f644f
added parameters w and h for imp[].banner objecct
mhlm Feb 28, 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
166 changes: 26 additions & 140 deletions modules/nextMillenniumBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
getWindowTop,
isArray,
isStr,
logMessage,
parseGPTSingleSizeArrayToRtbSize,
parseUrl,
triggerPixel,
Expand All @@ -18,7 +17,6 @@ import {getGlobal} from '../src/prebidGlobal.js';
import CONSTANTS from '../src/constants.json';
import {BANNER, VIDEO} from '../src/mediaTypes.js';
import {config} from '../src/config.js';
import * as events from '../src/events.js';

import {registerBidder} from '../src/adapters/bidderFactory.js';
import {getRefererInfo} from '../src/refererDetection.js';
Expand Down Expand Up @@ -55,15 +53,6 @@ const ALLOWED_ORTB2_PARAMETERS = [
'user.keywords',
];

const sendingDataStatistic = initSendingDataStatistic();
events.on(CONSTANTS.EVENTS.AUCTION_INIT, auctionInitHandler);

const EXPIRENCE_WURL = 20 * 60000;
const wurlMap = {};
cleanWurl();

events.on(CONSTANTS.EVENTS.BID_WON, bidWonHandler);

export const spec = {
code: BIDDER_CODE,
supportedMediaTypes: [BANNER, VIDEO],
Expand All @@ -79,7 +68,7 @@ export const spec = {
const requests = [];
window.nmmRefreshCounts = window.nmmRefreshCounts || {};

_each(validBidRequests, function(bid) {
_each(validBidRequests, (bid) => {
window.nmmRefreshCounts[bid.adUnitCode] = window.nmmRefreshCounts[bid.adUnitCode] || 0;
const id = getPlacementId(bid);
const auctionId = bid.auctionId;
Expand Down Expand Up @@ -135,6 +124,8 @@ export const spec = {
params,
auctionId,
});

this.getUrlPixelMetric(CONSTANTS.EVENTS.BID_REQUESTED, bid);
});

return requests;
Expand All @@ -148,11 +139,6 @@ export const spec = {
_each(resp.bid, (bid) => {
const requestId = bidRequest.bidId;
const params = bidRequest.params;
const auctionId = bidRequest.auctionId;
const wurl = deepAccess(bid, 'ext.prebid.events.win');

// TODO: fix auctionId leak: https://github.com/prebid/Prebid.js/issues/9781
addWurl({auctionId, requestId, wurl});

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

Expand Down Expand Up @@ -182,6 +168,8 @@ export const spec = {
};

bidResponses.push(bidResponse);

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

Expand Down Expand Up @@ -215,6 +203,16 @@ export const spec = {
},

getUrlPixelMetric(eventName, bid) {
const disabledSending = !!config.getBidderConfig()?.nextMillennium?.disabledSendingStatisticData;
if (disabledSending) return;

const url = this._getUrlPixelMetric(eventName, bid);
if (!url) return;

triggerPixel(url);
},

_getUrlPixelMetric(eventName, bid) {
const bidder = bid.bidder || bid.bidderCode;
if (bidder != BIDDER_CODE) return;

Expand Down Expand Up @@ -248,6 +246,12 @@ export const spec = {

return url;
},

onTimeout(bids) {
for (const bid of bids) {
this.getUrlPixelMetric(CONSTANTS.EVENTS.BID_TIMEOUT, bid);
};
},
};

export function getImp(bid, id, mediaTypes) {
Expand All @@ -267,8 +271,12 @@ export function getImp(bid, id, mediaTypes) {
if (banner.bidfloorcur) imp.bidfloorcur = banner.bidfloorcur;
if (banner.bidfloor) imp.bidfloor = banner.bidfloor;

const format = (banner.data?.sizes || []).map(s => { return {w: s[0], h: s[1]} })
const {w, h} = (format[0] || {})
imp.banner = {
format: (banner.data?.sizes || []).map(s => { return {w: s[0], h: s[1]} }),
w,
h,
format,
};
};

Expand Down Expand Up @@ -487,126 +495,4 @@ function getSua() {
};
}

function getKeyWurl({auctionId, requestId}) {
return `${auctionId}-${requestId}`;
}

function addWurl({wurl, requestId, auctionId}) {
if (!wurl) return;

const expirence = Date.now() + EXPIRENCE_WURL;
const key = getKeyWurl({auctionId, requestId});
wurlMap[key] = {wurl, expirence};
}

function removeWurl({auctionId, requestId}) {
const key = getKeyWurl({auctionId, requestId});
delete wurlMap[key];
}

function getWurl({auctionId, requestId}) {
const key = getKeyWurl({auctionId, requestId});
return wurlMap[key] && wurlMap[key].wurl;
}

function bidWonHandler(bid) {
const {auctionId, requestId} = bid;
const wurl = getWurl({auctionId, requestId});
if (wurl) {
logMessage(`(nextmillennium) Invoking image pixel for wurl on BID_WIN: "${wurl}"`);
triggerPixel(wurl);
removeWurl({auctionId, requestId});
};
}

function auctionInitHandler() {
sendingDataStatistic.initEvents();
}

function cleanWurl() {
const dateNow = Date.now();
Object.keys(wurlMap).forEach(key => {
if (dateNow >= wurlMap[key].expirence) {
delete wurlMap[key];
};
});

setTimeout(cleanWurl, 60000);
}

function initSendingDataStatistic() {
class SendingDataStatistic {
eventNames = [
CONSTANTS.EVENTS.BID_TIMEOUT,
CONSTANTS.EVENTS.BID_RESPONSE,
CONSTANTS.EVENTS.BID_REQUESTED,
CONSTANTS.EVENTS.NO_BID,
];

disabledSending = false;
enabledSending = false;
eventHendlers = {};

initEvents() {
this.disabledSending = !!config.getBidderConfig()?.nextMillennium?.disabledSendingStatisticData;
if (this.disabledSending) {
this.removeEvents();
} else {
this.createEvents();
};
}

createEvents() {
if (this.enabledSending) return;

this.enabledSending = true;
for (let eventName of this.eventNames) {
if (!this.eventHendlers[eventName]) {
this.eventHendlers[eventName] = this.eventHandler(eventName);
};

events.on(eventName, this.eventHendlers[eventName]);
};
}

removeEvents() {
if (!this.enabledSending) return;

this.enabledSending = false;
for (let eventName of this.eventNames) {
if (!this.eventHendlers[eventName]) continue;

events.off(eventName, this.eventHendlers[eventName]);
};
}

eventHandler(eventName) {
const eventHandlerFunc = this.getEventHandler(eventName);
if (eventName == CONSTANTS.EVENTS.BID_TIMEOUT) {
return bids => {
if (this.disabledSending || !Array.isArray(bids)) return;

for (let bid of bids) {
eventHandlerFunc(bid);
};
}
};

return eventHandlerFunc;
}

getEventHandler(eventName) {
return bid => {
if (this.disabledSending) return;

const url = spec.getUrlPixelMetric(eventName, bid);
if (!url) return;
triggerPixel(url);
};
}
};

return new SendingDataStatistic();
}

registerBidder(spec);
4 changes: 2 additions & 2 deletions test/spec/modules/nextMillenniumBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe('nextMillenniumBidAdapterTests', () => {
bidfloorcur: 'EUR',
bidfloor: 1.11,
ext: {prebid: {storedrequest: {id: '123'}}},
banner: {format: [{w: 300, h: 250}, {w: 320, h: 250}]},
banner: {w: 300, h: 250, format: [{w: 300, h: 250}, {w: 320, h: 250}]},
},
},

Expand Down Expand Up @@ -902,7 +902,7 @@ describe('nextMillenniumBidAdapterTests', () => {
];

for (let {eventName, bid, expected} of dataForTests) {
const url = spec.getUrlPixelMetric(eventName, bid);
const url = spec._getUrlPixelMetric(eventName, bid);
expect(url).to.equal(expected);
};
})
Expand Down