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

Greenbids Analytics Adapter : send params field to payload. #11642

Merged
merged 4 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 2 additions & 0 deletions modules/greenbidsAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
bidder: bid.bidder,
isTimeout: (status === BIDDER_STATUS.TIMEOUT),
hasBid: (status === BIDDER_STATUS.BID),
params: (bid.params && Object.keys(bid.params).length > 0) ? bid.params : {},
};
},
addBidResponseToMessage(message, bid, status) {
Expand All @@ -133,6 +134,7 @@ export const greenbidsAnalyticsAdapter = Object.assign(adapter({ANALYTICS_SERVER
if (bidderIndex === -1) {
message.adUnits[adUnitIndex].bidders.push(this.serializeBidResponse(bid, status));
} else {
message.adUnits[adUnitIndex].bidders[bidderIndex].params = (bid.params && Object.keys(bid.params).length > 0) ? bid.params : {};
if (status === BIDDER_STATUS.BID) {
message.adUnits[adUnitIndex].bidders[bidderIndex].hasBid = true;
message.adUnits[adUnitIndex].bidders[bidderIndex].cpm = bid.cpm;
Expand Down
76 changes: 40 additions & 36 deletions test/spec/modules/greenbidsAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
generateUUID
} from '../../../src/utils.js';
import * as utils from 'src/utils.js';
import {expect} from 'chai';
import { expect } from 'chai';
import sinon from 'sinon';

const events = require('src/events');
Expand Down Expand Up @@ -65,17 +65,17 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
greenbidsAnalyticsAdapter.disableAnalytics();
});

describe('#getCachedAuction()', function() {
const existing = {timeoutBids: [{}]};
describe('#getCachedAuction()', function () {
const existing = { timeoutBids: [{}] };
greenbidsAnalyticsAdapter.cachedAuctions['test_auction_id'] = existing;

it('should get the existing cached object if it exists', function() {
it('should get the existing cached object if it exists', function () {
const result = greenbidsAnalyticsAdapter.getCachedAuction('test_auction_id');

expect(result).to.equal(existing);
});

it('should create a new object and store it in the cache on cache miss', function() {
it('should create a new object and store it in the cache on cache miss', function () {
const result = greenbidsAnalyticsAdapter.getCachedAuction('no_such_id');

expect(result).to.deep.include({
Expand All @@ -84,7 +84,7 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

describe('when formatting JSON payload sent to backend', function() {
describe('when formatting JSON payload sent to backend', function () {
const receivedBids = [
{
auctionId: auctionId,
Expand All @@ -106,7 +106,8 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
timeToRespond: 100,
cpm: 0.08,
currency: 'USD',
ad: '<html>fake ad2</html>'
ad: '<html>fake ad2</html>',
params: {'placement ID': 12784}
},
{
auctionId: auctionId,
Expand Down Expand Up @@ -149,16 +150,16 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
}

describe('#createCommonMessage', function() {
it('should correctly serialize some common fields', function() {
describe('#createCommonMessage', function () {
it('should correctly serialize some common fields', function () {
const message = greenbidsAnalyticsAdapter.createCommonMessage(auctionId);

assertHavingRequiredMessageFields(message);
});
});

describe('#serializeBidResponse', function() {
it('should handle BID properly with timeout false and hasBid true', function() {
describe('#serializeBidResponse', function () {
it('should handle BID properly with timeout false and hasBid true', function () {
const result = greenbidsAnalyticsAdapter.serializeBidResponse(receivedBids[0], BIDDER_STATUS.BID);

expect(result).to.include({
Expand All @@ -168,7 +169,7 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

it('should handle NO_BID properly and set hasBid to false', function() {
it('should handle NO_BID properly and set hasBid to false', function () {
const result = greenbidsAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.NO_BID);

expect(result).to.include({
Expand All @@ -178,7 +179,7 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

it('should handle TIMEOUT properly and set isTimeout to true', function() {
it('should handle TIMEOUT properly and set isTimeout to true', function () {
const result = greenbidsAnalyticsAdapter.serializeBidResponse(noBids[0], BIDDER_STATUS.TIMEOUT);

expect(result).to.include({
Expand All @@ -189,8 +190,8 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

describe('#addBidResponseToMessage()', function() {
it('should add a bid response in the output message, grouped by adunit_id and bidder', function() {
describe('#addBidResponseToMessage()', function () {
it('should add a bid response in the output message, grouped by adunit_id and bidder', function () {
const message = {
adUnits: [
{
Expand All @@ -208,14 +209,15 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
bidder: 'greenbids',
isTimeout: false,
hasBid: false,
params: {}
}
]
});
});
});

describe('#createBidMessage()', function() {
it('should format auction message sent to the backend', function() {
describe('#createBidMessage()', function () {
it('should format auction message sent to the backend', function () {
const args = {
auctionId: auctionId,
timestamp: 1234567890,
Expand Down Expand Up @@ -258,10 +260,9 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
noBids: noBids
};

sinon.stub(greenbidsAnalyticsAdapter, 'getCachedAuction').returns({timeoutBids: timeoutBids});
sinon.stub(greenbidsAnalyticsAdapter, 'getCachedAuction').returns({ timeoutBids: timeoutBids });
const result = greenbidsAnalyticsAdapter.createBidMessage(args, timeoutBids);
greenbidsAnalyticsAdapter.getCachedAuction.restore();

assertHavingRequiredMessageFields(result);
expect(result).to.deep.include({
auctionElapsed: 100,
Expand All @@ -279,11 +280,13 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
bidder: 'greenbids',
isTimeout: false,
hasBid: true,
params: {}
},
{
bidder: 'greenbidsx',
isTimeout: false,
hasBid: true,
params: {'placement ID': 12784}
}
]
},
Expand Down Expand Up @@ -315,6 +318,7 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
hasBid: true,
cpm: 0.09,
currency: 'USD',
params: {}
}
]
}
Expand All @@ -323,8 +327,8 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

describe('#handleBidTimeout()', function() {
it('should cached the timeout bid as BID_TIMEOUT event was triggered', function() {
describe('#handleBidTimeout()', function () {
it('should cached the timeout bid as BID_TIMEOUT event was triggered', function () {
greenbidsAnalyticsAdapter.cachedAuctions['test_timeout_auction_id'] = { 'timeoutBids': [] };
const args = [{
auctionId: 'test_timeout_auction_id',
Expand Down Expand Up @@ -371,28 +375,28 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
events.getEvents.restore();
});

it('should call handleAuctionInit as AUCTION_INIT trigger event', function() {
it('should call handleAuctionInit as AUCTION_INIT trigger event', function () {
sinon.spy(greenbidsAnalyticsAdapter, 'handleAuctionInit');
events.emit(constants.EVENTS.AUCTION_INIT, {auctionId: 'auctionId'});
events.emit(constants.EVENTS.AUCTION_INIT, { auctionId: 'auctionId' });
sinon.assert.callCount(greenbidsAnalyticsAdapter.handleAuctionInit, 1);
greenbidsAnalyticsAdapter.handleAuctionInit.restore();
});

it('should call handleBidTimeout as BID_TIMEOUT trigger event', function() {
it('should call handleBidTimeout as BID_TIMEOUT trigger event', function () {
sinon.spy(greenbidsAnalyticsAdapter, 'handleBidTimeout');
events.emit(constants.EVENTS.BID_TIMEOUT, {auctionId: 'auctionId'});
events.emit(constants.EVENTS.BID_TIMEOUT, { auctionId: 'auctionId' });
sinon.assert.callCount(greenbidsAnalyticsAdapter.handleBidTimeout, 1);
greenbidsAnalyticsAdapter.handleBidTimeout.restore();
});

it('should call handleAuctionEnd as AUCTION_END trigger event', function() {
it('should call handleAuctionEnd as AUCTION_END trigger event', function () {
sinon.spy(greenbidsAnalyticsAdapter, 'handleAuctionEnd');
events.emit(constants.EVENTS.AUCTION_END, {auctionId: 'auctionId'});
events.emit(constants.EVENTS.AUCTION_END, { auctionId: 'auctionId' });
sinon.assert.callCount(greenbidsAnalyticsAdapter.handleAuctionEnd, 1);
greenbidsAnalyticsAdapter.handleAuctionEnd.restore();
});

it('should call handleBillable as BILLABLE_EVENT trigger event', function() {
it('should call handleBillable as BILLABLE_EVENT trigger event', function () {
sinon.spy(greenbidsAnalyticsAdapter, 'handleBillable');
events.emit(constants.EVENTS.BILLABLE_EVENT, {
type: 'auction',
Expand All @@ -405,34 +409,34 @@ describe('Greenbids Prebid AnalyticsAdapter Testing', function () {
});
});

describe('isSampled', function() {
it('should return true for invalid sampling rates', function() {
describe('isSampled', function () {
it('should return true for invalid sampling rates', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', -1, 0.0)).to.be.true;
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 1.2, 0.0)).to.be.true;
});

it('should return determinist falsevalue for valid sampling rate given the predifined id and rate', function() {
it('should return determinist falsevalue for valid sampling rate given the predifined id and rate', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0)).to.be.false;
});

it('should return determinist true value for valid sampling rate given the predifined id and rate', function() {
it('should return determinist true value for valid sampling rate given the predifined id and rate', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0)).to.be.true;
});

it('should return determinist true value for valid sampling rate given the predifined id and rate when we split to non exploration first', function() {
it('should return determinist true value for valid sampling rate given the predifined id and rate when we split to non exploration first', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.9999, 0.0, 1.0)).to.be.true;
});

it('should return determinist false value for valid sampling rate given the predifined id and rate when we split to non exploration first', function() {
it('should return determinist false value for valid sampling rate given the predifined id and rate when we split to non exploration first', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0, 1.0)).to.be.false;
});
});

describe('isSampled when analytic isforced', function() {
describe('isSampled when analytic isforced', function () {
before(() => {
sinon.stub(utils, 'getParameterByName').callsFake(par => par === 'greenbids_force_sampling' ? true : undefined);
});
it('should return determinist true when sampling flag activated', function() {
it('should return determinist true when sampling flag activated', function () {
expect(isSampled('ce1f3692-632c-4cfd-9e40-0c2ad625ec56', 0.0001, 0.0)).to.be.true;
});
after(() => {
Expand Down