Skip to content

Commit

Permalink
# This is a combination of 22 commits.tree 8abae7e6dffc9a21ad11770713…
Browse files Browse the repository at this point in the history
…ba485fc610028a

parent cecfce3
author pavel <pavel@setupad.com> 1706627437 +0200
committer pavel <pavel@setupad.com> 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 prebid#22:

Remove test parameter
  • Loading branch information
pavel committed Jan 30, 2024
1 parent cecfce3 commit f5c61d9
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 43 deletions.
69 changes: 31 additions & 38 deletions modules/setupadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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, () => {
Expand Down Expand Up @@ -75,7 +76,6 @@ export const spec = {
device,
site,
imp: [],
test: 1,
};

const imp = {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -239,31 +237,28 @@ export const spec = {
if (!placementIds) return;

let extraBidParams = '';
// additional params on bidWon
if (eventName === 'bidWon') {
extraBidParams = `&cpm=${bid.originalCpm}&currency=${bid.originalCurrency}`;

if (eventName === CONSTANTS.EVENTS.BID_RESPONSE) {
bidder = JSON.stringify(biddersCpms);

// Add extra parameters
extraBidParams = `&currency=${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}&currency=${bid.originalCurrency}`;
}

const url = `${REPORT_ENDPOINT}?event=${eventName}&bidder=${bidder}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}&timestamp=${timestamp}`;
Expand Down Expand Up @@ -357,6 +352,7 @@ function initSendingDataStatistic() {

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

initEvents() {
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion modules/setupadBidAdapter.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Overview

```
```text
Module Name: Setupad Bid Adapter
Module Type: Bidder Adapter
Maintainer: it@setupad.com
Expand Down
9 changes: 5 additions & 4 deletions test/spec/modules/setupadBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ describe('SetupadAdapter', function () {
h: 250,
},
],
seat: 'testBidder',
},
],
cur: 'USD',
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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&currency=USD&timestamp=123456789`,
expected: `${REPORT_ENDPOINT}?event=bidResponse&bidder={"testBidder":0.8}&placementIds=123&auctionId=test-auction-id&currency=USD&timestamp=123456789`,
},

{
Expand Down Expand Up @@ -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&currency=USD&timestamp=123456789`,
expected: `${REPORT_ENDPOINT}?event=bidWon&bidder=testBidder&placementIds=123&auctionId=test-auction-id&cpm=0.8&currency=USD&timestamp=123456789`,
},
];

Expand Down

0 comments on commit f5c61d9

Please sign in to comment.