HBA instream reporting with Google IMA SDK
Learn how to enable HBA to pick up revenue and impressions when using Google's IMA SDK for instream video - either directly or via a 3rd party video player.
When using Google's IMA SDK the instreamTracking module for Prebid.js is not working. Instead it is necessary to "manually" register instream impressions using the relevantDigital.Auction.registerImpressionByAdId() function.
When using the IMA SDK directly
We need to listen for the google.ima.AdEvent.Type.IMPRESSION event and then extract the ad id(s) via the Ad.getWrapperAdIds() and Ad.getAdId() functions that we'll then supply to relevantDigital.Auction.registerImpressionByAdId() .
First we create the event handler:
// Our impression event handler
const onImp = (ev) => {
window.relevantDigital = window.relevantDigital || {};
relevantDigital.cmd = relevantDigital.cmd || [];
relevantDigital.cmd.push(() => {
// Loop through all ad ids starting from the innermost ad.
// registerImpressionByAdId() will return true if it registered an impression
const adIds = [
ev.getAd().getAdId(),
...ev.getAd().getWrapperAdIds(),
];
for (const id of adIds) {
if (relevantDigital.Auction.registerImpressionByAdId(id)) {
return;
}
}
});
};We can then use this onImp handler from the existing site code similar to this:
When using the IMA SDK indirectly via 3'rd party video players
Unfortunately it's currently not possible to listen for the impression-events in a supported way from "outside" using the IMA SDK as there is no reliable way to get access to the google.ima.AdsManager instances.
It is highly recommended that you check the documentation for your existing video player to see if there is a way to to listen to impression events and get ad ids in the same manner as via Ad.getWrapperAdIds() and Ad.getAdId(). If so it should be possible create a listener very similar to the onImp listener above.
Quick workarounds
As a last resort it's possible to "inject" some JavaScript-functionality into the IMA SDK instead - in order to capture the impression events.
The solution below overwrites google.ima.AdsLoader etc. In worst case a subsequent update of the IMA SDK might interfere with this solution in such a way so that instream ads breaks completely!
The setting below requires that the first call to relevantDigital.loadPrebid() is executed before the video player code creates the google.ima.AdsLoader object, in order to work.

If that timing requirement is not possible, or in case of uncertainty - the code below will do the same thing:
Last updated
Was this helpful?