-
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
New version of Konduit Accelerate module #5164
Merged
Merged
Changes from 16 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
95faa22
Adding Konduit module
6adc687
Removed superfluous arguments passed to obtainVastUrl function
bc6d752
Removed superfluous arguments passed to obtainVastUrl function.
67e7957
Build trigger (empty commit)
alexander-kislitsyn f0d6e34
Module documentation updated according to the comments
9995e57
Merge branch 'master' of https://github.com/konduit-dev/Prebid.js
105513b
Logic in obtainVastUrl function updated according to the review comment.
alexander-kislitsyn 440aae0
Merge branch 'master' of https://github.com/konduit-dev/Prebid.js
alexander-kislitsyn 191a498
Removed hook, enabled eslint
6eabb0d
Merged recent prebid changes
2250e89
New method is introduced to process a bid and return dynamic CPM data
048c28a
New Konduit Analytics adapter responsible for client auction stats co…
f2f7fba
Updated konduit analytics adapter .md file
a8af558
Merged with Prebid master
92c8055
Fixed linter issue with more than 1 blank line used
a714eb5
Merge branch 'master' of https://github.com/prebid/Prebid.js
cb50ac8
Use '$prebid.version$' instead of the $$PREBID_GLOBAL$$.version
10a2842
Updated unit tests
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 |
---|---|---|
@@ -0,0 +1,225 @@ | ||
import { ajax } from '../src/ajax.js'; | ||
import adapter from '../src/AnalyticsAdapter.js'; | ||
import adapterManager from '../src/adapterManager.js'; | ||
import * as utils from '../src/utils.js'; | ||
import { targeting } from '../src/targeting.js'; | ||
import { config } from '../src/config.js'; | ||
import CONSTANTS from '../src/constants.json'; | ||
|
||
const TRACKER_HOST = 'tracker.konduit.me'; | ||
|
||
const analyticsType = 'endpoint'; | ||
|
||
const eventDataComposerMap = { | ||
[CONSTANTS.EVENTS.AUCTION_INIT]: obtainAuctionInfo, | ||
[CONSTANTS.EVENTS.AUCTION_END]: obtainAuctionInfo, | ||
[CONSTANTS.EVENTS.BID_REQUESTED]: obtainBidRequestsInfo, | ||
[CONSTANTS.EVENTS.BID_TIMEOUT]: obtainBidTimeoutInfo, | ||
[CONSTANTS.EVENTS.BID_RESPONSE]: obtainBidResponseInfo, | ||
[CONSTANTS.EVENTS.BID_WON]: obtainWinnerBidInfo, | ||
[CONSTANTS.EVENTS.NO_BID]: obtainNoBidInfo, | ||
}; | ||
|
||
// This function is copy from prebid core | ||
function formatQS(query) { | ||
return Object | ||
.keys(query) | ||
.map(k => Array.isArray(query[k]) | ||
? query[k].map(v => `${k}[]=${v}`).join('&') | ||
: `${k}=${query[k]}`) | ||
.join('&'); | ||
} | ||
|
||
// This function is copy from prebid core | ||
function buildUrl(obj) { | ||
return (obj.protocol || 'http') + '://' + | ||
(obj.host || | ||
obj.hostname + (obj.port ? `:${obj.port}` : '')) + | ||
(obj.pathname || '') + | ||
(obj.search ? `?${formatQS(obj.search || '')}` : '') + | ||
(obj.hash ? `#${obj.hash}` : ''); | ||
} | ||
|
||
const getWinnerBidFromAggregatedEvents = () => { | ||
return konduitAnalyticsAdapter.context.aggregatedEvents | ||
.filter(evt => evt.eventType === CONSTANTS.EVENTS.BID_WON)[0]; | ||
}; | ||
|
||
const isWinnerBidDetected = () => { | ||
return !!getWinnerBidFromAggregatedEvents(); | ||
}; | ||
const isWinnerBidExist = () => { | ||
return !!targeting.getWinningBids()[0]; | ||
}; | ||
|
||
const konduitAnalyticsAdapter = Object.assign( | ||
adapter({ analyticsType }), | ||
{ | ||
track ({ eventType, args }) { | ||
if (CONSTANTS.EVENTS.AUCTION_INIT === eventType) { | ||
konduitAnalyticsAdapter.context.aggregatedEvents.splice(0); | ||
} | ||
|
||
if (eventDataComposerMap[eventType]) { | ||
konduitAnalyticsAdapter.context.aggregatedEvents.push({ | ||
eventType, | ||
data: eventDataComposerMap[eventType](args), | ||
}); | ||
} | ||
|
||
if (eventType === CONSTANTS.EVENTS.AUCTION_END) { | ||
if (!isWinnerBidDetected() && isWinnerBidExist()) { | ||
const bidWonData = eventDataComposerMap[CONSTANTS.EVENTS.BID_WON](targeting.getWinningBids()[0]); | ||
|
||
konduitAnalyticsAdapter.context.aggregatedEvents.push({ | ||
eventType: CONSTANTS.EVENTS.BID_WON, | ||
data: bidWonData, | ||
}); | ||
} | ||
sendRequest({ method: 'POST', path: '/analytics-initial-event', payload: composeRequestPayload() }); | ||
} | ||
} | ||
} | ||
); | ||
|
||
function obtainBidTimeoutInfo (args) { | ||
return args.map(item => item.bidder).filter(utils.uniques); | ||
} | ||
|
||
function obtainAuctionInfo (auction) { | ||
return { | ||
auctionId: auction.auctionId, | ||
timestamp: auction.timestamp, | ||
auctionEnd: auction.auctionEnd, | ||
auctionStatus: auction.auctionStatus, | ||
adUnitCodes: auction.adUnitCodes, | ||
labels: auction.labels, | ||
timeout: auction.timeout | ||
}; | ||
} | ||
|
||
function obtainBidRequestsInfo (bidRequests) { | ||
return { | ||
bidderCode: bidRequests.bidderCode, | ||
time: bidRequests.start, | ||
bids: bidRequests.bids.map(function (bid) { | ||
return { | ||
transactionId: bid.transactionId, | ||
adUnitCode: bid.adUnitCode, | ||
bidId: bid.bidId, | ||
startTime: bid.startTime, | ||
sizes: utils.parseSizesInput(bid.sizes).toString(), | ||
params: bid.params | ||
}; | ||
}), | ||
}; | ||
} | ||
|
||
function obtainBidResponseInfo (bidResponse) { | ||
return { | ||
bidderCode: bidResponse.bidder, | ||
transactionId: bidResponse.transactionId, | ||
adUnitCode: bidResponse.adUnitCode, | ||
statusMessage: bidResponse.statusMessage, | ||
mediaType: bidResponse.mediaType, | ||
renderedSize: bidResponse.size, | ||
cpm: bidResponse.cpm, | ||
currency: bidResponse.currency, | ||
netRevenue: bidResponse.netRevenue, | ||
timeToRespond: bidResponse.timeToRespond, | ||
bidId: bidResponse.bidId, | ||
requestId: bidResponse.requestId, | ||
creativeId: bidResponse.creativeId | ||
}; | ||
} | ||
|
||
function obtainNoBidInfo (bidResponse) { | ||
return { | ||
bidderCode: bidResponse.bidder, | ||
transactionId: bidResponse.transactionId, | ||
adUnitCode: bidResponse.adUnitCode, | ||
bidId: bidResponse.bidId, | ||
}; | ||
} | ||
|
||
function obtainWinnerBidInfo (bidResponse) { | ||
return { | ||
adId: bidResponse.adId, | ||
bidderCode: bidResponse.bidder, | ||
adUnitCode: bidResponse.adUnitCode, | ||
statusMessage: bidResponse.statusMessage, | ||
mediaType: bidResponse.mediaType, | ||
renderedSize: bidResponse.size, | ||
cpm: bidResponse.cpm, | ||
currency: bidResponse.currency, | ||
netRevenue: bidResponse.netRevenue, | ||
timeToRespond: bidResponse.timeToRespond, | ||
bidId: bidResponse.requestId, | ||
dealId: bidResponse.dealId, | ||
status: bidResponse.status, | ||
creativeId: bidResponse.creativeId | ||
}; | ||
} | ||
|
||
function composeRequestPayload () { | ||
const konduitId = config.getConfig('konduit.konduitId'); | ||
const { width, height } = window.screen; | ||
|
||
return { | ||
konduitId, | ||
prebidVersion: $$PREBID_GLOBAL$$.version, | ||
jsnellbaker marked this conversation as resolved.
Show resolved
Hide resolved
|
||
environment: { | ||
screen: { width, height }, | ||
language: navigator.language, | ||
}, | ||
events: konduitAnalyticsAdapter.context.aggregatedEvents, | ||
}; | ||
} | ||
|
||
function sendRequest ({ host = TRACKER_HOST, method, path, payload }) { | ||
const formattedUrlOptions = { | ||
protocol: 'https', | ||
hostname: host, | ||
pathname: path, | ||
}; | ||
if (method === 'GET') { | ||
formattedUrlOptions.search = payload; | ||
} | ||
|
||
let konduitAnalyticsRequestUrl = buildUrl(formattedUrlOptions); | ||
|
||
ajax( | ||
konduitAnalyticsRequestUrl, | ||
undefined, | ||
method === 'POST' ? JSON.stringify(payload) : null, | ||
{ | ||
contentType: 'application/json', | ||
method, | ||
withCredentials: true | ||
} | ||
); | ||
} | ||
|
||
konduitAnalyticsAdapter.originEnableAnalytics = konduitAnalyticsAdapter.enableAnalytics; | ||
|
||
konduitAnalyticsAdapter.enableAnalytics = function (analyticsConfig) { | ||
const konduitId = config.getConfig('konduit.konduitId'); | ||
|
||
if (!konduitId) { | ||
utils.logError('A konduitId in config is required to use konduitAnalyticsAdapter'); | ||
return; | ||
} | ||
|
||
konduitAnalyticsAdapter.context = { | ||
aggregatedEvents: [], | ||
}; | ||
|
||
konduitAnalyticsAdapter.originEnableAnalytics(analyticsConfig); | ||
}; | ||
|
||
adapterManager.registerAnalyticsAdapter({ | ||
adapter: konduitAnalyticsAdapter, | ||
code: 'konduit' | ||
}); | ||
|
||
export default konduitAnalyticsAdapter; |
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,32 @@ | ||
# Overview | ||
| ||
``` | ||
Module Name: Konduit Analytics Adapter | ||
Module Type: Analytics Adapter | ||
Maintainer: support@konduit.me | ||
``` | ||
| ||
| ||
# Description | ||
| ||
Konduit Analytics adapter pushes Prebid events into Konduit platform, which is then organizes the data and presents it to a client in different insightful views. | ||
| ||
For more information, visit the [official Konduit website](https://konduitvideo.com/). | ||
| ||
| ||
# Usage | ||
| ||
Konduit Analytics can be enabled with a standard `enableAnalytics` call. | ||
Note it is also important to provide a valid Konduit identifier as a config parameter. | ||
| ||
```javascript | ||
pbjs.setConfig({ | ||
konduit: { | ||
konduitId: your_konduit_id, | ||
} | ||
}); | ||
| ||
pbjs.enableAnalytics({ | ||
provider: 'konduit' | ||
}) | ||
``` |
Oops, something went wrong.
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.
Can you clarify why you made your own local copies of these functions instead of just using them from the utils import? Are you concerned these functions would change in core unexpectedly for you? Or is there some other reason?
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.
Hi @jsnellbaker!
This is a good question. The main reason for the local copies is we would like the Konduit module to be compatible with previous Prebid versions.
Please let us know if there is a better way to maintain compatibility.
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.
The releases of Prebid are all snapshots of the repository taken at the respective times. Your module would only be available for use with the version of Prebid.js that published it (and future versions). It wouldn't inherently be backwards compatible, and I'm not sure there's any way within the current build/release process to make it work for older versions.
In regard to these functions, the local copies would seem to only help with the point I made before about potential worry of the core code updating and changing the logic slightly. I wouldn't say it won't happen, but changes like that are considered very carefully in terms of the impact and we would take steps to ensure it's handled well for everyone.
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.
@jsnellbaker thank you for these details, everything makes sense.
Our use case is in fact to be backwards compatible.
We have a number of existing publishers that are not ready to upgrade their Prebid version yet. For us it would be easier to have a backwards compatible module that can be used with previous Prebid versions without code modification.
This is the main reason we have the local copies and hopefully it is acceptable to leave it as is.
Please let us know if you have any concerns.