Skip to content

Commit

Permalink
Revert "Enhancements for the analytics adapter (#6991)"
Browse files Browse the repository at this point in the history
This reverts commit 196f633.
  • Loading branch information
ChrisHuie authored Jun 9, 2021
1 parent 196f633 commit a675c7d
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 43 deletions.
41 changes: 11 additions & 30 deletions modules/rubiconAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ function formatSource(src) {
return src.toLowerCase();
}

function sendMessage(auctionId, bidWonId, trigger) {
function sendMessage(auctionId, bidWonId) {
function formatBid(bid) {
return utils.pick(bid, [
'bidder',
Expand Down Expand Up @@ -163,12 +163,7 @@ function sendMessage(auctionId, bidWonId, trigger) {
let auctionCache = cache.auctions[auctionId];
let referrer = config.getConfig('pageUrl') || (auctionCache && auctionCache.referrer);
let message = {
timestamps: {
prebidLoaded: rubiconAdapter.MODULE_INITIALIZED_TIME,
auctionEnded: auctionCache.endTs,
eventTime: Date.now()
},
trigger,
eventTimeMillis: Date.now(),
integration: rubiConf.int_type || DEFAULT_INTEGRATION,
version: '$prebid.version$',
referrerUri: referrer,
Expand Down Expand Up @@ -324,10 +319,6 @@ function sendMessage(auctionId, bidWonId, trigger) {
);
}

function adUnitIsOnlyInstream(adUnit) {
return adUnit.mediaTypes && Object.keys(adUnit.mediaTypes).length === 1 && utils.deepAccess(adUnit, 'mediaTypes.video.context') === 'instream';
}

function getBidPrice(bid) {
// get the cpm from bidResponse
let cpm;
Expand Down Expand Up @@ -507,9 +498,9 @@ function subscribeToGamSlots() {
clearTimeout(cache.timeouts[auctionId]);
delete cache.timeouts[auctionId];
if (rubiConf.analyticsEventDelay > 0) {
setTimeout(() => sendMessage.call(rubiconAdapter, auctionId, undefined, 'delayedGam'), rubiConf.analyticsEventDelay)
setTimeout(() => sendMessage.call(rubiconAdapter, auctionId), rubiConf.analyticsEventDelay)
} else {
sendMessage.call(rubiconAdapter, auctionId, undefined, 'gam')
sendMessage.call(rubiconAdapter, auctionId)
}
}
});
Expand All @@ -518,7 +509,6 @@ function subscribeToGamSlots() {

let baseAdapter = adapter({analyticsType: 'endpoint'});
let rubiconAdapter = Object.assign({}, baseAdapter, {
MODULE_INITIALIZED_TIME: Date.now(),
referrerHostname: '',
enableAnalytics(config = {}) {
let error = false;
Expand Down Expand Up @@ -604,7 +594,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
// mark adUnits we expect bidWon events for
cache.auctions[args.auctionId].bidsWon[bid.adUnitCode] = false;

if (rubiConf.waitForGamSlots && !adUnitIsOnlyInstream(bid)) {
if (rubiConf.waitForGamSlots) {
cache.auctions[args.auctionId].gamHasRendered[bid.adUnitCode] = false;
}

Expand Down Expand Up @@ -760,7 +750,7 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {

// check if this BID_WON missed the boat, if so send by itself
if (auctionCache.sent === true) {
sendMessage.call(this, args.auctionId, args.requestId, 'soloBidWon');
sendMessage.call(this, args.auctionId, args.requestId);
} else if (!rubiConf.waitForGamSlots && Object.keys(auctionCache.bidsWon).reduce((memo, adUnitCode) => {
// only send if we've received bidWon events for all adUnits in auction
memo = memo && auctionCache.bidsWon[adUnitCode];
Expand All @@ -769,23 +759,14 @@ let rubiconAdapter = Object.assign({}, baseAdapter, {
clearTimeout(cache.timeouts[args.auctionId]);
delete cache.timeouts[args.auctionId];

sendMessage.call(this, args.auctionId, undefined, 'allBidWons');
sendMessage.call(this, args.auctionId);
}
break;
case AUCTION_END:
// see how long it takes for the payload to come fire
cache.auctions[args.auctionId].endTs = Date.now();

const isOnlyInstreamAuction = args.adUnits && args.adUnits.every(adUnit => adUnitIsOnlyInstream(adUnit));
// If only instream, do not wait around, just send payload
if (isOnlyInstreamAuction) {
sendMessage.call(this, args.auctionId, undefined, 'instreamAuction');
} else {
// start timer to send batched payload just in case we don't hear any BID_WON events
cache.timeouts[args.auctionId] = setTimeout(() => {
sendMessage.call(this, args.auctionId, undefined, 'auctionEnd');
}, rubiConf.analyticsBatchTimeout || SEND_TIMEOUT);
}
// start timer to send batched payload just in case we don't hear any BID_WON events
cache.timeouts[args.auctionId] = setTimeout(() => {
sendMessage.call(this, args.auctionId);
}, rubiConf.analyticsBatchTimeout || SEND_TIMEOUT);
break;
case BID_TIMEOUT:
args.forEach(badBid => {
Expand Down
15 changes: 2 additions & 13 deletions test/spec/modules/rubiconAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,12 +274,7 @@ const MOCK = {
}
}
},
'mediaTypes': {
'video': {
'context': 'instream',
'playerSize': [640, 480]
}
},
'mediaType': 'video',
'adUnitCode': '/19968336/header-bid-tag-0',
'transactionId': 'ca4af27a-6d02-4f90-949d-d5541fa12014',
'sizes': [[640, 480]],
Expand Down Expand Up @@ -367,6 +362,7 @@ const STUBBED_UUID = '12345678-1234-1234-1234-123456789abc';

const ANALYTICS_MESSAGE = {
'channel': 'web',
'eventTimeMillis': 1519767013781,
'integration': 'pbjs',
'version': '$prebid.version$',
'referrerUri': 'http://www.test.com/page.html',
Expand All @@ -375,12 +371,6 @@ const ANALYTICS_MESSAGE = {
'id': STUBBED_UUID,
'start': 1519767013781
},
'timestamps': {
'auctionEnded': 1519767013781,
'eventTime': 1519767013781,
'prebidLoaded': rubiconAnalyticsAdapter.MODULE_INITIALIZED_TIME
},
'trigger': 'allBidWons',
'referrerHostname': 'www.test.com',
'auctions': [
{
Expand Down Expand Up @@ -1668,7 +1658,6 @@ describe('rubicon analytics adapter', function () {
lineItemId: 6666,
adSlot: '/19968336/header-bid-tag1'
};
expectedMessage.trigger = 'gam';
expect(message).to.deep.equal(expectedMessage);
});

Expand Down
5 changes: 5 additions & 0 deletions test/spec/modules/rubiconAnalyticsSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "A batched data object describing the lifecycle of an auction or multiple auction across a single page view.",
"type": "object",
"required": [
"eventTimeMillis",
"integration",
"version"
],
Expand All @@ -20,6 +21,10 @@
}
],
"properties": {
"eventTimeMillis": {
"type": "integer",
"description": "Unix timestamp of time of creation for this batched event in milliseconds."
},
"integration": {
"type": "string",
"description": "Integration type that generated this event.",
Expand Down

0 comments on commit a675c7d

Please sign in to comment.