Table of content

Google Analytics 4 (GA4)

Android / iOS integration


Dailymotion currently supports client-side integration with Google Analytics. This allows Partners to collect client-side events from their mobile apps and send them to their Google Analytics account for further storage and analysis.

Find dedicated documentation for GA4 web integration


Android integration

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.

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)

    }    
  }
)


iOS integration

Add the Analytics SDK to your app

Use Swift Package Manager to install and manage Firebase dependencies:

  1. In Xcode, with your app project open, navigate to File > Add Packages.
  2. When prompted, add the Firebase Apple platforms SDK repository: https://github.com/firebase/firebase-ios-sdk.git

Learn more about adding Firebase to your project.

Initiate the Firebase SDK

Import the FirebaseCore module in your UIApplicationDelegate, as well as any other Firebase modules your app delegate uses. For example, to use Cloud Firestore and Authentication:

import os.log
import DailymotionPlayerSDK
import GoogleCast
import FirebaseCore

Configure a FirebaseApp shared instance in your app delegate’s application(_:didFinishLaunchingWithOptions:) method:

FirebaseApp.configure()

Send event to Google Analytics

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

func addPlayerEvent(event: String) {     
   Analytics.logEvent("DailymotionPlayer", parameters: ["playerEvent": event])        
}

Sent the first time the Player attempts to start the playback, either because of user interaction, an autoplay parameter or an API call (e.g. play()loadContent(), etc.)

func playerDidStart(_ player: DMPlayerView) {
     addPlayerEvent(event: "playerDidStart")
}

Sent when the video playback has paused:

func videoDidPause(_ player: DMPlayerView) {
     addPlayerEvent(event: "videoDidPause")
}

Check more events sample in here.