Skip to content

Commit

Permalink
Fix bidResponse and bidWon responses
Browse files Browse the repository at this point in the history
  • Loading branch information
eldzis committed Nov 21, 2023
1 parent 3070cd8 commit 4d1ec31
Showing 1 changed file with 32 additions and 7 deletions.
39 changes: 32 additions & 7 deletions modules/setupadBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SYNC_ENDPOINT = 'https://cookie.stpd.cloud/sync?';
const REPORT_ENDPOINT = 'https://adapter-analytics.azurewebsites.net/api/adapter-analytics';
const GVLID = 1241;
const TIME_TO_LIVE = 360;
let seat = null;
const allBidders = {};

const sendingDataStatistic = initSendingDataStatistic();
events.on(CONSTANTS.EVENTS.AUCTION_INIT, () => {
Expand Down Expand Up @@ -148,7 +148,6 @@ export const spec = {

const serverBody = serverResponse.body;
const bidResponses = [];
seat = serverBody?.seatbid ? serverBody?.seatbid[0].seat : '';

_each(serverBody.seatbid, (res) => {
_each(res.bid, (bid) => {
Expand All @@ -171,6 +170,12 @@ 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;

bidResponse.ad = ad;
bidResponse.adUrl = adUrl;
bidResponses.push(bidResponse);
Expand Down Expand Up @@ -208,7 +213,7 @@ export const spec = {
},

getPixelUrl: function (eventName, bid, timestamp) {
const bidder = bid.bidder || bid.bidderCode;
let bidder = bid.bidder || bid.bidderCode;
const auctionId = bid.auctionId;
if (bidder != BIDDER_CODE) return;

Expand All @@ -235,13 +240,33 @@ export const spec = {

let extraBidParams = '';
// additional params on bidWon
if (eventName === 'bidWon' || eventName === 'bidResponse') {
if (eventName === 'bidWon') {

This comment has been minimized.

Copy link
@pashaGhub

pashaGhub Nov 22, 2023

we have bidWon handler below at line 256. Either move this part there or that part here

extraBidParams = `&cpm=${bid.originalCpm}&currency=${bid.originalCurrency}`;
}

const url = `${REPORT_ENDPOINT}?event=${eventName}&bidder=${
eventName === 'bidRequested' ? BIDDER_CODE : seat || bidder
}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}&timestamp=${timestamp}`;
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') {

This comment has been minimized.

Copy link
@pashaGhub

pashaGhub Nov 22, 2023

don't need "else" in this case (sugar syntax :D)

// Iterate through all bidders to find the winning bidder by using creativeId as identification
for (const bidderName in allBidders) {
if (
allBidders.hasOwnProperty(bidderName) &&
allBidders[bidderName].creativeId === bid.creativeId
) {
bidder = bidderName;
break; // Exit the loop once a match is found
}
}
}

const url = `${REPORT_ENDPOINT}?event=${eventName}&bidder=${bidder}&placementIds=${placementIds}&auctionId=${auctionId}${extraBidParams}&timestamp=${timestamp}`;

return url;
},
Expand Down

0 comments on commit 4d1ec31

Please sign in to comment.