This article shows you how to configure an application to use Google Analytics. To configure a website to use Analytics, see Set up Analytics for a website and/or app.
Before you begin
Add Firebase to your Android project and make sure that Analytics is enabled in your Firebase project:
If you're creating a new Firebase project, enable Analytics during the project creation workflow.
If you're using an existing Firebase project that doesn't have Analytics enabled, go to the Integrations tab of your
to enable it. > Project settings When you enable Analytics in your project, your Firebase apps are linked to Analytics data streams.
Add the Analytics SDK to your app
Using the Firebase Android BoM, declare the dependency for the Analytics Android library in your module (app-level) Gradle file (usually
app/build.gradle
).Java
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:29.3.0') // Declare 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' }
Kotlin
dependencies { // Import the BoM for the Firebase platform implementation platform('com.google.firebase:firebase-bom:29.3.0') // Declare 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-ktx' }
Declare the
com.google.firebase.analytics.FirebaseAnalytics
object at the top of your activity:Java
private FirebaseAnalytics mFirebaseAnalytics;
Kotlin
private lateinit var firebaseAnalytics: FirebaseAnalytics
Initialize it in the
onCreate()
method:Java
// Obtain the FirebaseAnalytics instance. mFirebaseAnalytics = FirebaseAnalytics.getInstance(this);
Kotlin
// Obtain the FirebaseAnalytics instance. firebaseAnalytics = Firebase.analytics
Next steps
- Send events to Analytics.
- Use the DebugView to verify your events.
- Explore your data in the Firebase console.
- Explore the guides on events and user properties.
- Learn how to export your data to BigQuery.