Skip to content

Commit

Permalink
Magnite Analytics: auction index + small cleanup (prebid#11345)
Browse files Browse the repository at this point in the history
* move globals up + add auctionIndex

* add / update tests
  • Loading branch information
robertrmartinez authored and DecayConstant committed Jul 18, 2024
1 parent efee836 commit 4e8ef9f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
18 changes: 10 additions & 8 deletions modules/magniteAnalyticsAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ const LAST_SEEN_EXPIRE_TIME = 1800000; // 30 mins
const END_EXPIRE_TIME = 21600000; // 6 hours
const MODULE_NAME = 'Magnite Analytics';
const BID_REJECTED_IPF = 'rejected-ipf';
const DEFAULT_INTEGRATION = 'pbjs';

// List of known rubicon aliases
// This gets updated on auction init to account for any custom aliases present
Expand All @@ -48,6 +49,12 @@ const pbsErrorMap = {
}
let cookieless;

let browser;
let pageReferer;
let auctionIndex = 0; // count of auctions on page
let accountId;
let endpoint;

let prebidGlobal = getGlobal();
const {
AUCTION_INIT,
Expand Down Expand Up @@ -105,8 +112,6 @@ config.getConfig('s2sConfig', ({ s2sConfig }) => {
serverConfig = s2sConfig;
});

const DEFAULT_INTEGRATION = 'pbjs';

const adUnitIsOnlyInstream = adUnit => {
return adUnit.mediaTypes && Object.keys(adUnit.mediaTypes).length === 1 && deepAccess(adUnit, 'mediaTypes.video.context') === 'instream';
}
Expand Down Expand Up @@ -309,8 +314,6 @@ const addFloorData = floorData => {
}
}

let pageReferer;

const getTopLevelDetails = () => {
let payload = {
channel: 'web',
Expand Down Expand Up @@ -645,9 +648,6 @@ export const detectBrowserFromUa = userAgent => {
return 'OTHER';
}

let accountId;
let endpoint;

let magniteAdapter = adapter({ analyticsType: 'endpoint' });

magniteAdapter.originEnableAnalytics = magniteAdapter.enableAnalytics;
Expand Down Expand Up @@ -703,6 +703,7 @@ magniteAdapter.disableAnalytics = function () {
magniteAdapter._oldEnable = enableMgniAnalytics;
endpoint = undefined;
accountId = undefined;
auctionIndex = 0;
resetConfs();
getHook('callPrebidCache').getHooks({ hook: callPrebidCacheHook }).remove();
magniteAdapter.originDisableAnalytics();
Expand Down Expand Up @@ -791,10 +792,10 @@ const getLatencies = (args, auctionStart) => {
}
}

let browser;
magniteAdapter.track = ({ eventType, args }) => {
switch (eventType) {
case AUCTION_INIT:
auctionIndex += 1;
// Update session
cache.sessionData = storage.localStorageIsEnabled() && updateRpaCookie();
// set the rubicon aliases
Expand All @@ -810,6 +811,7 @@ magniteAdapter.track = ({ eventType, args }) => {
'timeout as clientTimeoutMillis',
]);
auctionData.accountId = accountId;
auctionData.auctionIndex = auctionIndex;

// get browser
if (!browser) {
Expand Down
18 changes: 17 additions & 1 deletion test/spec/modules/magniteAnalyticsAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ const ANALYTICS_MESSAGE = {
},
'auctions': [
{
'auctionIndex': 1,
'auctionId': '99785e47-a7c8-4c8a-ae05-ef1c717a4b4d',
'auctionStart': 1658868383741,
'samplingFactor': 1,
Expand Down Expand Up @@ -601,7 +602,22 @@ describe('magnite analytics adapter', function () {
it(`should parse browser from ${testData.expected} user agent correctly`, function () {
expect(detectBrowserFromUa(testData.ua)).to.equal(testData.expected);
});
})
});

it('should increment auctionIndex each auction', function () {
// run 3 auctions
performStandardAuction();
performStandardAuction();
performStandardAuction();

expect(server.requests.length).to.equal(3);
server.requests.forEach((request, index) => {
let message = JSON.parse(request.requestBody);

// should be index of array + 1
expect(message?.auctions?.[0].auctionIndex).to.equal(index + 1);
});
});

it('should pass along 1x1 size if no sizes in adUnit', function () {
const auctionInit = utils.deepClone(MOCK.AUCTION_INIT);
Expand Down

0 comments on commit 4e8ef9f

Please sign in to comment.