Skip to content

Commit dd6896c

Browse files
committed
Firebase Analytics
1 parent c2c772e commit dd6896c

15 files changed

Lines changed: 206 additions & 60 deletions

android/app/src/main/AndroidManifest.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:tools="http://schemas.android.com/tools">
3+
4+
<uses-permission
5+
android:name="com.google.android.gms.permission.AD_ID"
6+
tools:node="remove" />
27

38
<application
49
android:icon="@mipmap/ic_launcher"

ios/Podfile.lock

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,45 @@ PODS:
66
- ffmpeg_kit_flutter_full_gpl/full-gpl (5.1.0):
77
- ffmpeg-kit-ios-full-gpl (= 5.1)
88
- Flutter
9+
- Firebase/Analytics (10.9.0):
10+
- Firebase/Core
11+
- Firebase/Core (10.9.0):
12+
- Firebase/CoreOnly
13+
- FirebaseAnalytics (~> 10.9.0)
914
- Firebase/CoreOnly (10.9.0):
1015
- FirebaseCore (= 10.9.0)
1116
- Firebase/Crashlytics (10.9.0):
1217
- Firebase/CoreOnly
1318
- FirebaseCrashlytics (~> 10.9.0)
19+
- firebase_analytics (10.4.2):
20+
- Firebase/Analytics (= 10.9.0)
21+
- firebase_core
22+
- Flutter
1423
- firebase_core (2.13.1):
1524
- Firebase/CoreOnly (= 10.9.0)
1625
- Flutter
1726
- firebase_crashlytics (3.3.2):
1827
- Firebase/Crashlytics (= 10.9.0)
1928
- firebase_core
2029
- Flutter
30+
- FirebaseAnalytics (10.9.0):
31+
- FirebaseAnalytics/AdIdSupport (= 10.9.0)
32+
- FirebaseCore (~> 10.0)
33+
- FirebaseInstallations (~> 10.0)
34+
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
35+
- GoogleUtilities/MethodSwizzler (~> 7.11)
36+
- GoogleUtilities/Network (~> 7.11)
37+
- "GoogleUtilities/NSData+zlib (~> 7.11)"
38+
- nanopb (< 2.30910.0, >= 2.30908.0)
39+
- FirebaseAnalytics/AdIdSupport (10.9.0):
40+
- FirebaseCore (~> 10.0)
41+
- FirebaseInstallations (~> 10.0)
42+
- GoogleAppMeasurement (= 10.9.0)
43+
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
44+
- GoogleUtilities/MethodSwizzler (~> 7.11)
45+
- GoogleUtilities/Network (~> 7.11)
46+
- "GoogleUtilities/NSData+zlib (~> 7.11)"
47+
- nanopb (< 2.30910.0, >= 2.30908.0)
2148
- FirebaseCore (10.9.0):
2249
- FirebaseCoreInternal (~> 10.0)
2350
- GoogleUtilities/Environment (~> 7.8)
@@ -53,15 +80,47 @@ PODS:
5380
- FMDB (2.7.5):
5481
- FMDB/standard (= 2.7.5)
5582
- FMDB/standard (2.7.5)
83+
- GoogleAppMeasurement (10.9.0):
84+
- GoogleAppMeasurement/AdIdSupport (= 10.9.0)
85+
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
86+
- GoogleUtilities/MethodSwizzler (~> 7.11)
87+
- GoogleUtilities/Network (~> 7.11)
88+
- "GoogleUtilities/NSData+zlib (~> 7.11)"
89+
- nanopb (< 2.30910.0, >= 2.30908.0)
90+
- GoogleAppMeasurement/AdIdSupport (10.9.0):
91+
- GoogleAppMeasurement/WithoutAdIdSupport (= 10.9.0)
92+
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
93+
- GoogleUtilities/MethodSwizzler (~> 7.11)
94+
- GoogleUtilities/Network (~> 7.11)
95+
- "GoogleUtilities/NSData+zlib (~> 7.11)"
96+
- nanopb (< 2.30910.0, >= 2.30908.0)
97+
- GoogleAppMeasurement/WithoutAdIdSupport (10.9.0):
98+
- GoogleUtilities/AppDelegateSwizzler (~> 7.11)
99+
- GoogleUtilities/MethodSwizzler (~> 7.11)
100+
- GoogleUtilities/Network (~> 7.11)
101+
- "GoogleUtilities/NSData+zlib (~> 7.11)"
102+
- nanopb (< 2.30910.0, >= 2.30908.0)
56103
- GoogleDataTransport (9.2.3):
57104
- GoogleUtilities/Environment (~> 7.7)
58105
- nanopb (< 2.30910.0, >= 2.30908.0)
59106
- PromisesObjC (< 3.0, >= 1.2)
107+
- GoogleUtilities/AppDelegateSwizzler (7.11.1):
108+
- GoogleUtilities/Environment
109+
- GoogleUtilities/Logger
110+
- GoogleUtilities/Network
60111
- GoogleUtilities/Environment (7.11.1):
61112
- PromisesObjC (< 3.0, >= 1.2)
62113
- GoogleUtilities/Logger (7.11.1):
63114
- GoogleUtilities/Environment
115+
- GoogleUtilities/MethodSwizzler (7.11.1):
116+
- GoogleUtilities/Logger
117+
- GoogleUtilities/Network (7.11.1):
118+
- GoogleUtilities/Logger
119+
- "GoogleUtilities/NSData+zlib"
120+
- GoogleUtilities/Reachability
64121
- "GoogleUtilities/NSData+zlib (7.11.1)"
122+
- GoogleUtilities/Reachability (7.11.1):
123+
- GoogleUtilities/Logger
65124
- GoogleUtilities/UserDefaults (7.11.1):
66125
- GoogleUtilities/Logger
67126
- image_picker_ios (0.0.1):
@@ -90,6 +149,7 @@ PODS:
90149

91150
DEPENDENCIES:
92151
- ffmpeg_kit_flutter_full_gpl (from `.symlinks/plugins/ffmpeg_kit_flutter_full_gpl/ios`)
152+
- firebase_analytics (from `.symlinks/plugins/firebase_analytics/ios`)
93153
- firebase_core (from `.symlinks/plugins/firebase_core/ios`)
94154
- firebase_crashlytics (from `.symlinks/plugins/firebase_crashlytics/ios`)
95155
- Flutter (from `Flutter`)
@@ -105,13 +165,15 @@ SPEC REPOS:
105165
trunk:
106166
- ffmpeg-kit-ios-full-gpl
107167
- Firebase
168+
- FirebaseAnalytics
108169
- FirebaseCore
109170
- FirebaseCoreExtension
110171
- FirebaseCoreInternal
111172
- FirebaseCrashlytics
112173
- FirebaseInstallations
113174
- FirebaseSessions
114175
- FMDB
176+
- GoogleAppMeasurement
115177
- GoogleDataTransport
116178
- GoogleUtilities
117179
- nanopb
@@ -121,6 +183,8 @@ SPEC REPOS:
121183
EXTERNAL SOURCES:
122184
ffmpeg_kit_flutter_full_gpl:
123185
:path: ".symlinks/plugins/ffmpeg_kit_flutter_full_gpl/ios"
186+
firebase_analytics:
187+
:path: ".symlinks/plugins/firebase_analytics/ios"
124188
firebase_core:
125189
:path: ".symlinks/plugins/firebase_core/ios"
126190
firebase_crashlytics:
@@ -146,8 +210,10 @@ SPEC CHECKSUMS:
146210
ffmpeg-kit-ios-full-gpl: 2682965e5b3e7f13a05836d46d302eafe6c5039e
147211
ffmpeg_kit_flutter_full_gpl: 7dcfcdc419f4667252cde1871859976bca328169
148212
Firebase: bd152f0f3d278c4060c5c71359db08ebcfd5a3e2
213+
firebase_analytics: 48ed4a230abf9f585f7e7b477791effe96f5a791
149214
firebase_core: ce64b0941c6d87c6ef5022ae9116a158236c8c94
150215
firebase_crashlytics: 9b80d1944507cc07fa1c4455797f7d2eb7c8873f
216+
FirebaseAnalytics: 5ea0db4893825e7b0149d575352cd838236313dc
151217
FirebaseCore: b68d3616526ec02e4d155166bbafb8eca64af557
152218
FirebaseCoreExtension: 8d93ebbf6838a874b4ed82a564c9d6705f8365dd
153219
FirebaseCoreInternal: 971029061d326000d65bfdc21f5502c75c8b0893
@@ -157,6 +223,7 @@ SPEC CHECKSUMS:
157223
Flutter: f04841e97a9d0b0a8025694d0796dd46242b2854
158224
flutter_native_splash: 52501b97d1c0a5f898d687f1646226c1f93c56ef
159225
FMDB: 2ce00b547f966261cd18927a3ddb07cb6f3db82a
226+
GoogleAppMeasurement: 373bcbead1bb6a85be7a64d5d8f96284b762ea9c
160227
GoogleDataTransport: f0308f5905a745f94fb91fea9c6cbaf3831cb1bd
161228
GoogleUtilities: 9aa0ad5a7bc171f8bae016300bfcfa3fb8425749
162229
image_picker_ios: 4a8aadfbb6dc30ad5141a2ce3832af9214a705b5

lib/creation/creation.dart

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ class CreationScreen extends StatefulWidget {
2323
static Route<void> route({
2424
Movie? draftMovie,
2525
}) =>
26-
ScreenRoute(
27-
settings: const RouteSettings(
28-
name: 'creation',
26+
MaterialPageRoute(
27+
settings: AppRouteSettings(
28+
routeName: 'creation',
29+
screenClass: CreationScreen,
2930
),
30-
child: CreationScreen._(draftMovie: draftMovie),
31+
builder: (_) => CreationScreen._(draftMovie: draftMovie),
3132
);
3233

3334
final Movie? draftMovie;

lib/creation/widget/creation_cancel_dialog.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ enum CancelCreationResult {
99
}
1010

1111
class CancelCreationDialog extends StatelessWidget {
12-
static const RouteSettings _routeSettings = RouteSettings(
13-
name: 'creation/cancel',
12+
static final RouteSettings _routeSettings = AppRouteSettings(
13+
routeName: 'creation/cancel',
14+
screenClass: CancelCreationDialog,
1415
);
1516

1617
static Future<CancelCreationResult?> show(BuildContext context) async {

lib/creation/widget/creation_leave_dialog.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'package:flutter/material.dart';
22
import 'package:slidemix/localizations.dart';
3+
import 'package:slidemix/navigation.dart';
34
import 'package:slidemix/widget/button.dart';
45

56
enum LeaveCreationResult {
@@ -11,8 +12,9 @@ class LeaveCreationDialog extends StatelessWidget {
1112
static Future<LeaveCreationResult?> show(BuildContext context) async {
1213
return await showModalBottomSheet(
1314
context: context,
14-
routeSettings: const RouteSettings(
15-
name: 'creation/leave',
15+
routeSettings: AppRouteSettings(
16+
routeName: 'creation/leave',
17+
screenClass: LeaveCreationDialog,
1618
),
1719
isScrollControlled: true,
1820
builder: (_) => const LeaveCreationDialog._(),

lib/creation/widget/creation_source_dialog.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,16 @@
11
import 'package:flutter/material.dart';
22
import 'package:slidemix/localizations.dart';
3+
import 'package:slidemix/navigation.dart';
34

45
enum CreationMediaSource { camera, gallery }
56

67
class PickMediaSourceDialog extends StatelessWidget {
78
static Future<CreationMediaSource?> show(BuildContext context) =>
89
showModalBottomSheet<CreationMediaSource>(
910
context: context,
10-
routeSettings: const RouteSettings(
11-
name: 'creation/pick',
11+
routeSettings: AppRouteSettings(
12+
routeName: 'creation/pick',
13+
screenClass: PickMediaSourceDialog,
1214
),
1315
builder: (context) => const PickMediaSourceDialog._(),
1416
);

lib/logger.dart

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
import 'package:firebase_analytics/firebase_analytics.dart';
12
import 'package:firebase_core/firebase_core.dart';
23
import 'package:firebase_crashlytics/firebase_crashlytics.dart';
34
import 'package:flutter/foundation.dart';
5+
import 'package:flutter/material.dart';
46
import 'package:logger/logger.dart' as logger_impl;
57
import 'package:slidemix/firebase_options.dart';
8+
import 'package:slidemix/navigation.dart';
69

710
/// Log to Logcat only in debug mode, send logs to Crashlytics in other cases.
811
class Logger {
@@ -52,4 +55,68 @@ class Logger {
5255
);
5356
}
5457
}
58+
59+
static NavigatorObserver navigatorObserver = _NavigationLogger();
60+
61+
static void screen(Route route) {
62+
navigatorObserver.didPush(route, null);
63+
}
64+
}
65+
66+
class _NavigationLogger extends RouteObserver<Route<dynamic>> {
67+
@override
68+
void didPush(Route route, Route? previousRoute) {
69+
Logger.d('didPush ${_routeToLog(route)}, previous=${_routeToLog(previousRoute)}');
70+
_onScreenShown(route);
71+
}
72+
73+
@override
74+
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
75+
Logger.d('didReplace ${_routeToLog(newRoute)}, oldRoute=${_routeToLog(oldRoute)}');
76+
if (newRoute != null) _onScreenShown(newRoute);
77+
}
78+
79+
@override
80+
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
81+
Logger.d('didPop ${_routeToLog(route)}, previous=${_routeToLog(previousRoute)}');
82+
if (previousRoute != null) _onScreenShown(previousRoute);
83+
}
84+
85+
@override
86+
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
87+
Logger.d('didRemove ${_routeToLog(route)}, previous=${_routeToLog(previousRoute)}');
88+
if (previousRoute != null) _onScreenShown(previousRoute);
89+
}
90+
91+
String _routeToLog(Route<dynamic>? route) {
92+
if (route == null) return '';
93+
return <String>[
94+
"'${route.settings.name}'",
95+
if (route.settings.arguments != null)
96+
"arguments:${route.settings.arguments.toString()}",
97+
].join(' ');
98+
}
99+
100+
void _onScreenShown(Route<dynamic> route) {
101+
if (route.settings.name == '/') {
102+
// Ignore initial route, we will log inside WelcomeScreen when it's shown
103+
return;
104+
}
105+
106+
String screenClass = 'null';
107+
if (route.settings is AppRouteSettings) {
108+
screenClass = (route.settings as AppRouteSettings).screenClass.toString();
109+
}
110+
111+
if (Logger._crashlyticsEnabled) {
112+
FirebaseAnalytics.instance
113+
.setCurrentScreen(
114+
screenName: route.settings.name,
115+
screenClassOverride: screenClass,
116+
)
117+
.ignore();
118+
} else {
119+
Logger._loggerImpl.w('onScreenShown $screenClass, ${_routeToLog(route)}');
120+
}
121+
}
55122
}

lib/main.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class SlideMixApp extends StatelessWidget {
6363
navigatorKey: navigatorKey,
6464
navigatorObservers: [
6565
NavigationStackObserver(),
66-
NavigationLogger(),
66+
Logger.navigatorObserver,
6767
],
6868
localizationsDelegates: AppLocalizations.localizationsDelegates,
6969
supportedLocales: AppLocalizations.supportedLocales,

lib/movies/movies.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@ import 'package:slidemix/preview/preview.dart';
1010
import 'package:slidemix/widget/toolbar.dart';
1111

1212
class MoviesScreen extends StatefulWidget {
13-
static Route<void> route() => ScreenRoute(
14-
settings: const RouteSettings(name: 'movies'),
15-
child: const MoviesScreen._(),
13+
static Route<void> route() => MaterialPageRoute(
14+
settings: AppRouteSettings(
15+
routeName: 'movies',
16+
screenClass: MoviesScreen,
17+
),
18+
builder: (_) => const MoviesScreen._(),
1619
);
1720

1821
const MoviesScreen._({Key? key}) : super(key: key);

lib/navigation.dart

Lines changed: 16 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
11
import 'package:flutter/material.dart';
2-
import 'package:slidemix/logger.dart';
2+
3+
class AppRouteSettings extends RouteSettings {
4+
final String routeName;
5+
final Type screenClass;
6+
7+
AppRouteSettings({
8+
required this.routeName,
9+
required this.screenClass,
10+
Map<String, Object>? arguments,
11+
}) : super(
12+
name: routeName,
13+
arguments: <String, Object>{
14+
'screenClass': screenClass.toString(),
15+
}..addAll(arguments ?? {}),
16+
);
17+
}
318

419
class ScreenRoute<T> extends MaterialPageRoute<T> {
520
ScreenRoute({
@@ -58,33 +73,3 @@ class NavigationStackObserver extends RouteObserver<Route<dynamic>> {
5873
_stack.removeWhere((e) => e.settings.name == route.settings.name);
5974
}
6075
}
61-
62-
class NavigationLogger extends RouteObserver<Route<dynamic>> {
63-
@override
64-
void didPush(Route route, Route? previousRoute) {
65-
Logger.d('didPush ${_routeToLog(route)} ||| ${_routeToLog(previousRoute)}');
66-
}
67-
68-
@override
69-
void didReplace({Route<dynamic>? newRoute, Route<dynamic>? oldRoute}) {
70-
Logger.d('didReplace ${_routeToLog(newRoute)} ||| ${_routeToLog(oldRoute)}');
71-
}
72-
73-
@override
74-
void didPop(Route<dynamic> route, Route<dynamic>? previousRoute) {
75-
Logger.d('didPop ${_routeToLog(route)} ||| ${_routeToLog(previousRoute)}');
76-
}
77-
78-
@override
79-
void didRemove(Route<dynamic> route, Route<dynamic>? previousRoute) {
80-
Logger.d('didRemove ${_routeToLog(route)} ||| ${_routeToLog(previousRoute)}');
81-
}
82-
83-
String _routeToLog(Route<dynamic>? route) {
84-
if (route == null) return '';
85-
return <String>[
86-
"'${route.settings.name}'",
87-
if (route.settings.arguments != null) "arguments:{${route.settings.arguments.toString()}}",
88-
].join(' ');
89-
}
90-
}

0 commit comments

Comments
 (0)