From f5c61d9e75bff16c9bafc51a4e3c2c24ce7814af Mon Sep 17 00:00:00 2001 From: pavel Date: Tue, 30 Jan 2024 17:10:37 +0200 Subject: [PATCH] # This is a combination of 22 commits.tree 8abae7e6dffc9a21ad11770713ba485fc610028a parent cecfce3db84fdeca9bb9b66005f3c7aa6106d951 author pavel 1706627437 +0200 committer pavel 1706627437 +0200 gpgsig -----BEGIN PGP SIGNATURE----- iQIzBAABCAAdFiEEqGYI3KX/FkbObQG8FABtd4pCs/AFAmW5EW0ACgkQFABtd4pC s/CK3w//WWJSFUlycnnNKTV2XfdcBjooOeZZvjpXVthwr09CCC4uO//kw4bPluhn f5fcVFdXzrY1AZ6ch8Wo3msX/Pkso014jIGd5aIWcHpNYFtffACwH/40Y8AcJNZd bsOZxVK0awPTz/RihC5eY+0J3cP+iFWP/FlYJoHEQIBXq/Eg6mWoAhxwpL/JvxbY QbLFWsRn2ckQ6ftOZgm3/jh8VLaG1zWbWImlWEs5Zel+CorJBTniTj58VbApelYD TFMgbSR2I4NGVaqNIrHePnSMsDATxalQ2nZPwY6raKCHWIbvoUPIn/OpDMMbKgC7 nCwounNmObxFVoj3xusAZppzHpKPasY8xKWb2Kr7zfhZArsOMC6B7fYqQNK0cWG3 8RR/10oheJD9M2kRlfLiqnRv7ExY08SQ/ZMo9LA8BeRUGBXhh6++8FKhKIHvX1gL k1R5W6c+NNWP+PDFsmrFpMn+LpYdl84I7yfYK5dHuw80od7f1wuAVYpswi6Cziy9 /KY6/rfENvUrGTmWSh5GdDBel89ACCfFkasIKB92xhzKTfjzF/DXkc8XQZOMbt1j CsILgWMNfLPMo4Dlgdx/tYCSLLBNEtZ1/hhUcFQ3+0TzLf0GtMkvMnlBnDinqe1n 1P30fQ2I5W5NJKDPrCOnRymI6QOAPFXtMF11R81mbB9H8asft/E= =oJtZ -----END PGP SIGNATURE----- bugfixes # This is the commit message #22: Remove test parameter --- modules/setupadBidAdapter.js | 69 +++++++++------------ modules/setupadBidAdapter.md | 2 +- test/spec/modules/setupadBidAdapter_spec.js | 9 +-- 3 files changed, 37 insertions(+), 43 deletions(-) diff --git a/modules/setupadBidAdapter.js b/modules/setupadBidAdapter.js index 9e9dc4f99a3..6d54b56c827 100644 --- a/modules/setupadBidAdapter.js +++ b/modules/setupadBidAdapter.js @@ -17,10 +17,11 @@ import CONSTANTS from '../src/constants.json'; const BIDDER_CODE = 'setupad'; const ENDPOINT = 'https://prebid.setupad.io/openrtb2/auction'; const SYNC_ENDPOINT = 'https://cookie.stpd.cloud/sync?'; -const REPORT_ENDPOINT = 'https://adapter-analytics.azurewebsites.net/api/adapter-analytics'; +const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io'; const GVLID = 1241; const TIME_TO_LIVE = 360; -const allBidders = {}; +const biddersCpms = {}; +const biddersCreativeIds = {}; const sendingDataStatistic = initSendingDataStatistic(); events.on(CONSTANTS.EVENTS.AUCTION_INIT, () => { @@ -75,7 +76,6 @@ export const spec = { device, site, imp: [], - test: 1, }; const imp = { @@ -171,10 +171,8 @@ export const spec = { }; // Set all bidders obj for later use in getPixelUrl() - allBidders[res.seat] = {}; - allBidders[res.seat].cpm = bidResponse.cpm; - allBidders[res.seat].currency = bidResponse.currency; - allBidders[res.seat].creativeId = bidResponse.creativeId; + biddersCpms[res.seat] = bidResponse.cpm; + biddersCreativeIds[res.seat] = bidResponse.creativeId; bidResponse.ad = ad; bidResponse.adUrl = adUrl; @@ -215,7 +213,7 @@ export const spec = { getPixelUrl: function (eventName, bid, timestamp) { let bidder = bid.bidder || bid.bidderCode; const auctionId = bid.auctionId; - if (bidder != BIDDER_CODE) return; + if (bidder !== BIDDER_CODE) return; let params; if (bid.params) { @@ -239,31 +237,28 @@ export const spec = { if (!placementIds) return; let extraBidParams = ''; - // additional params on bidWon - if (eventName === 'bidWon') { - extraBidParams = `&cpm=${bid.originalCpm}¤cy=${bid.originalCurrency}`; + + if (eventName === CONSTANTS.EVENTS.BID_RESPONSE) { + bidder = JSON.stringify(biddersCpms); + + // Add extra parameters + extraBidParams = `¤cy=${bid.originalCurrency}`; } - if (eventName === 'bidResponse') { - // Exclude not needed creativeId key for bidResponse bidders - const filteredBidders = Object.fromEntries( - Object.entries(allBidders).map(([bidderKey, bidderObj]) => [ - bidderKey, - Object.fromEntries(Object.entries(bidderObj).filter(([key]) => key !== 'creativeId')), - ]) - ); - bidder = JSON.stringify(filteredBidders); - } else if (eventName === 'bidWon') { + if (eventName === CONSTANTS.EVENTS.BID_WON) { // Iterate through all bidders to find the winning bidder by using creativeId as identification - for (const bidderName in allBidders) { + for (const bidderName in biddersCreativeIds) { if ( - allBidders.hasOwnProperty(bidderName) && - allBidders[bidderName].creativeId === bid.creativeId + biddersCreativeIds.hasOwnProperty(bidderName) && + biddersCreativeIds[bidderName] === bid.creativeId ) { bidder = bidderName; - break; // Exit the loop once a match is found + break; // Exit the loop if a match is found } } + + // Add extra parameters + extraBidParams = `&cpm=${bid.originalCpm}¤cy=${bid.originalCurrency}`; } const url = `${REPORT_ENDPOINT}?event=${eventName}&bidder=${bidder}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}×tamp=${timestamp}`; @@ -357,6 +352,7 @@ function initSendingDataStatistic() { disabledSending = false; enabledSending = false; + auctionIds = {}; eventHendlers = {}; initEvents() { @@ -393,24 +389,21 @@ function initSendingDataStatistic() { } 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; + return this.getEventHandler(eventName); } getEventHandler(eventName) { return (bid) => { if (this.disabledSending) return; - + if ( + this.auctionIds[bid.auctionId] === bid.bidder && + eventName === CONSTANTS.EVENTS.BID_RESPONSE + ) { + return; + } + if (eventName === CONSTANTS.EVENTS.BID_RESPONSE) { + this.auctionIds[bid.auctionId] = bid.bidder; + } const url = spec.getPixelUrl(eventName, bid, Date.now()); if (!url) return; triggerPixel(url); diff --git a/modules/setupadBidAdapter.md b/modules/setupadBidAdapter.md index d9b72f05c0f..0d4f0ef392e 100644 --- a/modules/setupadBidAdapter.md +++ b/modules/setupadBidAdapter.md @@ -1,6 +1,6 @@ # Overview -``` +```text Module Name: Setupad Bid Adapter Module Type: Bidder Adapter Maintainer: it@setupad.com diff --git a/test/spec/modules/setupadBidAdapter_spec.js b/test/spec/modules/setupadBidAdapter_spec.js index ad1f870bb53..7c9cdae69e7 100644 --- a/test/spec/modules/setupadBidAdapter_spec.js +++ b/test/spec/modules/setupadBidAdapter_spec.js @@ -60,6 +60,7 @@ describe('SetupadAdapter', function () { h: 250, }, ], + seat: 'testBidder', }, ], cur: 'USD', @@ -242,7 +243,7 @@ describe('SetupadAdapter', function () { }); describe('getPixelUrl', function () { - const REPORT_ENDPOINT = 'https://adapter-analytics.azurewebsites.net/api/adapter-analytics'; + const REPORT_ENDPOINT = 'https://adapter-analytics.setupad.io'; const mockData = [ { timestamp: 123456789, @@ -324,12 +325,11 @@ describe('SetupadAdapter', function () { bid: { auctionId: 'test-auction-id', bidderCode: 'setupad', - originalCpm: 0.8, originalCurrency: 'USD', params: { placement_id: '123' }, }, - expected: `${REPORT_ENDPOINT}?event=bidResponse&bidder=setupad&placementIds=123&auctionId=test-auction-id&cpm=0.8¤cy=USD×tamp=123456789`, + expected: `${REPORT_ENDPOINT}?event=bidResponse&bidder={"testBidder":0.8}&placementIds=123&auctionId=test-auction-id¤cy=USD×tamp=123456789`, }, { @@ -385,11 +385,12 @@ describe('SetupadAdapter', function () { auctionId: 'test-auction-id', bidder: 'setupad', originalCpm: 0.8, + creativeId: 'test-bid-id', originalCurrency: 'USD', params: { placement_id: '123', account_id: 'test' }, }, - expected: `${REPORT_ENDPOINT}?event=bidWon&bidder=setupad&placementIds=123&auctionId=test-auction-id&cpm=0.8¤cy=USD×tamp=123456789`, + expected: `${REPORT_ENDPOINT}?event=bidWon&bidder=testBidder&placementIds=123&auctionId=test-auction-id&cpm=0.8¤cy=USD×tamp=123456789`, }, ];