Skip to content

Commit

Permalink
Merge branch 'develop' into ssai-docu-and-changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
strangesource committed Jul 4, 2024
2 parents d9b1e4e + 7b59f90 commit 82dac4c
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import java.util.Map;

public class ConvivaAnalyticsIntegration {
public static final String STREAM_TYPE = "streamType";
public static final String INTEGRATION_VERSION = "integrationVersion";

private static final String TAG = "ConvivaAnalyticsInt";

Expand Down Expand Up @@ -374,8 +376,8 @@ private void buildDynamicContentMetadata() {
// streamType could be missing at time of session initialization
// as source information could be unavailable at that time
Map<String, String> customInternTags = new HashMap<>();
customInternTags.put("streamType", playerHelper.getStreamType());
customInternTags.put("integrationVersion", BuildConfig.VERSION_NAME);
customInternTags.put(STREAM_TYPE, playerHelper.getStreamType());
customInternTags.put(INTEGRATION_VERSION, BuildConfig.VERSION_NAME);
contentMetadataBuilder.setCustom(customInternTags);

if (bitmovinPlayer.isLive()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.util.Log;

import com.bitmovin.analytics.conviva.ConvivaAnalyticsIntegration;
import com.conviva.sdk.ConvivaAdAnalytics;
import com.conviva.sdk.ConvivaSdkConstants;
import com.conviva.sdk.ConvivaVideoAnalytics;
Expand Down Expand Up @@ -70,7 +71,7 @@ public void reportAdStarted(AdInfo adInfo) {
return;
}
Log.d(TAG, "Server side ad started");
convivaAdAnalytics.reportAdStarted(convertToConvivaAdInfo(adInfo));
convivaAdAnalytics.reportAdStarted(convertToConvivaAdInfo(adInfo, convivaVideoAnalytics.getMetadataInfo()));
convivaAdAnalytics.reportAdMetric(ConvivaSdkConstants.PLAYBACK.PLAYER_STATE, player.getPlayerState());
}

Expand Down Expand Up @@ -102,19 +103,53 @@ public void updateAdInfo(AdInfo adInfo) {
}
Log.d(TAG, "Setting ad info");

convivaAdAnalytics.setAdInfo(convertToConvivaAdInfo(adInfo));
convivaAdAnalytics.setAdInfo(convertToConvivaAdInfo(adInfo, convivaVideoAnalytics.getMetadataInfo()));
}

private static Map<String, Object> convertToConvivaAdInfo(AdInfo adInfo) {
private static Map<String, Object> convertToConvivaAdInfo(
AdInfo adInfo,
Map<String, Object> mainContentMetadata
) {
HashMap<String, Object> convivaAdInfo = new HashMap<>();

setDefaults(convivaAdInfo);
setFromMainContent(mainContentMetadata, convivaAdInfo);
setFromAdInfo(adInfo, convivaAdInfo);

if (adInfo.getAdditionalMetadata() != null) {
convivaAdInfo.putAll(adInfo.getAdditionalMetadata());
}

return convivaAdInfo;
}

private static void setDefaults(HashMap<String, Object> convivaAdInfo) {
convivaAdInfo.put("c3.ad.id", "NA");
convivaAdInfo.put("c3.ad.system", "NA");
convivaAdInfo.put("c3.ad.mediaFileApiFramework", "NA");
convivaAdInfo.put("c3.ad.firstAdSystem", "NA");
convivaAdInfo.put("c3.ad.firstAdId", "NA");
convivaAdInfo.put("c3.ad.firstCreativeId", "NA");
convivaAdInfo.put("c3.ad.technology", "Server Side");
}

private static void setFromMainContent(Map<String, Object> mainContentMetadata, HashMap<String, Object> convivaAdInfo) {
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaSdkConstants.STREAM_URL);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaSdkConstants.ASSET_NAME);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaSdkConstants.IS_LIVE);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaSdkConstants.DEFAULT_RESOURCE);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaSdkConstants.ENCODED_FRAMERATE);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaAnalyticsIntegration.STREAM_TYPE);
maybeCopyFromMainContent(mainContentMetadata, convivaAdInfo, ConvivaAnalyticsIntegration.INTEGRATION_VERSION);
}

private static void maybeCopyFromMainContent(Map<String, Object> mainContentMetadata, HashMap<String, Object> convivaAdInfo, String key) {
if (mainContentMetadata.containsKey(key)) {
convivaAdInfo.put(key, mainContentMetadata.get(key));
}
}

private static void setFromAdInfo(AdInfo adInfo, HashMap<String, Object> convivaAdInfo) {
convivaAdInfo.put("c3.ad.isSlate", adInfo.isSlate());

if (adInfo.getTitle() != null) {
Expand All @@ -135,11 +170,6 @@ private static Map<String, Object> convertToConvivaAdInfo(AdInfo adInfo) {
if (adInfo.getAdStitcher() != null) {
convivaAdInfo.put("c3.ad.stitcher", adInfo.getAdStitcher());
}
if (adInfo.getAdditionalMetadata() != null) {
convivaAdInfo.putAll(adInfo.getAdditionalMetadata());
}

return convivaAdInfo;
}

private static ConvivaSdkConstants.AdPosition toConvivaAdPosition(AdPosition position) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ class DefaultSsaiApiTest {
expectThat(slot.captured["c3.ad.id"]).isEqualTo("adIdSetInAdditionalMetadata")
}

@Test
fun `reports ad start with main content metadata when ad starts without overwriting it`() {
every { videoAnalytics.metadataInfo } returns mapOf(
"streamType" to "mainContentStreamType",
ConvivaSdkConstants.ASSET_NAME to "mainContentTitle",
)

ssaiApi.reportAdBreakStarted()
ssaiApi.reportAdStarted(SsaiApi.AdInfo().apply {
title = "overwrittenTitle"
})

val slot = slot<MutableMap<String, Any>>()
verify {
adAnalytics.reportAdStarted(capture(slot))
}

expectThat(slot){
get { captured[ConvivaSdkConstants.ASSET_NAME] }.isEqualTo("overwrittenTitle")
get { captured["streamType"] }.isEqualTo("mainContentStreamType")
}
}

@Test
fun `reports ad end to conviva when ad finished`() {
ssaiApi.reportAdBreakStarted()
Expand Down

0 comments on commit 82dac4c

Please sign in to comment.