-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kargo Analytics Adapter: Bid response time logging #8510
Merged
Merged
Changes from 18 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
5e6bd1a
Kargo Bid Adapter: Use currency from Bid Response
wwongkargo 797a0f7
Kargo Bid Adapter: Fix failed test
wwongkargo 88d6cfd
Kargo Bid Adapter: adding media type to bid response, supporting vast…
andyrusiecki 2d79302
Merge branch 'prebid:master' into master
jsadwith 0a03e35
Kargo Bid Adapter: onTimeout Support (#6)
jsadwith 2bdf502
Adding additional param
jsadwith b634652
Adding response time function
jsadwith 5f6f448
Remove debug
jsadwith 50e0224
Updating response time log to be set by bid response
jsadwith a5eda12
Adding screen width/height to request
jsadwith f066881
Test fix
jsadwith 62b1c1e
Test fix
jsadwith 478191f
Removing interpretResponse signaling
jsadwith d884b69
Simplifying send data function
jsadwith 451080f
Merge branch 'prebid:master' into master
jsadwith c012a35
Kargo Analytics Adapter: Update with bid response time support
jsadwith 514f8ce
Renaming event route for auction data
jsadwith 8639ae7
Reset bid response data sent bool
jsadwith 47646ea
Using array to store logged auctions
jsadwith 5ebbffb
Update to use timeToResponse
jsadwith 2dac35a
Test fix
jsadwith File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,98 @@ | ||
import { logError } from '../src/utils.js'; | ||
import { ajax } from '../src/ajax.js'; | ||
import adapter from '../src/AnalyticsAdapter.js'; | ||
import adapterManager from '../src/adapterManager.js'; | ||
import CONSTANTS from '../src/constants.json'; | ||
|
||
var kargoAdapter = adapter({ | ||
analyticsType: 'endpoint', | ||
url: 'https://krk.kargo.com/api/v1/event/prebid' | ||
}); | ||
const EVENT_URL = 'https://krk.kargo.com/api/v1/event'; | ||
const KARGO_BIDDER_CODE = 'kargo'; | ||
|
||
const analyticsType = 'endpoint'; | ||
|
||
let _initOptions = {}; | ||
|
||
let _logBidResponseData = { | ||
auctionId: '', | ||
auctionTimeout: 0, | ||
responseTime: 0, | ||
}; | ||
|
||
let _bidResponseDataSent = false; | ||
|
||
var kargoAnalyticsAdapter = Object.assign( | ||
adapter({ analyticsType }), { | ||
track({ eventType, args }) { | ||
switch (eventType) { | ||
case CONSTANTS.EVENTS.AUCTION_INIT: { | ||
_logBidResponseData.auctionTimeout = args.timeout; | ||
break; | ||
} | ||
case CONSTANTS.EVENTS.BID_RESPONSE: { | ||
handleBidResponseData(args); | ||
break; | ||
} | ||
case CONSTANTS.EVENTS.AUCTION_END: { | ||
// Reset bool for whether or not to send bid response data | ||
_bidResponseDataSent = false; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
); | ||
|
||
function handleBidResponseData (bidResponse) { | ||
if (bidResponse.bidder !== KARGO_BIDDER_CODE || _bidResponseDataSent) { | ||
return | ||
} | ||
|
||
_logBidResponseData.auctionId = bidResponse.auctionId; | ||
_logBidResponseData.responseTime = bidResponse.responseTimestamp - bidResponse.requestTimestamp; | ||
sendBidResponseData(_logBidResponseData); | ||
|
||
_bidResponseDataSent = true; | ||
} | ||
|
||
function sendBidResponseData (data) { | ||
try { | ||
if (!shouldFireEventRequest()) { | ||
return; | ||
} | ||
|
||
ajax( | ||
`${EVENT_URL}/auction-data`, | ||
null, | ||
{ | ||
aid: data.auctionId, | ||
ato: data.auctionTimeout, | ||
rt: data.responseTime, | ||
it: 0, | ||
}, | ||
{ | ||
method: 'GET', | ||
} | ||
); | ||
} catch (err) { | ||
logError('Error sending auction data: ', err); | ||
} | ||
} | ||
|
||
// Sampling rate out of 100 | ||
function shouldFireEventRequest () { | ||
const samplingRate = (_initOptions && _initOptions.sampling) || 100; | ||
return ((Math.floor(Math.random() * 100) + 1) <= parseInt(samplingRate)); | ||
} | ||
|
||
kargoAnalyticsAdapter.originEnableAnalytics = kargoAnalyticsAdapter.enableAnalytics; | ||
|
||
kargoAnalyticsAdapter.enableAnalytics = function (config) { | ||
_initOptions = config.options; | ||
kargoAnalyticsAdapter.originEnableAnalytics(config); | ||
}; | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: kargoAdapter, | ||
adapter: kargoAnalyticsAdapter, | ||
code: 'kargo' | ||
}); | ||
|
||
export default kargoAdapter; | ||
export default kargoAnalyticsAdapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Overview | ||
|
||
Module Name: Kargo Analytics Adapter | ||
Module Type: Analytics Adapter | ||
Maintainer: [email protected] | ||
|
||
# Description | ||
|
||
Analytics adapter for Kargo. Contact [email protected] for information. | ||
|
||
# Usage | ||
|
||
The simplest way to enable the analytics adapter is this | ||
|
||
```javascript | ||
pbjs.enableAnalytics([{ | ||
provider: 'kargo', | ||
options: { | ||
sampling: 100 // value out of 100 | ||
} | ||
}]); | ||
``` | ||
|
||
# Test Parameters | ||
|
||
``` | ||
{ | ||
provider: 'kargo', | ||
options: { | ||
sampling: 100 | ||
} | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import kargoAnalyticsAdapter from 'modules/kargoAnalyticsAdapter.js'; | ||
import { expect } from 'chai'; | ||
import { server } from 'test/mocks/xhr.js'; | ||
let events = require('src/events'); | ||
let constants = require('src/constants.json'); | ||
|
||
describe('Kargo Analytics Adapter', function () { | ||
const adapterConfig = { | ||
provider: 'kargoAnalytics', | ||
}; | ||
|
||
after(function () { | ||
kargoAnalyticsAdapter.disableAnalytics(); | ||
}); | ||
|
||
describe('main test flow', function () { | ||
beforeEach(function () { | ||
kargoAnalyticsAdapter.enableAnalytics(adapterConfig); | ||
sinon.stub(events, 'getEvents').returns([]); | ||
}); | ||
|
||
afterEach(function () { | ||
events.getEvents.restore(); | ||
}); | ||
|
||
it('bid response data should send one request with auction ID, auction timeout, and response time', function() { | ||
const bidResponse = { | ||
bidder: 'kargo', | ||
auctionId: '66529d4c-8998-47c2-ab3e-5b953490b98f', | ||
requestTimestamp: 1652283459030, | ||
responseTimestamp: 1652283459222, | ||
}; | ||
|
||
events.emit(constants.EVENTS.AUCTION_INIT, { | ||
timeout: 1000 | ||
}); | ||
events.emit(constants.EVENTS.BID_RESPONSE, bidResponse); | ||
|
||
expect(server.requests.length).to.equal(1); | ||
expect(server.requests[0].url).to.equal('https://krk.kargo.com/api/v1/event/auction-data?aid=66529d4c-8998-47c2-ab3e-5b953490b98f&ato=1000&rt=192&it=0'); | ||
}); | ||
}); | ||
}); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think prebid core sets a param on this object called
timeToRespond
which is essentially this.Also, you want to only track when your exchange does a VALID bid response? Not when it no-bids or errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated to use
timeToResponse
- thanks for pointing that out.Confirmed - for now we want to just track valid bid responses.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this still is using response - request timestamps.
It is really up to you, just noting that there is
timeToRespond
available which is essentially the same thing.