Skip to content

Commit

Permalink
Magnite Analytics Adapter : track to PBS Analytics Event and ATAG (#1…
Browse files Browse the repository at this point in the history
…2043)

* Update constants.js

* Update magniteAnalyticsAdapter.js

* Update magniteAnalyticsAdapter_spec.js
  • Loading branch information
spotxslagle authored Oct 8, 2024
1 parent 7ac768f commit da9f7ca
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 6 deletions.
51 changes: 46 additions & 5 deletions modules/magniteAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ const {
BID_TIMEOUT,
BID_WON,
BILLABLE_EVENT,
SEAT_NON_BID,
PBS_ANALYTICS,
BID_REJECTED
} = EVENTS;

Expand Down Expand Up @@ -927,8 +927,8 @@ magniteAdapter.track = ({ eventType, args }) => {
const bidStatus = args.rejectionReason === REJECTION_REASON.FLOOR_NOT_MET ? BID_REJECTED_IPF : 'rejected';
handleBidResponse(args, bidStatus);
break;
case SEAT_NON_BID:
handleNonBidEvent(args);
case PBS_ANALYTICS:
handlePbsAnalytics(args);
break;
case BIDDER_DONE:
const serverError = deepAccess(args, 'serverErrors.0');
Expand Down Expand Up @@ -1019,8 +1019,27 @@ magniteAdapter.track = ({ eventType, args }) => {
}
};

const handleNonBidEvent = function(args) {
const {seatnonbid, auctionId} = args;
const handlePbsAnalytics = function (args) {
const {seatnonbid, auctionId, atag} = args;
if (seatnonbid) {
handleNonBidEvent(seatnonbid, auctionId);
}
if (atag) {
handleAtagEvent(atag, auctionId);
}
}

const handleAtagEvent = function (atag, auctionId) {
const tags = findTimeoutOptimization(atag)
tags.forEach(tag => {
tag.activities.forEach(activity => {
if (activity.name === 'optimize-tmax' && activity.status === 'success') {
setAnalyticsTagData(activity.results[0]?.values, deepAccess(cache, `auctions.${auctionId}.auction`))
}
})
});
}
const handleNonBidEvent = function(seatnonbid, auctionId) {
const auction = deepAccess(cache, `auctions.${auctionId}.auction`);
// if no auction just bail
if (!auction) {
Expand Down Expand Up @@ -1050,6 +1069,28 @@ const handleNonBidEvent = function(args) {
});
};

const findTimeoutOptimization = (atag) => {
let timeoutOpt;
atag.forEach(tag => {
if (tag.module === 'mgni-timeout-optimization') {
timeoutOpt = tag.analyticstags;
}
})
return timeoutOpt;
}
const setAnalyticsTagData = (values, auction) => {
let data = {
name: values.scenario,
rule: values.rule,
value: values.tmax
}

const experiments = deepAccess(auction, 'experiments') || [];
experiments.push(data);

deepSetValue(auction, 'experiments', experiments);
}

const statusMap = {
0: {
status: 'no-bid'
Expand Down
42 changes: 41 additions & 1 deletion test/spec/modules/magniteAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const {
BID_TIMEOUT,
BILLABLE_EVENT,
SEAT_NON_BID,
PBS_ANALYTICS,
BID_REJECTED
} = EVENTS;

Expand Down Expand Up @@ -639,6 +640,45 @@ describe('magnite analytics adapter', function () {
]);
});

it('should pass along atag data', function () {
const PBS_ANALYTICS_EVENT = {
'auctionId': '99785e47-a7c8-4c8a-ae05-ef1c717a4b4d',
atag: [{
'stage': 'processed-auction-request',
'module': 'mgni-timeout-optimization',
'analyticstags': [{
activities: [{
name: 'optimize-tmax',
status: 'success',
results: [{
status: 'success',
values: {
'scenario': 'a',
'rule': 'b',
'tmax': 3
}
}]
}]
}]
}]
}

events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(BID_RESPONSE, MOCK.BID_RESPONSE);
events.emit(PBS_ANALYTICS, PBS_ANALYTICS_EVENT)
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
clock.tick(rubiConf.analyticsBatchTimeout + 1000);

let message = JSON.parse(server.requests[0].requestBody);
expect(message.auctions[0].experiments[0]).to.deep.equal({
name: 'a',
rule: 'b',
value: 3
});
});

it('should pass along user ids', function () {
let auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
auctionInit.bidderRequests[0].bids[0].userId = {
Expand Down Expand Up @@ -2262,7 +2302,7 @@ describe('magnite analytics adapter', function () {
const runNonBidAuction = () => {
events.emit(AUCTION_INIT, MOCK.AUCTION_INIT);
events.emit(BID_REQUESTED, MOCK.BID_REQUESTED);
events.emit(SEAT_NON_BID, seatnonbid)
events.emit(PBS_ANALYTICS, seatnonbid)
events.emit(BIDDER_DONE, MOCK.BIDDER_DONE);
events.emit(AUCTION_END, MOCK.AUCTION_END);
clock.tick(rubiConf.analyticsBatchTimeout + 1000);
Expand Down

0 comments on commit da9f7ca

Please sign in to comment.