Skip to content

Commit

Permalink
Greenbids Analytics : send cpm on any valid bid (prebid#12174)
Browse files Browse the repository at this point in the history
* fix(greenbids,analytics): send cpm on any valid bid (#5)

* fix(greenbids,analytics): cpm not passed

* bump version number

* fix unit tests
  • Loading branch information
AlexisBRENON authored Aug 30, 2024
1 parent b7efc5a commit 360c3ea
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
28 changes: 27 additions & 1 deletion modules/greenbidsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,17 @@ import { EVENTS } from '../src/constants.js';
import adapterManager from '../src/adapterManager.js';
import {deepClone, generateUUID, logError, logInfo, logWarn, getParameterByName} from '../src/utils.js';

/**
* @typedef {import('../src/adapters/bidderFactory.js').Bid} Bid
*/

/**
* @typedef {object} Message Payload message sent to the Greenbids API
*/

const analyticsType = 'endpoint';

export const ANALYTICS_VERSION = '2.3.1';
export const ANALYTICS_VERSION = '2.3.2';

const ANALYTICS_SERVER = 'https://a.greenbids.ai';

Expand Down Expand Up @@ -97,6 +105,11 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
contentType: 'application/json'
});
},
/**
*
* @param {string} auctionId
* @returns {Message}
*/
createCommonMessage(auctionId) {
const cachedAuction = this.getCachedAuction(auctionId);
return {
Expand All @@ -111,14 +124,27 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
adUnits: [],
};
},
/**
* @param {Bid} bid
* @param {BIDDER_STATUS} status
*/
serializeBidResponse(bid, status) {
return {
bidder: bid.bidder,
isTimeout: (status === BIDDER_STATUS.TIMEOUT),
hasBid: (status === BIDDER_STATUS.BID),
params: (bid.params && Object.keys(bid.params).length > 0) ? bid.params : {},
...(status === BIDDER_STATUS.BID ? {
cpm: bid.cpm,
currency: bid.currency
} : {}),
};
},
/**
* @param {*} message Greenbids API payload
* @param {Bid} bid Bid to add to the payload
* @param {BIDDER_STATUS} status Bidding status
*/
addBidResponseToMessage(message, bid, status) {
const adUnitCode = bid.adUnitCode.toLowerCase();
const adUnitIndex = message.adUnits.findIndex((adUnit) => {
Expand Down
8 changes: 6 additions & 2 deletions test/spec/modules/greenbidsAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,13 +280,17 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
bidder: 'greenbids',
isTimeout: false,
hasBid: true,
params: {}
params: {},
cpm: 0.1,
currency: 'USD',
},
{
bidder: 'greenbidsx',
isTimeout: false,
hasBid: true,
params: {'placement ID': 12784}
params: { 'placement ID': 12784 },
cpm: 0.08,
currency: 'USD',
}
]
},
Expand Down

0 comments on commit 360c3ea

Please sign in to comment.