Google Analytics 4 (Android)

Dailymotion currently supports client-side integration with Google Analytics. It allows collecting client-side events from Android apps and send them to a Google Analytics account for further storage and analysis.

Implementation steps

1. Add the Analytics SDK to your app

In your module (app-level) Gradle file (usually <project>/<app-module>/build.gradle.kts or <project>/<app-module>/build.gradle), add the dependency for the Analytics library for Android:

dependencies {
    // Import the BoM for the Firebase platform
    implementation(platform("com.google.firebase:firebase-bom:33.1.0"))

    // Add the dependency for the Analytics library
    // When using the BoM, you don't specify versions in Firebase library dependencies
    implementation("com.google.firebase:firebase-analytics")
}

Learn more about adding Firebase to your project.

2. Send events to Google Analytics

Check the dedicated guide to learn how to listen to events.

For example, to listen to onVideoEnd event, just implement the method onVideoEnd():

Dailymotion.createPlayer(
  context = context,
  playerId = "MY_PLAYER_ID",   
  playerSetupListener = object : Dailymotion.PlayerSetupListener{
    ...
  }, 
  videoListener = object : VideoListener {        
    override fun onVideoEnd(playerView: PlayerView) {    
         // video end event 
  	}    
  }
)

Declare the com.google.firebase.analytics.FirebaseAnalytics object at the top of your activity:

private lateinit var firebaseAnalytics: FirebaseAnalytics

Initialize it in the onCreate() method:

// Obtain the FirebaseAnalytics instance.
firebaseAnalytics = Firebase.analytics

Send event onVideoEnd:

Dailymotion.createPlayer(
  context = context,
  playerId = "MY_PLAYER_ID",   
  playerSetupListener = object : Dailymotion.PlayerSetupListener{
    ...
  }, 
  videoListener = object : VideoListener {        
    override fun onVideoEnd(playerView: PlayerView) {  

        // Create a Bundle to hold event parameters
        val bundle = Bundle().apply {
            putString("videoId", "MY_VIDEO_ID")
            putString("event", "onVideoEnd")
            putString(FirebaseAnalytics.Param.CONTENT_TYPE, "video_player")
        }
       
      	// Log the event with the parameters
        firebaseAnalytics.logEvent("DailymotionPlayer", bundle)

    }    
  }
)