ExoPlayer
ExoPlayer copied to clipboard
How to capture Ads Requested event from ImaAdsLoader
I want to capture the event when ImaAdsLoader makes the request to the ad server to make sure that the number of ads requested and the number of ads that failed or succeeded are in correlation with GAM. I have checked the existing issues and does not found an answer.
In general, ExoPlayer only can report what it knows about and ExoPlayer is not aware of the internal workings of the IMA SDK which is a black box for ExoPlayer as much as for the app.
If you are looking for the requests made to download media for an ad, then this should be reported by the AnalyticsListener.onLoadStarted(...)/onLoadCompleted(...)/onLoadCanceled(...)/onLoadError(...)
methods like for the content.
I'm not sure how well these events are suited for your purpose though.
First, you have to identify and correlate these request belonging to an ad or to content. While EventTime
will report the period being played while the event is generated, this does not allow to identify the ad because you don't know whether an ad is loaded ahead of time while the previous ad is still playing.
Second, an ad may have been downloaded for buffering but is then not played for instance when a user exits playback. So even if possible, having identified and correlated the download to ad vs. content it isn't a sufficiently good indication whether the ad actually has been played.
If I wanted to know what ads have been played by ExoPlayer, I would monitor the calls to onPositionDiscontinuity(PositionInfo old, PositionInfo new)
. The PositionInfo
report adGroupIndex
and adIndexInAdGroup
. So every ad that has been played produces a position discontinuity of reason DISCONTINUITY_REASON_AUTO_TRANSITION
that has the given adGroupIndex
and adIndexInAdGroup
in the oldPosition
while the newPosition
is different. That would give you the ad periods played by ExoPlayer.