mirror of
https://github.com/GitJournal/GitJournal.git
synced 2025-06-30 19:36:25 +08:00
Send app_update in analytics
I'm calling this event gj_app_update as firebase automatically sends an app_update event. This is being done so that I can easily remove firebase analytics in the future.
This commit is contained in:
@ -44,6 +44,11 @@ enum Event {
|
||||
Settings,
|
||||
FeatureTimelineGithubClicked,
|
||||
|
||||
AppFirstOpen,
|
||||
AppUpdate,
|
||||
|
||||
// FIXME: Add os_update
|
||||
|
||||
/*
|
||||
Firebase Automatic Events:
|
||||
app_update:
|
||||
@ -122,6 +127,11 @@ String _eventToString(Event e) {
|
||||
|
||||
case Event.FeatureTimelineGithubClicked:
|
||||
return "feature_timeline_github_clicked";
|
||||
|
||||
case Event.AppFirstOpen:
|
||||
return "gj_first_open";
|
||||
case Event.AppUpdate:
|
||||
return "gj_app_update";
|
||||
}
|
||||
|
||||
return "unknown_event";
|
||||
|
22
lib/app.dart
22
lib/app.dart
@ -10,6 +10,7 @@ import 'package:dynamic_theme/dynamic_theme.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:easy_localization_loader/easy_localization_loader.dart';
|
||||
import 'package:flutter_sentry/flutter_sentry.dart';
|
||||
import 'package:package_info/package_info.dart';
|
||||
import 'package:path/path.dart' as p;
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
@ -53,6 +54,7 @@ class JournalApp extends StatefulWidget {
|
||||
if (appSettings.collectUsageStatistics) {
|
||||
_enableAnalyticsIfPossible(settings);
|
||||
}
|
||||
_sendAppUpdateEvent(appSettings);
|
||||
|
||||
var dir = await getApplicationDocumentsDirectory();
|
||||
appState.gitBaseDirectory = dir.path;
|
||||
@ -141,6 +143,26 @@ class JournalApp extends StatefulWidget {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> _sendAppUpdateEvent(AppSettings appSettings) async {
|
||||
var info = await PackageInfo.fromPlatform();
|
||||
var version = info.version;
|
||||
|
||||
if (appSettings.appVersion == version) {
|
||||
return;
|
||||
}
|
||||
|
||||
logEvent(Event.AppUpdate, parameters: {
|
||||
"version": version,
|
||||
"previous_app_version": appSettings.appVersion,
|
||||
"app_name": info.appName,
|
||||
"package_name": info.packageName,
|
||||
"build_number": info.buildNumber,
|
||||
});
|
||||
|
||||
appSettings.appVersion = version;
|
||||
appSettings.save();
|
||||
}
|
||||
|
||||
static final analytics = Analytics();
|
||||
static bool isInDebugMode = false;
|
||||
|
||||
|
@ -35,6 +35,8 @@ class AppSettings extends ChangeNotifier {
|
||||
var experimentalGraphView = false;
|
||||
var experimentalZeroConf = false;
|
||||
|
||||
var appVersion = "";
|
||||
|
||||
void load(SharedPreferences pref) {
|
||||
onBoardingCompleted = pref.getBool("onBoardingCompleted") ?? false;
|
||||
|
||||
@ -64,6 +66,8 @@ class AppSettings extends ChangeNotifier {
|
||||
pref.getBool("experimentalGraphView") ?? experimentalGraphView;
|
||||
experimentalZeroConf =
|
||||
pref.getBool("experimentalZeroConf") ?? experimentalZeroConf;
|
||||
|
||||
appVersion = pref.getString("appVersion") ?? "";
|
||||
}
|
||||
|
||||
Future<void> save() async {
|
||||
@ -92,6 +96,7 @@ class AppSettings extends ChangeNotifier {
|
||||
defaultSet.experimentalZeroConf);
|
||||
|
||||
pref.setInt("appSettingsVersion", version);
|
||||
pref.setString("appVersion", appVersion);
|
||||
|
||||
notifyListeners();
|
||||
}
|
||||
|
Reference in New Issue
Block a user