How to Setup Firebase for OTT Video Services

Overview

Google has been making major changes to its Google Analytics product in recent months. In October 2019, they started sunsetting mobile app reporting using their Google Analytics SDK. This required companies wanting to collect usage data from their mobile apps to switch to Google’s successor service: Google Analytics for Firebase.

In this blog post, we will demonstrate how to solve a particular use-case for video streaming services: how to leverage Google Analytics for Firebase to track the video playback events generated by your apps. The primary purpose is to track how popular the content is on your service – at a much deeper level than a simple view count.  As a bonus, you will also be able to see how many users are watching content in near real-time.

This post is a follow-up to How to Set up Google Analytics for Video Success. While that article is still relevant for tracking video playback events from a website, this article is focused on playback events from apps.

Getting Started

If you are in a position to start collecting analytics data from scratch, we recommend using Google’s new App+Web property type. This makes it possible to track your website and app traffic in one combined view in Google Analytics. Krista Seiden has written an excellent step-by-step guide for creating an App+Web property on her blog. If creating an entirely new property is not an option for you, then you only need to create a new App property.

Developing for Video Events

Initial Setup

You will need to update your apps to include the Firebase SDK. Google has quick start guides to get you started. If more thorough step-by-step instructions would be helpful, Simo Ahava has written fantastic guides for Android and iOS.

Video Playback Events

Next you must update your video player to send events to Firebase when certain user playback events occur. First make sure to set a userId so that all video playback events are tied to a specific user. This can either be an anonymous id (e.g.: if your site offers free videos without requiring registration), or it can be a subscriber id. Do not use an email address for userId, as it constitutes PII and is against Google’s Terms of Service. For all video playback events, set an Event Name of “video_playback” and include the following Params in the Event:

Param Names Type Param Values
video_event String The type of video playback event. See table below for the list of event types.
video_id String Content ID.
video_title String Title of the content.
video_position Int The user’s current playback position, in seconds.
video_duration Int The total duration of the content, in seconds.
video_progress Double Video position divided by video duration.

Send events to Firebase when the following actions occur:

Playback Event Description
start Sent once at the start of the video.
pause Sent when the user pauses the video.
resume Sent when the user resumes the video.
rewind Sent when the user rewinds the video.
fastforward Sent when the user fast-forwards the video.
stop Sent when the user stops the video.
skip Sent when the user skips to the next video in a playlist.
progress

Sent when the user reaches:

  • first 30 second marker into video
  • 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100% of total video duration

Android Sample Code

This sample code demonstrates the different kinds of playback events that could be sent from the video player to Google Analytics for Firebase:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
class MainActivity : AppCompatActivity() {

   private lateinit var firebaseAnalytics: FirebaseAnalytics

   override fun onCreate(savedInstanceState: Bundle?) {
       super.onCreate(savedInstanceState)

       // firebase developer documentation
       // https://firebase.google.com/docs/reference/android/com/google/firebase/analytics/package-summary

       firebaseAnalytics = FirebaseAnalytics.getInstance(this)

       // set user id
       firebaseAnalytics.setUserId("test_user_id")

       /** video playback events **/

       // video start
       val videoStartBundle = Bundle()
       videoStartBundle.putString("video_event", "start")
       videoStartBundle.putString("video_id", "tt7984734")
       videoStartBundle.putString("video_title", "The Lighthouse")
       videoStartBundle.putInt("video_position", 0)
       videoStartBundle.putInt("video_duration", 6540)
       videoStartBundle.putDouble("video_progress", 0.0)
       firebaseAnalytics.logEvent("video_playback", videoStartBundle)

       // video pause
       val videoPauseBundle = Bundle()
       videoPauseBundle.putString("video_event", "pause")
       videoPauseBundle.putString("video_id", "tt7984734")
       videoPauseBundle.putString("video_title", "The Lighthouse")
       videoPauseBundle.putInt("video_position", 654)
       videoPauseBundle.putInt("video_duration", 6540)
       videoPauseBundle.putDouble("video_progress", 10.0)
       firebaseAnalytics.logEvent("video_playback", videoPauseBundle)

       // video resume
       val videoResumeBundle = Bundle()
       videoResumeBundle.putString("video_event", "resume")
       videoResumeBundle.putString("video_id", "tt7984734")
       videoResumeBundle.putString("video_title", "The Lighthouse")
       videoResumeBundle.putInt("video_position", 654)
       videoResumeBundle.putInt("video_duration", 6540)
       videoResumeBundle.putDouble("video_progress", 10.0)
       firebaseAnalytics.logEvent("video_playback", videoResumeBundle)

       // video rewind
       val videoRewindBundle = Bundle()
       videoRewindBundle.putString("video_event", "rewind")
       videoRewindBundle.putString("video_id", "tt7984734")
       videoRewindBundle.putString("video_title", "The Lighthouse")
       videoRewindBundle.putInt("video_position", 327)
       videoRewindBundle.putInt("video_duration", 6540)
       videoRewindBundle.putDouble("video_progress", 5.0)
       firebaseAnalytics.logEvent("video_playback", videoRewindBundle)

       // video fast-forward
       val videoFastForwardBundle = Bundle()
       videoFastForwardBundle.putString("video_event", "fastforward")
       videoFastForwardBundle.putString("video_id", "tt7984734")
       videoFastForwardBundle.putString("video_title", "The Lighthouse")
       videoFastForwardBundle.putInt("video_position", 4905)
       videoFastForwardBundle.putInt("video_duration", 6540)
       videoFastForwardBundle.putDouble("video_progress", 75.0)
       firebaseAnalytics.logEvent("video_playback", videoFastForwardBundle)

       // video stop
       val videoStopBundle = Bundle()
       videoStopBundle.putString("video_event", "stop")
       videoStopBundle.putString("video_id", "tt7984734")
       videoStopBundle.putString("video_title", "The Lighthouse")
       videoStopBundle.putInt("video_position", 6000)
       videoStopBundle.putInt("video_duration", 6540)
       videoStopBundle.putDouble("video_progress", 91.74)
       firebaseAnalytics.logEvent("video_playback", videoStopBundle)

       // video skip
       val videoSkipBundle = Bundle()
       videoSkipBundle.putString("video_event", "skip")
       videoSkipBundle.putString("video_id", "tt7984734")
       videoSkipBundle.putString("video_title", "The Lighthouse")
       videoSkipBundle.putInt("video_position", 6000)
       videoSkipBundle.putInt("video_duration", 6540)
       videoSkipBundle.putDouble("video_progress", 91.74)
       firebaseAnalytics.logEvent("video_playback", videoSkipBundle)

       // video progress
       // send progress events at:
       // - first 30 seconds reached
       // - 10%, 20%, 30%, 40%, 50%, 60%, 70%, 80%, 90%, 100% of video completion
       val videoProgressBundle = Bundle()
       videoProgressBundle.putString("video_event", "progress")
       videoProgressBundle.putString("video_id", "tt7984734")
       videoProgressBundle.putString("video_title", "The Lighthouse")
       videoProgressBundle.putInt("video_position", 654)
       videoProgressBundle.putInt("video_duration", 6540)
       videoProgressBundle.putDouble("video_progress", 10.0)
       firebaseAnalytics.logEvent("video_playback", videoProgressBundle)

       setContentView(R.layout.activity_main)
   }
}

Debugging

Firebase has a feature called DebugView that makes testing very efficient. Once enabled, you will see an event stream delivered in near real-time in the Firebase Console. You will also be able to see all custom event parameters and values, which are otherwise not possible to see in the Firebase Console. We highly recommend using this feature to confirm that your events are firing at the correct times and with all of the correct values.

Exporting with BigQuery

There’s a new paradigm to access your raw data in Firebase versus Google Analytics. Google Analytics historically has offered a reporting API, whereas Firebase offers a database: Google BigQuery. There are a number of extra steps that you must follow to enable BigQuery for Firebase, the first of which is to upgrade to Firebase’s Blaze plan. This is a pay-as-you-go plan with a pleasant bonus: Google offers free usage quotas per month, so depending on the amount of traffic generated by your apps, you may end up paying little or nothing. You may wish to do more research on the pricing based on your expected usage.

Why would you want to set up raw data access in BigQuery?

  1. It enables quick, ad-hoc analysis of your data.
  2. Certain data (like custom parameters) cannot be viewed in their entirety in the Firebase Console, whereas all data are made available in BigQuery. This makes access to the raw data essential for advanced users and third-party audience analytics platforms like the Wicket Scorecard, who rely on a complete dataset.

We recommend that you enable the link with BigQuery as soon as possible, as the data only starts being delivered from the date that you enable the configuration. Data is not populated in BigQuery retroactively.

We again to turn to Simo Ahava for a step-by-step guide to link BigQuery with Firebase.

We hope you found this guide helpful in setting up Firebase for Google Analytics. To learn more about how Wicket Labs can help set your video service up for success, contact us for a demo of the Wicket Scorecard to see how we’re increasing audience lifetime value for our customers.

 

 

Tags:
Stay in the Know

Stay in the Know

Don't miss the latest OTT industry insights, product releases, company updates, and more.

You have Successfully Subscribed!

Share This