Skip to content

Commit

Permalink
VIS.X: add response time tracking on bidWon event (#10772)
Browse files Browse the repository at this point in the history
  • Loading branch information
vfedoseev authored Dec 5, 2023
1 parent f818b8f commit 9a65d49
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 1 deletion.
23 changes: 23 additions & 0 deletions modules/visxBidAdapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const TIME_TO_LIVE = 360;
const DEFAULT_CUR = 'EUR';
const ADAPTER_SYNC_PATH = '/push_sync';
const TRACK_TIMEOUT_PATH = '/track/bid_timeout';
const RUNTIME_STATUS_RESPONSE_TIME = 999000;
const LOG_ERROR_MESS = {
noAuid: 'Bid from response has no auid parameter - ',
noAdm: 'Bid from response has no adm parameter - ',
Expand All @@ -33,6 +34,7 @@ const LOG_ERROR_MESS = {
};
const currencyWhiteList = ['EUR', 'USD', 'GBP', 'PLN'];
export const storage = getStorageManager({bidderCode: BIDDER_CODE});
const _bidResponseTimeLogged = [];
export const spec = {
code: BIDDER_CODE,
gvlid: GVLID,
Expand Down Expand Up @@ -208,6 +210,12 @@ export const spec = {
if (bid.ext && bid.ext.events && bid.ext.events.win) {
triggerPixel(bid.ext.events.win);
}
// Call 'track/runtime' with the corresponding bid.requestId - only once per auction
if (bid.ext && bid.ext.events && bid.ext.events.runtime && !_bidResponseTimeLogged.includes(bid.auctionId)) {
_bidResponseTimeLogged.push(bid.auctionId);
const _roundedTime = _roundResponseTime(bid.timeToRespond, 50);
triggerPixel(bid.ext.events.runtime.replace('{STATUS_CODE}', RUNTIME_STATUS_RESPONSE_TIME + _roundedTime));
}
},
onTimeout: function(timeoutData) {
// Call '/track/bid_timeout' with timeout data
Expand Down Expand Up @@ -321,6 +329,10 @@ function _addBidResponse(serverBid, bidsMap, currency, bidResponses) {

if (serverBid.ext && serverBid.ext.prebid) {
bidResponse.ext = serverBid.ext.prebid;
if (serverBid.ext.visx && serverBid.ext.visx.events) {
const prebidExtEvents = bidResponse.ext.events || {};
bidResponse.ext.events = Object.assign(prebidExtEvents, serverBid.ext.visx.events);
}
}

const visxTargeting = deepAccess(serverBid, 'ext.prebid.targeting');
Expand Down Expand Up @@ -434,4 +446,15 @@ function _getUserId() {
return null;
}

function _roundResponseTime(time, timeRange) {
if (time <= 0) {
return 0; // Special code for scriptLoadTime of 0 ms or less
} else if (time > 5000) {
return 100; // Constant code for scriptLoadTime greater than 5000 ms
} else {
const roundedValue = Math.floor((time - 1) / timeRange) + 1;
return roundedValue;
}
}

registerBidder(spec);
40 changes: 39 additions & 1 deletion test/spec/modules/visxBidAdapter_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ describe('VisxAdapter', function () {
const request = spec.buildRequests(bidRequests);
const pendingUrl = 'https://t.visx.net/track/pending/123123123';
const winUrl = 'https://t.visx.net/track/win/53245341';
const runtimeUrl = 'https://t.visx.net/track/status/12345678';
const expectedResponse = [
{
'requestId': '300bfeb0d71a5b',
Expand All @@ -1281,7 +1282,8 @@ describe('VisxAdapter', function () {
'ext': {
'events': {
'pending': pendingUrl,
'win': winUrl
'win': winUrl,
'runtime': runtimeUrl
},
'targeting': {
'hb_visx_product': 'understitial',
Expand All @@ -1298,6 +1300,9 @@ describe('VisxAdapter', function () {
pending: pendingUrl,
win: winUrl,
});
utils.deepSetValue(serverResponse.bid[0], 'ext.visx.events', {
runtime: runtimeUrl
});
const result = spec.interpretResponse({'body': {'seatbid': [serverResponse]}}, request);
expect(result).to.deep.equal(expectedResponse);
});
Expand Down Expand Up @@ -1325,6 +1330,39 @@ describe('VisxAdapter', function () {
expect(utils.triggerPixel.calledOnceWith(trackUrl)).to.equal(true);
});

it('onBidWon with runtime tracker (0 < timeToRespond <= 5000 )', function () {
const trackUrl = 'https://t.visx.net/track/win/123123123';
const runtimeUrl = 'https://t.visx.net/track/status/12345678/{STATUS_CODE}';
const bid = { auctionId: '1', ext: { events: { win: trackUrl, runtime: runtimeUrl } }, timeToRespond: 100 };
spec.onBidWon(bid);
expect(utils.triggerPixel.calledTwice).to.equal(true);
expect(utils.triggerPixel.calledWith(trackUrl)).to.equal(true);
expect(utils.triggerPixel.calledWith(runtimeUrl.replace('{STATUS_CODE}', 999002))).to.equal(true);
});

it('onBidWon with runtime tracker (timeToRespond <= 0 )', function () {
const runtimeUrl = 'https://t.visx.net/track/status/12345678/{STATUS_CODE}';
const bid = { auctionId: '2', ext: { events: { runtime: runtimeUrl } }, timeToRespond: 0 };
spec.onBidWon(bid);
expect(utils.triggerPixel.calledOnceWith(runtimeUrl.replace('{STATUS_CODE}', 999000))).to.equal(true);
});

it('onBidWon with runtime tracker (timeToRespond > 5000 )', function () {
const runtimeUrl = 'https://t.visx.net/track/status/12345678/{STATUS_CODE}';
const bid = { auctionId: '3', ext: { events: { runtime: runtimeUrl } }, timeToRespond: 5001 };
spec.onBidWon(bid);
expect(utils.triggerPixel.calledOnceWith(runtimeUrl.replace('{STATUS_CODE}', 999100))).to.equal(true);
});

it('onBidWon runtime tracker should be called once per auction', function () {
const runtimeUrl = 'https://t.visx.net/track/status/12345678/{STATUS_CODE}';
const bid1 = { auctionId: '4', ext: { events: { runtime: runtimeUrl } }, timeToRespond: 100 };
spec.onBidWon(bid1);
const bid2 = { auctionId: '4', ext: { events: { runtime: runtimeUrl } }, timeToRespond: 200 };
spec.onBidWon(bid2);
expect(utils.triggerPixel.calledOnceWith(runtimeUrl.replace('{STATUS_CODE}', 999002))).to.equal(true);
});

it('onTimeout', function () {
const data = [{ timeout: 3000, adUnitCode: 'adunit-code-1', auctionId: '1cbd2feafe5e8b', bidder: 'visx', bidId: '23423', params: [{ uid: '1' }] }];
const expectedData = [{ timeout: 3000, params: [{ uid: 1 }] }];
Expand Down

0 comments on commit 9a65d49

Please sign in to comment.