Where Is My Google Analytics Code on Android?
If you're looking for your Google Analytics code to install on your Android app, you might be thinking of the old JavaScript snippet used for websites. For mobile apps, things work a bit differently. This article will show you exactly what "code" you need - your Measurement ID - and walk you through the modern way of integrating Google Analytics into your Android project using the Firebase SDK.
Understanding the “Code”: Measurement ID vs. Tracking ID
First, let’s clear up some common confusion. Google has shifted from Universal Analytics (UA) to Google Analytics 4. This change affects the type of identifier you use.
- Tracking ID (UA-XXXXXXXXX-X): This was the identifier for the older Universal Analytics. If you're building a new app or setting up analytics for the first time, you can and should ignore this. Universal Analytics is no longer processing data.
- Measurement ID (G-XXXXXXXXXX): This is the new identifier used by Google Analytics 4. For any new Android and web tracking, the Measurement ID is what you're looking for. It acts as the unique identifier for your app's or website's data stream, telling Google Analytics where to send the collected event data.
So, when you see "Google Analytics code" in the context of a modern Android app, it refers to integrating the necessary tools that use your Measurement ID and a special configuration file to connect your app to your GA4 property.
How to Find Your Android Measurement ID in Google Analytics
If you already have a Google Analytics 4 property and an Android data stream set up, finding your Measurement ID is simple. Here’s how you do it step-by-step:
- Log in to your Google Analytics account.
- Click on the Admin gear icon in the bottom-left corner of the page.
- In the 'Property' column (the middle one), ensure your correct GA4 property is selected in the dropdown menu.
- Under the 'Property' settings, click on Data Streams.
- You'll see a list of your data streams for web, iOS, and Android. Click on your existing Android app stream.
- On the next screen, your Measurement ID (e.g., G-ABC123DEF4) will be displayed clearly in the top-right corner.
That's it! That G- value is the unique identifier for your Android app's data stream. However, you don't typically just copy and paste this into an Android project. The modern integration method uses a configuration file and the Firebase SDK.
Setting Up a New Android Data Stream
What if you don't have an Android data stream yet? No problem. It only takes a minute to create one. From the 'Data Streams' page mentioned above:
- Click the blue Add stream button and select Android app.
- Register your app:
- Click Register app.
After registering, Google Analytics will take you to a screen with your new Measurement ID and, more importantly, instructions for downloading your configuration file. This brings us to the next step: actual implementation.
Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Implementing Google Analytics in Your Android Project with Firebase
The recommended - and most powerful - way to add Google Analytics to an Android app is through Google's Firebase platform. Firebase is a suite of tools for building apps, and its Analytics SDK seamlessly sends data to your Google Analytics 4 property.
Step 1: Download Your Configuration File
Instead of manually inserting a Measurement ID, you’ll download a configuration file named google-services.json. This file contains your Measurement ID and all the other necessary keys to connect your app to your Firebase project and, by extension, Google Analytics.
During the Android data stream setup, Google provides a prominent button to Download google-services.json. Download this file and save it.
If you skipped this step before, you can always go back to your GA4 Data Stream settings or open your Firebase console, go to Project Settings (gear icon), scroll down to 'Your apps', and download the google-services.json file from there.
Step 2: Add the Configuration File to Your App
Open your project in Android Studio. Switch to the Project view in the file explorer on the left. Then, move the google-services.json file you just downloaded into your app’s root directory (e.g., MyAwesomeApp/app/).
Step 3: Configure Your Project’s Gradle Files
Next, you need to tell your Android project to use the Firebase SDK and a special plugin that reads your google-services.json file.
You’ll need to make additions to two different build.gradle or build.gradle.kts files.
1. At the Project-Level (build.gradle or build.gradle.kts in your root folder)
You need to add the Google services plugin. Your file should look something like this:
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id("com.android.application") version "8.X.X" apply false
id("org.jetbrains.kotlin.android") version "1.9.X" apply false
// ADD THIS LINE
id("com.google.gms.google-services") version "4.4.1" apply false
}2. At the App-Level (build.gradle or build.gradle.kts inside your 'app' folder)
First, apply the plugin at the top of the file. Then, add the Firebase Analytics library dependency.
plugins {
id("com.android.application")
id("org.jetbrains.kotlin.android")
// ADD THIS LINE AT THE TOP
id("com.google.gms.google-services")
}
android {
// ... your usual android config
}
dependencies {
// ... your other dependencies
// Add the Firebase BoM (Bill of Materials)
implementation(platform("com.google.firebase:firebase-bom:33.0.0"))
// Add the dependency for the Google Analytics library
// When using the BoM, you don't need to specify version
implementation("com.google.firebase:firebase-analytics")
}After adding these lines, click Sync Now in the banner that appears in Android Studio. This will download and configure all the necessary libraries for your project.
Step 4: Start Logging Events
With the setup complete, you can now start tracking user activity. The first step is to get an instance of the FirebaseAnalytics class.
In your main Activity or any relevant file, declare the analytics variable:
Kotlin:
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
class MainActivity : AppCompatActivity() {
private lateinit var firebaseAnalytics: FirebaseAnalytics
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
// Obtain the Firebase Analytics instance.
firebaseAnalytics = Firebase.analytics
}
}Now, you can log custom events anywhere in your app. For example, to track when a user clicks a "share" button:
val shareButton: Button = findViewById(R.id.share_button)
shareButton.setOnClickListener {
// Define the content details
val imageId = "image123"
val imageName = "Awesome Sunset Photo"
// Log a custom event
val bundle = Bundle()
bundle.putString("image_id", imageId)
bundle.putString("image_name", imageName)
firebaseAnalytics.logEvent("share_image", bundle)
}Free PDF · the crash course
AI Agents for Marketing Crash Course
Learn how to deploy AI marketing agents across your go-to-market — the best tools, prompts, and workflows to turn your data into autonomous execution without writing code.
Verifying That Your Integration Works
After adding the code, you'll naturally want to know if it's working. Waiting for data to show up in the standard Google Analytics reports can take 24-48 hours. Fortunately, there's a much faster way: DebugView.
DebugView shows you a real-time stream of events from your device. Here’s how to enable it:
- Connect your Android device or start an emulator.
- Open the terminal in Android Studio or your computer's command prompt.
- Run the following command, replacing
com.your.package.namewith your app's package name:
adb shell setprop debug.firebase.analytics.app com.your.package.name- Now, open either your Google Analytics account or your Firebase console. In GA, go to Admin > DebugView. In Firebase, it’s under Analytics > DebugView.
- Open your app and start triggering the events you’ve set up. You should see them appear in the DebugView stream within seconds.
If you see events, congratulations! Your app is successfully connected to Google Analytics.
Final Thoughts
To sum it up, finding your Google Analytics "code" for an Android app isn't about copying a code snippet. It’s about locating your GA4 Measurement ID and, more importantly, implementing the Firebase SDK using the google-services.json configuration file. This shifts tracking from a simple tag to a much more powerful and flexible event-based system right inside your application's logic.
Getting your app data flowing into Google Analytics is just the first hill to climb. The next challenge is making sense of it all, especially when that data needs to be combined with information from your ad platforms, CRM, and e-commerce store. We built Graphed to unify all your marketing and sales data sources automatically. You can connect everything in seconds and then use simple, natural language to ask questions or build real-time dashboards that show the complete picture of your performance - all without writing code or wrestling with spreadsheets.
Related Articles
Facebook Ads for Realtors: The Complete 2026 Strategy Guide
Discover how to use Facebook Ads for realtors to generate more leads in 2026. Learn proven strategies, targeting methods, and budget recommendations for your real estate business.
Facebook Ads for Accountants: The Complete 2026 Strategy Guide
Learn how to use Facebook ads for accountants to attract new clients in 2026. Discover targeting strategies, campaign setup, budgeting, and optimization techniques.
Facebook Ads for Electricians: The Complete 2026 Strategy Guide
Learn how to run high-converting Facebook ads for your electrical business in 2026. Covers campaign types, targeting strategies, and creative best practices.