##dz-db-collector-details
Adding dependencies to your project
-
Add following maven repository URL in your project's build.gradle file
maven { // Snapshot Repository maven { url 'https://gitlab.com/api/v4/projects/18323233/packages/maven' } // Release Repository maven { url 'https://gitlab.com/api/v4/projects/10353305/packages/maven' } }
-
Add the following dependencies for Datazoom Exo Player SDK in your project’s build.gradle file's dependencies block
com/datazoom/android/exo-collector-gold-google
com.datazoom.android:base-collector-gold
com/datazoom/android/exo-collector-gold-amazondependencies { implementation 'com.datazoom.android:base-collector-gold:3.6.4' implementation 'com.datazoom.android:exo-collector-gold-google:2.9.11' } // For Amazon ExoPlayer dependencies { implementation 'com.datazoom.android:base-collector-gold:3.6.3' implementation 'com.datazoom.android:exo-collector-gold-amazon:2.9.11' }
-
Add the following compile options if you don't have it already.
compileOptions { sourceCompatibility JavaVersion.VERSION_1_8 targetCompatibility JavaVersion.VERSION_1_8 }
-
Add the following additional dependencies to your project.
dependencies { // ExoPlayer Core library implementation 'com.google.android.exoplayer:exoplayer-core:2.18.3' // Optional(Depends on usage) implementation 'com.google.android.exoplayer:exoplayer-dash:2.18.3' implementation 'com.google.android.exoplayer:exoplayer-ui:2.18.3' implementation 'com.google.android.exoplayer:extension-ima:2.18.3' implementation 'com.google.android.exoplayer:exoplayer-hls:2.18.3' // Google Ads Service (optional) implementation 'com.google.ads.interactivemedia.v3:interactivemedia:3.25.1' } // For Amazon dependencies { implementation 'com.amazon.android:exoplayer-core:2.18.2' implementation 'com.amazon.android:exoplayer-hls:2.18.2' implementation 'com.amazon.android:exoplayer-ui:2.18.2' implementation 'com.amazon.android:extension-ima:2.18.2' }
-
The following code snippet example illustrates the usage of ExoPlayer collector. Open the demo application's MainActivity.java to see a running example.
// Kotlin version: var configId = <configuration id from Datazoom> var configUrl = <url given by Datazoom> var exoPlayerCollector = ExoPlayerCollector().create(player, context) exoPlayerCollector?.setConfig(new DatazoomConfig(configId, configUrl)) exoPlayerCollector?.connect(new DZBeaconConnector.ConnectionListener() { override fun onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } override fun onError(Throwable t) { // Error while creating exo player collector } }); // Java version: String configId = <configuration id from Datazoom>; String configUrl = <url given by Datazoom>; ExoPlayerCollector exoPlayerCollector = ExoPlayerCollector.create(player, context); exoPlayerCollector.setConfig(new DatazoomConfig(configId, configUrl)); exoPlayerCollector.connect(new DZBeaconConnector.ConnectionListener() { @Override public void onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } @Override public void onError(Throwable t) { // Error while creating exo player collector } });
-
The following code snippet example illustrates the usage of ExoPlayer collector. Context must be added initially, because without it the configuration cannot be retrieved, but later you have the option to set the instance of the player and the context after initializing the collector. Open the demo application's MainActivity.java to see a running example.
// Kotlin version: var configId = <configuration id from Datazoom> var configUrl = <url given by Datazoom> var exoPlayerCollector = ExoPlayerCollector().create(context) exoPlayerCollector?.setConfig(new DatazoomConfig(configId, configUrl)) exoPlayerCollector?.connect(new DZBeaconConnector.ConnectionListener() { override fun onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete // Set player instance exoPlayerCollector?.setPlayer(mPlayer) } override fun onError(Throwable t) { // Error while creating exo player collector } }); // Java version: String configId = <configuration id from Datazoom>; String configUrl = <url given by Datazoom>; ExoPlayerCollector exoPlayerCollector = ExoPlayerCollector.create(context); exoPlayerCollector.setConfig(new DatazoomConfig(configId, configUrl)); exoPlayerCollector.connect(new DZBeaconConnector.ConnectionListener() { @Override public void onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete // Set player instance exoPlayerCollector.setPlayer(mPlayer) } @Override public void onError(Throwable t) { // Error while creating exo player collector } });
-
The following code snippet example illustrates the usage of ExoPlayer collector. ("2.16.1" - player version) if this parameter is empty then the version of the player used in the collector will be sent . Open the demo application's MainActivity.java to see a running example.
// Kotlin version: var configId = <configuration id from Datazoom> var configUrl = <url given by Datazoom> var exoPlayerCollector = ExoPlayerCollector().create(player, context, "2.16.1") exoPlayerCollector?.setConfig(new DatazoomConfig(configId, configUrl)) exoPlayerCollector?.connect(new DZBeaconConnector.ConnectionListener() { override fun onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } override fun onError(Throwable t) { // Error while creating exo player collector } }); // Java version: String configId = <configuration id from Datazoom>; String configUrl = <url given by Datazoom>; ExoPlayerCollector exoPlayerCollector = ExoPlayerCollector.create(player, context, "2.16.1"); exoPlayerCollector.setConfig(new DatazoomConfig(configId, configUrl)); exoPlayerCollector.connect(new DZBeaconConnector.ConnectionListener() { @Override public void onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } @Override public void onError(Throwable t) { // Error while creating exo player collector } });
-
The following code snippet example illustrates the usage of DZEventCollector (Instance without forwarding the instance of the player) .
// Kotlin version: String configId = <configuration id from Datazoom>; String configUrl = <url given by Datazoom>; var exoPlayerCollector = ExoPlayerCollector().create(context) exoPlayerCollector?.setConfig(new DatazoomConfig(configId, configUrl)) exoPlayerCollector?.connect(new DZBeaconConnector.ConnectionListener() { override fun onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } override fun onError(Throwable t) { //Error while creating exo player collector } }); // Java version: String configId = "<configuration id from Datazoom>"; String configUrl = "<url given by Datazoom>"; ExoPlayerCollector exoPlayerCollector = ExoPlayerCollector.create(context); exoPlayerCollector.setConfig(new DatazoomConfig(configId, configUrl)); exoPlayerCollector.connect(new DZBeaconConnector.ConnectionListener() { @Override public void onSuccess(DZEventCollector dzEventCollector) { // Everything is setup, collector initialization complete } @Override public void onError(Throwable t) { // Error while creating exo player collector } });
-
After the player is done playing a content, invoke the collector’s
releasePlayer()
method to stop data collection for the player. Later if the same or a different play instance is used to play contents again, invoke the collector’ssetPlayer()
method again to start data collection.// when content playing is done (completed or aborted) exoPlayerCollector.releasePlayer(); ... // before requesting content playback again exoPlayerCollector.setPlayer(player);
-
This part of code need to be called inside method onDestroy() to free some data storage
// Kotlin version: override fun onDestroy() { super.onDestroy() exoPlayerCollector?.clearPlayerData() } // Java version: @Override protected void onDestroy() { super.onDestroy(); if (exoPlayerCollector != null) { exoPlayerCollector.clearPlayerData(); } }
-
This part of code need to be called inside method onStop() to stop collector
// Kotlin version: override fun onStop() { exoPlayerCollector?.onStop() } // Java version: protected void onStop() { super.onStop(); if (exoPlayerCollector != null) { exoPlayerCollector.onStop(); } }
Custom Events & Metadata
Datazoom allows customers to collect custom events and custom metadata that don't originate from a video player.
Custom Metadata
ADD APP SESSION CUSTOM METADATA
(Metadata during the application session)
val appSessionMapTest = ConcurrentHashMap<String, Any>() appSessionMapTest["key"] = "value" DZEventCollector.setAppSessionCustomMetadata(appSessionMapTest)
READ APP SESSION CUSTOM METADATA
1. DZEventCollector.getAppSessionCustomMetadata()
: ConcurrentHashMap<String, Any>()
UPDATE APP SESSION CUSTOM METADATA
DZEventCollector.updateAppSessionCustomMetadata ("key", "value")
DELETE APP SESSION CUSTOM METADATA
1. DZEventCollector.clearAppSessionCustomMetadata();
ADD PLAYER SESSION CUSTOM METADATA
(Metadata during the player session)
val appPlayerMapTest = ConcurrentHashMap<String, Any>() appPlayerMapTest["key"] = "value" DZEventCollector.setPlayerSessionCustomMetadata(appPlayerMapTest)
READ PLAYER SESSION CUSTOM METADATA
1. DZEventCollector.getPlayerSessionCustomMetadata(): ConcurrentHashMap<String, Any>()
UPDATE PLAYER SESSION CUSTOM METADATA
DZEventCollector.updatePlayerSessionCustomMetadata ("key", "value")
DELETE PLAYER SESSION CUSTOM METADATA
1. DZEventCollector.clearPlayerSessionCustomMetadata();
Custom Events
a. Create an Event object.
var event = Event("Custom_Event_Name", new JSONArray()); or var event = Event(type: String, metadata: ConcurrentHashMap<String, Object>);
The first constructor parameter is the event name, and the second is a list of custom metadata to be included in the event.
b. Add the event to DZEventCollector.
dzEventCollector.addCustomEvent(event);
Example:
@Override public void onSuccess(DZEventCollector dzEventCollector) { Event event = new Event("SDKLoaded", new JSONArray()); dzEventCollector.addCustomEvent(event); btnPush.setOnClickListener(v -> { try { Event event1 = new Event("btnPush", new JSONArray("[{\"customPlay\": \"true\"}] ")); dzEventCollector.addCustomEvent(event1); } catch (JSONException e) { e.printStackTrace(); } }); }
IMA Ad Events
Use the following code track IMA Ad Events or IMA Ad Errors
adsLoader = ImaAdsLoader.Builder(this) .setAdEventListener(new AdEvent.AdEventListener { override fun onAdEvent(AdEvent : adEvent) { exoPlayerCollector?.trackIMAAdEvent(adEvent) } }) .setAdErrorListener {new AdErrorEvent.AdErrorListener { override fun onAdError(adError: AdErrorEvent?) { exoPlayerCollector?.trackIMAAdErrorEvent(adError)} })} .build()
Comments
0 comments
Article is closed for comments.