如何获取Android应用的Tracking ID?Analytics控制台仅显示Firebase选项
Hey there! I’ve dealt with this exact frustration before—when you need that old-school Tracking ID but the Analytics console just shoves Firebase in your face. Let’s break down how to track it down:
1. Switch to the Universal Analytics View (If It Exists)
- Open your Google Analytics console and pick your project.
- Hit the Admin gear icon at the bottom left corner.
- In the Property column, click on Property Settings.
- Scroll down until you see the Universal Analytics Property section. There’s a link that says "See your Universal Analytics property"—click that to jump to the old UA dashboard.
- Once you’re in the UA view, your Tracking ID (format:
UA-XXXXXXXXX-X) will be front-and-center at the top. If not, head to Admin > Tracking Info > Tracking Code to grab it.
2. Link Firebase to a Universal Analytics Property (If You Don’t Have One)
If your project was only set up with Firebase and no UA property, you’ll need to connect them first:
- Go to your Firebase console and open your project.
- Navigate to Project Settings > Integrations.
- Find Google Analytics in the list and click Link.
- Follow the prompts to either create a new UA property or link an existing one. Once linked, go back to the Google Analytics console’s UA view (using the steps above) to get your Tracking ID.
3. Quick Note on Implementation (For Legacy Apps)
If you need to add this Tracking ID to your Android app, here’s the quick setup (keep in mind UA is deprecated, so this is only for legacy use cases):
- Add this dependency to your module-level
build.gradle:implementation 'com.google.android.gms:play-services-analytics:17.0.0' - Initialize the tracker in your Application class:
import com.google.android.gms.analytics.GoogleAnalytics; import com.google.android.gms.analytics.Tracker; public class MyApp extends Application { private Tracker mTracker; synchronized public Tracker getDefaultTracker() { if (mTracker == null) { GoogleAnalytics analytics = GoogleAnalytics.getInstance(this); mTracker = analytics.newTracker("UA-XXXXXXXXX-X"); // Replace with your ID } return mTracker; } }
Heads Up: Universal Analytics stops processing data as of July 1, 2024. If you’re building a new app, Firebase Analytics is the way to go—it doesn’t use a traditional Tracking ID, but offers more robust event-based tracking directly in the Firebase console.
内容的提问来源于stack exchange,提问作者Josef Vancura

