The Prebid Analytics API provides a way to get analytics data from
Prebid.js and send it to the analytics provider of your choice, such as Google Analytics. Because it’s an open source API, you can write an adapter to send analytics data to any provider you like. Integrating with the Prebid Analytics API has the following benefits:
Before we jump into looking at code, let’s look at the high-level architecture. As shown in the diagram below,
Prebid.js calls into an analytics adapter. The analytics adapter is the only part of the code that must be stored in the
The analytics adapter listens to events and may call out directly to the analytics backend, or it may call out to an analytics library that integrates with the analytics server.
For instructions on integrating an analytics provider, see the next section.
Working with any Prebid project requires using Github. In general, we recommend the same basic workflow for any project:
moduleswith the name of the bidder suffixed with ‘AnalyticsAdapter’, e.g.,
Example markdown file:
Create a JS file under
modules with the name of the bidder suffixed with ‘AnalyticsAdapter’, e.g.,
Create an analytics adapter to listen for Prebid events and call the analytics library or server. See the existing *AnalyticsAdapter.js files in the repo under modules.
There are two types of analytics adapters. The example here focuses on the ‘endpoint’ type. See AnalyticsAdapter.js for more info on the ‘bundle’ type.
In order to get access to the configuration passed in from the page, the analytics adapter needs to specify an enableAnalytics() function, but it should also call the base class function to set up the events.
A basic prototype analytics adapter:
Analytics adapter best practices:
Create a JS file under
test/spec/modules with the name of the bidder suffixed with ‘AnalyticsAdapter_spec’, e.g.,
Write great unit tests. See the other AnalyticsAdapter_spec.js files for examples.
Once everything looks good, submit the code, tests, and markdown as a pull request to the Prebid.js repo.
There are two files that need to be updated to list your new analytics adapter.
Create a fork of the website repo and a branch for your new adapter. (e.g. feature/exAnalyticsAdapter)
overview/analytics.md to add your adapter alphabetically into the list.
download.md to add your new adapter alphabetically into the li
st of other analytics adapters.
Submit the pull request to the prebid.github.io repo.
We sometimes get pretty busy, so it can take a couple of weeks for the review process to complete, so while you’re waiting, consider joining Prebid.org to help us out with code reviews. (!)