Prebid Analytics with GA
- Code Example
- How Prebid.js uses GA’s Events
- How to Verify it Works
- Better Reports within GA
- Spreadsheet Dashboard
A Few Requirements
- This code snippet has to be inserted after the
'ga'param is available.
- This code snippet has to be inserted after pbjs.que has been defined.
- You must include
Note: we recommend disabling
enableDistribution if you are using more than 4 bidders. This is because GA throttles the number of events that can be logged (20 initial + 2/second). Distribution data provides you with a histogram of CPM distribution and bid load time (latency) for each bidder. See distribution data demo here.
See this link for details on GA’s throttling.
To track a lower volume of traffic in Google Analytics, you may specify a sample rate in the options. For example, to set up a 5% sample rate:
At the start of each page, Prebid chooses a random number between 0 and 1 and logs the analytics only if the number is less than the supplied sample rate, which defaults to 1 (100%). Of course a smaller sample rate means that reported numbers will be correspondingly lower, so a scaling factor in reports may be useful, but is outside the scope of Prebid.
It should also be noted that all events on a given page are subject to the same analytics behavior. This means that all requests, responses, and renders on a page are either logged or not logged.
How Prebid.js uses GA’s Events
In this example, the page has 1 ad unit with 3 bidders. The timeout is set to 400ms. Let’s go through what Prebid Analytics sends out to GA:
|Time||What Happened||GA Events Sent|
|15ms||Prebid.js sends out bid requests to bidders AppNexus, OpenX, and Pubmatic.||Event 1: Category=
Event 2: Category=
Event 3: Category=
|203ms||AppNexus’ bid came back with a CPM of $2.314 and a latency of 188ms.||Event 1: Category=
Event 2: Category=
|274ms||Pubmatic’s bid came back with a CPM of $0 and a latency of 259ms.||No bid event sent out because it is a no bid.
Event 1: Category=
|415ms||Timeout is up because 400ms has passed since bid requests were sent. OpenX has timed out.||Event 1: Category=
|476ms||OpenX’s bid came back with a CPM of $2.831 and a latency of 461ms (a bid may still come back after a timeout).||Event 1: Category=
Event 2: Category=
|572ms||DFP completed its auction and the AppNexus $2.314 bid won.||Event 3: Category=
Note that a Win event is a true win, meaning that it is not just the highest bid in the header bidding auction, but the winning bid across the entire auction hosted by the ad server and its creative is served back to the page.
How to Verify it Works
After you’ve implemented the above code snippet, load the page a few times, wait 1-2 hours for GA’s data pipeline to finish, and go to your GA Reporting screen. Navigate to Behavior > Events. You should be able to find the Prebid.js events (if you have many other events, filter Event Category by
As you can see, this reporting screen cannot help you answer questions such as:
- What’s the AppNexus bidder’s avg. bid CPM
- What’s the AppNexus bidder’s avg. bid load time?
To see how to answer these questions, see the following sections.
Better Reports within GA
With a custom report in GA, you can get:
This can be built by:
However, this is still not the most ideal dashboard, because it’s hard to find information you need quickly. For that you can build a Spreadsheet Dashboard as shown in the next section.
Find the demo of the Spreadsheet Dashboard here.
To build your own version of this report dashboard:
Step 1. Install the GA Spreadsheet Add-On
Install the Google Analytics Spreadsheet Add-on. Understand how the add-on works.
Step 2. Copy the Demo Dashboard
Make a local copy of the Demo Dashboard.
Step 3. Update the GA Profile ID
In your local copy, go to the Report Configuration tab, update the GA profile ID (you should be able to get this ID from Step 1)
Step 4. Run the Report
Step 5. (Optional) Schedule a Daily Report