flutter 接入 谷歌统计 Firebase analytics
更新时间:2023-05-25 21:55
更详细步骤请移步:将 Firebase 添加到您的 Flutter 应用 (google.com)
开通firebase账号 Firebase console (google.com)
安卓:
开通firebase账号 Firebase console (google.com)
- 修改 pubspec.yaml 增加
dependencies:
firebase_core: ^1.7.0 #firebase基础服务 firebase_analytics: ^8.3.3 #谷歌统计
安卓:
- 下载 google-services.json 到 android/app/google-services.json
- android/build.gradle 增加:
-
dependencies {
classpath 'com.android.tools.build:gradle:4.1.0' classpath 'com.google.gms:google-services:4.3.4' //谷歌统计 }
- android/app/build.gradle 增加:
-
apply plugin: 'com.google.gms.google-services' //谷歌统计
IOS 接入
- 下载 GoogleService-Info.plist 到 ios/Runner/GoogleService-Info.plist
项目
//统计 FirebaseAnalytics analytics = FirebaseAnalytics();
lib/main.dart
......
class MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
MaterialApp(
......
navigatorObservers: <NavigatorObserver>[FirebaseAnalyticsObserver(analytics: analytics)],//加入路由统计
);
}
}
其他调用:
analytics.logEvent(name: 'component', parameters: {'name': itemInfo.title});
lib/main.dart
......
class MainAppState extends State<MainApp> {
@override
Widget build(BuildContext context) {
MaterialApp(
......
navigatorObservers: <NavigatorObserver>[FirebaseAnalyticsObserver(analytics: analytics)],//加入路由统计
);
}
}
其他调用:
analytics.logEvent(name: 'component', parameters: {'name': itemInfo.title});