Dailymotion currently supports client-side integration with Google Analytics. This allows player partners to collect client-side events from the web and send it to their Google Analytics account for further storage and analysis.
Google Analytics Android
Steps:
- Add firebase to your project and enable Google analytics for your firebase project. Once enabled the application will be linked to your Google analytics data stream associated with that account. To learn more about adding firebase to your project see here: https://firebase.google.com/docs/android/setup
- Add the Analytics SDK to your Java/Kotilin project.
- Declare the dependency for the analytics library in your projects app-level Gradle file. See the most recent version. (https://firebase.google.com/docs/analytics/get-started?platform=android).
- Declare the firebase analytics object at the top level of your activity then initalize and obtain the instance in the onCreate() method.
The analytics library already logs some predefined events, https://support.google.com/firebase/answer/9234069?visit_id=637463003363964881-2397299297&rd=1.
To log events outside this list use the `logEvent()` method then shoot over a prescribed events with custom parameters and values. Events are case sensitive. From being able to log certain custom events to Google analytics we can pick up on the Dailymotion player events using the DM Android SDK and Player API and log them as custom events using Google Analyics custom `.logEvent()`. When using Dailymotion's SDKs, you add listens to player events via the dailymotion player API. The player will send event on any change of its states. To learn more about the available player events in our Android SDK please see here https://developer.dailymotion.com/player/#embed-mobile-android-events.
Below is an example of picking on some player events and logging to them GA using the `logEvent`. These events can also be logged over with some corresponding properties and values.For information about logging events and additional values with Firebase please read (https://firebase.google.com/docs/analytics/events?platform=android).
To make developers life easier we provide a sample applications, its possible to test easily your chosen required analytics solution with it: https://github.com/dailymotion/dailymotion-player-sdk-android/tree/master/sampleapp
```java
dailyMotionVideoPlayer.setEventListener { event ->
when (event) {
is ApiReadyEvent -> {analytics.logEvent(eventName, null)}
is StartEvent -> {analytics.logEvent(eventName, null)}
is LoadedMetaDataEvent -> {analytics.logEvent(eventName, null)}
is ProgressEvent -> {analytics.logEvent(eventName, null)}
is DurationChangeEvent ->{analytics.logEvent(eventName, null)}
}
}
```
Google Analytics iOS
Steps:
- Install the Firebase SDKs that connects to Google analytics in your application. Its recommended to use CocoaPods to install the library. Add the firebase pod for Google analytics `Firebase/Analytics`.
- Initialize Firebase in your APP, import the Firebase module in your `UIApplicationDelegate`. Then intialize a `Firebase` shared instance.
- Once the `FirebaseApp` instance is configured. There are a few app events that the analytics library will track automatically for you. Along with automatically picked up events, there are some predefined events you can add easily and are ready to go. To pick up on other events, potentially Players events you can log them with the `logEvent()` method. You can log the event name accompanied with optional additional parameters.
Once Firebase Analytics is installed and the Player Embed is embedded using our iOS SDK, you can add listeners to various Dailymotion player events and log them to Google analytics via Firebase's `logEvent` method to log custom events in app. To learn more about our iOS SDK and the events our player sends, please see [https://developer.dailymotion.com/player/#embed-mobile-ios].
Below is an example of picking on some player events and logging to them GA using the `logEvent`. These events can also be logged over with some corresponding properties and values.For information about logging events and additional values with Firebase please read (https://firebase.google.com/docs/analytics/events?platform=ios).
extension ViewController: DMPlayerViewControllerDelegate {
func player(_ player: DMPlayerViewController, didReceiveEvent event: PlayerEvent) {
switch event {
case .namedEvent(let name, _) where name == "loadedmetadata":
Analytics.logEvent("loadedmetadata", parameters: nil)
case .namedEvent(let name, _) where name == "apiready":
Analytics.logEvent("apiready", parameters: nil)
default:
break
}
}
}