Flutter
[Flutter] Firebase Analytics 추가하기. (ios)
개발_블로그
2024. 12. 21. 19:21
앞 부분은 생략하겠습니다. 아래 링크 참조
https://jangstory.tistory.com/167
1. Flutter pubspec.yaml 코드 추가 .
firebase_analytics: ^11.3.3
2. ga.dart 파일 추가
import 'package:firebase_analytics/firebase_analytics.dart';
final FirebaseAnalytics analytics = FirebaseAnalytics.instance;
final gaObserver = FirebaseAnalyticsObserver(analytics: analytics);
3. Flutter main.dart 코드 추가
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Admin Panel',
theme: ThemeData.light().copyWith(
scaffoldBackgroundColor: bgColor2,
textTheme: GoogleFonts.poppinsTextTheme(Theme.of(context).textTheme)
.apply(bodyColor: Colors.black),
),
navigatorObservers: [gaObserver],
home: const LoginView(),
);
}
4. ios / Podfile 코드 추가
target 'Runner' do
use_frameworks!
use_modular_headers!
pod 'FirebaseFirestore', '~> 11.2.0'
// 아래 2줄
pod 'FirebaseCore'
pod 'Firebase/Analytics'
flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
target 'RunnerTests' do
inherit! :search_paths
end
end
5. ios / Runner / Info.plist 코드 추가
<key>FirebaseAnalyticsCollectionEnabled</key>
<true/>
<key>FirebaseAutomaticScreenReportingEnabled</key>
<false/>
6. ios / Runner / AppDelegate.swift 코드 추가
import FirebaseAnalytics // 이 부분
@main
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
) -> Bool {
FirebaseApp.configure() // 이 부분
GeneratedPluginRegistrant.register(with: self)
return super.application(application, didFinishLaunchingWithOptions: launchOptions)
}
}
7. Xcode - Product - Scheme -> Edit Scheme
7-1. 스키마 추가
7-2. -FIRDebugEnabled 추가
확인.
1. ga.dart 파일 코드 추가 .
import 'package:firebase_analytics/firebase_analytics.dart';
final FirebaseAnalytics analytics = FirebaseAnalytics.instance;
final gaObserver = FirebaseAnalyticsObserver(analytics: analytics);
void logScreenView(String screenName) async {
print("screenName $screenName");
await analytics.logEvent(
name: 'screen_view',
parameters: {
'screen_name': screenName,
},
);
}
2. LoginView
class LoginView extends StatelessWidget {
const LoginView({super.key});
@override
Widget build(BuildContext context) {
logScreenView("LoginView 테스트");
return ..
.
.
.
.
3. Firebase 프로젝트 -> DebugView 이동
https://console.firebase.google.com/u/0/?hl=ko
확인 끝.