Skip to content

Commit

Permalink
Report initial ad metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
strangesource committed Jul 2, 2024
1 parent 3af6cf2 commit e74ba1c
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 16 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package com.bitmovin.analytics.conviva.ssai;

import com.bitmovin.player.api.Player;
import com.bitmovin.player.api.media.video.quality.VideoQuality;
import com.conviva.sdk.ConvivaSdkConstants;

public class DefaultPlaybackStateProvider implements PlaybackStateProvider {
public class DefaultPlaybackInfoProvider implements PlaybackInfoProvider {
private final Player player;

public DefaultPlaybackStateProvider(Player player) {
public DefaultPlaybackInfoProvider(Player player) {
this.player = player;
}

Expand All @@ -22,4 +23,9 @@ public ConvivaSdkConstants.PlayerState getPlayerState() {
}
return state;
}

@Override
public VideoQuality getPlaybackVideoData() {
return player.getPlaybackVideoData();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.util.Log;

import com.bitmovin.player.api.media.video.quality.VideoQuality;
import com.conviva.sdk.ConvivaAdAnalytics;
import com.conviva.sdk.ConvivaSdkConstants;
import com.conviva.sdk.ConvivaVideoAnalytics;
Expand All @@ -14,9 +15,9 @@ public class DefaultSsaiApi implements SsaiApi {
private static final String TAG = "DefaultSsaiApi";
private final ConvivaVideoAnalytics convivaVideoAnalytics;
private final ConvivaAdAnalytics convivaAdAnalytics;
private final PlaybackStateProvider player;
private final PlaybackInfoProvider player;

public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlaybackStateProvider player) {
public DefaultSsaiApi(ConvivaVideoAnalytics convivaVideoAnalytics, ConvivaAdAnalytics convivaAdAnalytics, PlaybackInfoProvider player) {
this.convivaVideoAnalytics = convivaVideoAnalytics;
this.convivaAdAnalytics = convivaAdAnalytics;
this.player = player;
Expand Down Expand Up @@ -70,7 +71,17 @@ public void reportAdStarted(AdInfo adInfo) {
}
Log.d(TAG, "Server side ad started");
convivaAdAnalytics.reportAdStarted(convertToConvivaAdInfo(adInfo));
reportInitialAdMetrics();
}

private void reportInitialAdMetrics() {
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, player.getPlayerState());
VideoQuality videoQuality = player.getPlaybackVideoData();
if (videoQuality != null) {
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, videoQuality.getHeight(), videoQuality.getWidth());
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, videoQuality.getBitrate() / 1000);
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, Math.round(videoQuality.getFrameRate()));
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.bitmovin.analytics.conviva.ssai;

import com.bitmovin.player.api.media.video.quality.VideoQuality;
import com.conviva.sdk.ConvivaSdkConstants;

public interface PlaybackStateProvider {
public interface PlaybackInfoProvider {
ConvivaSdkConstants.PlayerState getPlayerState();
VideoQuality getPlaybackVideoData();
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.bitmovin.analytics.conviva.ssai

import android.util.Log
import com.bitmovin.player.api.media.video.quality.VideoQuality
import com.conviva.sdk.ConvivaAdAnalytics
import com.conviva.sdk.ConvivaSdkConstants
import com.conviva.sdk.ConvivaVideoAnalytics
Expand Down Expand Up @@ -29,29 +30,42 @@ import strikt.assertions.isTrue
class DefaultSsaiApiTest {
private val videoAnalytics: ConvivaVideoAnalytics = mockk(relaxed = true)
private val adAnalytics: ConvivaAdAnalytics = mockk()
private val playbackStateProvider = mockk<PlaybackStateProvider>()
private val ssaiApi = DefaultSsaiApi(
videoAnalytics,
adAnalytics,
playbackStateProvider,
)
private val playbackInfoProvider = mockk<PlaybackInfoProvider>()
private lateinit var ssaiApi: DefaultSsaiApi

@Before
fun beforeTest() {
every { playbackStateProvider.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING
every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.PLAYING
every { playbackInfoProvider.playbackVideoData } returns VideoQuality(
"videoQualityId",
"videoQualityLabel",
1000,
"codec",
60.1F,
1600,
800,
)
with(adAnalytics) {
every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, any()) } just runs
every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, any(), any()) } just runs
every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, any()) } just runs
every { reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, any()) } just runs
every { reportAdStarted(any()) } just runs
every { reportAdEnded() } just runs
every { reportAdSkipped() } just runs
every { setAdInfo(any()) } just runs
}

ssaiApi = DefaultSsaiApi(
videoAnalytics,
adAnalytics,
playbackInfoProvider,
)
}

@After
fun afterTest() {
clearMocks(videoAnalytics, adAnalytics, playbackStateProvider)
ssaiApi.reset()
clearMocks(videoAnalytics, adAnalytics, playbackInfoProvider)
}


Expand Down Expand Up @@ -122,7 +136,7 @@ class DefaultSsaiApiTest {

@Test
fun `reports ad playback state playing to conviva when ad starts while paused`() {
every { playbackStateProvider.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED
every { playbackInfoProvider.playerState } returns ConvivaSdkConstants.PlayerState.PAUSED

ssaiApi.reportAdBreakStarted()
ssaiApi.reportAdStarted(SsaiApi.AdInfo())
Expand All @@ -137,7 +151,7 @@ class DefaultSsaiApiTest {

@Test
fun `reports ad playback state buffering to conviva when ad starts while stalling`() {
every { playbackStateProvider.playerState } returns
every { playbackInfoProvider.playerState } returns
ConvivaSdkConstants.PlayerState.BUFFERING

ssaiApi.reportAdBreakStarted()
Expand All @@ -151,6 +165,18 @@ class DefaultSsaiApiTest {
}
}

@Test
fun `reports current playback video quality to conviva on ad start`() {
ssaiApi.reportAdBreakStarted()
ssaiApi.reportAdStarted(SsaiApi.AdInfo())

verify {
adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.BITRATE, 1)
adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RESOLUTION, 800, 1600)
adAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.RENDERED_FRAMERATE, 60)
}
}

@Test
fun `reports ad start with overwritten metadata when ad starts with additional metadata`() {
ssaiApi.reportAdBreakStarted()
Expand Down

0 comments on commit e74ba1c

Please sign in to comment.