Skip to content

Commit 5fcfd79

Browse files
analytics for on page message sending
1 parent b10fb27 commit 5fcfd79

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

modules/rubiconAnalyticsAdapter.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function formatSource(src) {
115115
return src.toLowerCase();
116116
}
117117

118-
function sendMessage(auctionId, bidWonId) {
118+
function sendMessage(auctionId, bidWonId, trigger) {
119119
function formatBid(bid) {
120120
return utils.pick(bid, [
121121
'bidder',
@@ -163,6 +163,7 @@ function sendMessage(auctionId, bidWonId) {
163163
let auctionCache = cache.auctions[auctionId];
164164
let referrer = config.getConfig('pageUrl') || (auctionCache && auctionCache.referrer);
165165
let message = {
166+
trigger,
166167
eventTimeMillis: Date.now(),
167168
integration: rubiConf.int_type || DEFAULT_INTEGRATION,
168169
version: '$prebid.version$',
@@ -301,8 +302,10 @@ function sendMessage(auctionId, bidWonId) {
301302
message.bidsWon = bidsWon;
302303
}
303304

305+
message.eventTiming = Math.round(utils.getPerformanceNow() - auctionCache.endTs);
304306
auctionCache.sent = true;
305307
} else if (bidWonId && auctionCache && auctionCache.bids[bidWonId]) {
308+
message.eventTiming = Math.round(utils.getPerformanceNow() - auctionCache.endTs);
306309
message.bidsWon = [
307310
formatBidWon(auctionCache.bids[bidWonId])
308311
];
@@ -496,9 +499,9 @@ function subscribeToGamSlots() {
496499
clearTimeout(cache.timeouts[auctionId]);
497500
delete cache.timeouts[auctionId];
498501
if (rubiConf.analyticsEventDelay > 0) {
499-
setTimeout(() => sendMessage.call(rubiconAdapter, auctionId), rubiConf.analyticsEventDelay)
502+
setTimeout(() => sendMessage.call(rubiconAdapter, auctionId, undefined, 'delayedGam'), rubiConf.analyticsEventDelay)
500503
} else {
501-
sendMessage.call(rubiconAdapter, auctionId)
504+
sendMessage.call(rubiconAdapter, auctionId, undefined, 'gam')
502505
}
503506
}
504507
});
@@ -748,7 +751,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
748751

749752
// check if this BID_WON missed the boat, if so send by itself
750753
if (auctionCache.sent === true) {
751-
sendMessage.call(this, args.auctionId, args.requestId);
754+
sendMessage.call(this, args.auctionId, args.requestId, 'soloBidWon');
752755
} else if (!rubiConf.waitForGamSlots && Object.keys(auctionCache.bidsWon).reduce((memo, adUnitCode) => {
753756
// only send if we've received bidWon events for all adUnits in auction
754757
memo = memo && auctionCache.bidsWon[adUnitCode];
@@ -757,13 +760,15 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
757760
clearTimeout(cache.timeouts[args.auctionId]);
758761
delete cache.timeouts[args.auctionId];
759762

760-
sendMessage.call(this, args.auctionId);
763+
sendMessage.call(this, args.auctionId, undefined, 'allBidWons');
761764
}
762765
break;
763766
case AUCTION_END:
767+
// see how long it takes for the payload to come fire
768+
cache.auctions[args.auctionId].endTs = utils.getPerformanceNow();
764769
// start timer to send batched payload just in case we don't hear any BID_WON events
765770
cache.timeouts[args.auctionId] = setTimeout(() => {
766-
sendMessage.call(this, args.auctionId);
771+
sendMessage.call(this, args.auctionId, undefined, 'auctionEnd');
767772
}, rubiConf.analyticsBatchTimeout || SEND_TIMEOUT);
768773
break;
769774
case BID_TIMEOUT:

0 commit comments

Comments
 (0)