changed how analytics work

This commit is contained in:
Kima 2024-10-02 21:06:01 +02:00
parent d7741ca1c4
commit 816ddf58a2
4 changed files with 53 additions and 30 deletions

View File

@ -18,7 +18,7 @@ import 'package:connectivity_plus/connectivity_plus.dart';
class FilcAPI { class FilcAPI {
// API base // API base
static const baseUrl = "https://api.refilc.hu"; static const baseUrl = "https://api.refilcapp.hu";
// Public API // Public API
static const schoolList = "$baseUrl/v3/public/school-list"; static const schoolList = "$baseUrl/v3/public/school-list";
@ -51,7 +51,7 @@ class FilcAPI {
static const gradeColorsByID = "$gradeColorsGet/"; static const gradeColorsByID = "$gradeColorsGet/";
// Payment API // Payment API
static const payment = "$baseUrl/v3/payment"; static const payment = "$baseUrl/v4/payment";
static const stripeSheet = "$payment/stripe-sheet"; static const stripeSheet = "$payment/stripe-sheet";
static Future<bool> checkConnectivity() async => static Future<bool> checkConnectivity() async =>
@ -93,10 +93,14 @@ class FilcAPI {
"x-filc-id": settings.xFilcId, "x-filc-id": settings.xFilcId,
"user-agent": userAgent, "user-agent": userAgent,
// platform things // platform things
"rf-platform": Platform.operatingSystem, "rf-platform":
"rf-platform-version": Platform.operatingSystemVersion, settings.analyticsEnabled ? Platform.operatingSystem : "unknown",
"rf-app-version": "rf-platform-version": settings.analyticsEnabled
const String.fromEnvironment("APPVER", defaultValue: "?"), ? Platform.operatingSystemVersion
: "unknown",
"rf-app-version": settings.analyticsEnabled
? const String.fromEnvironment("APPVER", defaultValue: "?")
: "unknown",
"rf-uinid": settings.xFilcId, "rf-uinid": settings.xFilcId,
}; };

View File

@ -60,6 +60,7 @@ class SettingsProvider extends ChangeNotifier {
UpdateChannel _updateChannel; UpdateChannel _updateChannel;
Config _config; Config _config;
String _xFilcId; String _xFilcId;
bool _analyticsEnabled;
bool _graphClassAvg; bool _graphClassAvg;
bool _goodStudent; bool _goodStudent;
bool _presentationMode; bool _presentationMode;
@ -137,6 +138,7 @@ class SettingsProvider extends ChangeNotifier {
required UpdateChannel updateChannel, required UpdateChannel updateChannel,
required Config config, required Config config,
required String xFilcId, required String xFilcId,
required bool analyticsEnabled,
required bool graphClassAvg, required bool graphClassAvg,
required bool goodStudent, required bool goodStudent,
required bool presentationMode, required bool presentationMode,
@ -208,6 +210,7 @@ class SettingsProvider extends ChangeNotifier {
_updateChannel = updateChannel, _updateChannel = updateChannel,
_config = config, _config = config,
_xFilcId = xFilcId, _xFilcId = xFilcId,
_analyticsEnabled = analyticsEnabled,
_graphClassAvg = graphClassAvg, _graphClassAvg = graphClassAvg,
_goodStudent = goodStudent, _goodStudent = goodStudent,
_presentationMode = presentationMode, _presentationMode = presentationMode,
@ -297,6 +300,7 @@ class SettingsProvider extends ChangeNotifier {
updateChannel: UpdateChannel.values[map["update_channel"]], updateChannel: UpdateChannel.values[map["update_channel"]],
config: Config.fromJson(configMap ?? {}), config: Config.fromJson(configMap ?? {}),
xFilcId: map["x_filc_id"], xFilcId: map["x_filc_id"],
analyticsEnabled: map["analytics_enabled"] == 1,
graphClassAvg: map["graph_class_avg"] == 1, graphClassAvg: map["graph_class_avg"] == 1,
goodStudent: false, goodStudent: false,
presentationMode: map["presentation_mode"] == 1, presentationMode: map["presentation_mode"] == 1,
@ -377,6 +381,7 @@ class SettingsProvider extends ChangeNotifier {
"notification_poll_interval": _notificationPollInterval, "notification_poll_interval": _notificationPollInterval,
"config": jsonEncode(config.json), "config": jsonEncode(config.json),
"x_filc_id": _xFilcId, "x_filc_id": _xFilcId,
"analytics_enabled": _analyticsEnabled ? 1 : 0,
"graph_class_avg": _graphClassAvg ? 1 : 0, "graph_class_avg": _graphClassAvg ? 1 : 0,
"presentation_mode": _presentationMode ? 1 : 0, "presentation_mode": _presentationMode ? 1 : 0,
"bell_delay_enabled": _bellDelayEnabled ? 1 : 0, "bell_delay_enabled": _bellDelayEnabled ? 1 : 0,
@ -458,6 +463,7 @@ class SettingsProvider extends ChangeNotifier {
updateChannel: UpdateChannel.stable, updateChannel: UpdateChannel.stable,
config: Config.fromJson({}), config: Config.fromJson({}),
xFilcId: const Uuid().v4(), xFilcId: const Uuid().v4(),
analyticsEnabled: true,
graphClassAvg: false, graphClassAvg: false,
goodStudent: false, goodStudent: false,
presentationMode: false, presentationMode: false,
@ -532,6 +538,7 @@ class SettingsProvider extends ChangeNotifier {
UpdateChannel get updateChannel => _updateChannel; UpdateChannel get updateChannel => _updateChannel;
Config get config => _config; Config get config => _config;
String get xFilcId => _xFilcId; String get xFilcId => _xFilcId;
bool get analyticsEnabled => _analyticsEnabled;
bool get graphClassAvg => _graphClassAvg; bool get graphClassAvg => _graphClassAvg;
bool get goodStudent => _goodStudent; bool get goodStudent => _goodStudent;
bool get presentationMode => _presentationMode; bool get presentationMode => _presentationMode;
@ -604,6 +611,7 @@ class SettingsProvider extends ChangeNotifier {
UpdateChannel? updateChannel, UpdateChannel? updateChannel,
Config? config, Config? config,
String? xFilcId, String? xFilcId,
bool? analyticsEnabled,
bool? graphClassAvg, bool? graphClassAvg,
bool? goodStudent, bool? goodStudent,
bool? presentationMode, bool? presentationMode,
@ -708,6 +716,9 @@ class SettingsProvider extends ChangeNotifier {
} }
if (config != null && config != _config) _config = config; if (config != null && config != _config) _config = config;
if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId; if (xFilcId != null && xFilcId != _xFilcId) _xFilcId = xFilcId;
if (analyticsEnabled != null && analyticsEnabled != _analyticsEnabled) {
_analyticsEnabled = analyticsEnabled;
}
if (graphClassAvg != null && graphClassAvg != _graphClassAvg) { if (graphClassAvg != null && graphClassAvg != _graphClassAvg) {
_graphClassAvg = graphClassAvg; _graphClassAvg = graphClassAvg;
} }

View File

@ -5,6 +5,7 @@ import 'package:refilc_plus/providers/plus_provider.dart';
import 'package:refilc_plus/ui/mobile/plus/activation_view/activation_view.dart'; import 'package:refilc_plus/ui/mobile/plus/activation_view/activation_view.dart';
import 'package:refilc_mobile_ui/plus/plus_screen.i18n.dart'; import 'package:refilc_mobile_ui/plus/plus_screen.i18n.dart';
import 'package:url_launcher/url_launcher.dart'; import 'package:url_launcher/url_launcher.dart';
import 'package:uuid/uuid.dart';
class PlusPlanCard extends StatelessWidget { class PlusPlanCard extends StatelessWidget {
const PlusPlanCard({ const PlusPlanCard({
@ -53,18 +54,24 @@ class PlusPlanCard extends StatelessWidget {
if (Provider.of<SettingsProvider>(context, listen: false).xFilcId == if (Provider.of<SettingsProvider>(context, listen: false).xFilcId ==
"none") { "none") {
ScaffoldMessenger.of(context).showSnackBar(const SnackBar( Provider.of<SettingsProvider>(context, listen: false)
content: Text( .update(xFilcId: const Uuid().v4(), store: true);
"Be kell kapcsolnod a Névtelen Analitikát a beállítások főoldalán, mielőtt reFilc+ előfizetést vásárolnál!",
style:
TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
),
backgroundColor: Colors.white,
));
return;
} }
// if (Provider.of<SettingsProvider>(context, listen: false).xFilcId ==
// "none") {
// ScaffoldMessenger.of(context).showSnackBar(const SnackBar(
// content: Text(
// "Be kell kapcsolnod a Névtelen Analitikát a beállítások főoldalán, mielőtt reFilc+ előfizetést vásárolnál!",
// style:
// TextStyle(color: Colors.black, fontWeight: FontWeight.bold),
// ),
// backgroundColor: Colors.white,
// ));
// return;
// }
if (Provider.of<PlusProvider>(context, listen: false).hasPremium) { if (Provider.of<PlusProvider>(context, listen: false).hasPremium) {
if (!active) { if (!active) {
launchUrl( launchUrl(

View File

@ -1177,7 +1177,7 @@ class SettingsScreenState extends State<SettingsScreen>
secondary: Icon( secondary: Icon(
FeatherIcons.barChart2, FeatherIcons.barChart2,
size: 22.0, size: 22.0,
color: settings.xFilcId != "none" color: settings.analyticsEnabled
? AppColors.of(context).text.withOpacity(0.95) ? AppColors.of(context).text.withOpacity(0.95)
: AppColors.of(context).text.withOpacity(.25), : AppColors.of(context).text.withOpacity(.25),
), ),
@ -1187,28 +1187,29 @@ class SettingsScreenState extends State<SettingsScreen>
fontWeight: FontWeight.w600, fontWeight: FontWeight.w600,
fontSize: 16.0, fontSize: 16.0,
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context).text.withOpacity(
settings.xFilcId != "none" ? 1.0 : .5), settings.analyticsEnabled ? 1.0 : .5),
), ),
), ),
subtitle: Text( subtitle: Text(
"Anonymous Usage Analytics".i18n, "Anonymous Usage Analytics".i18n,
style: TextStyle( style: TextStyle(
color: AppColors.of(context).text.withOpacity( color: AppColors.of(context)
settings.xFilcId != "none" ? .5 : .2), .text
.withOpacity(settings.analyticsEnabled ? .5 : .2),
), ),
), ),
onChanged: (v) { onChanged: (v) {
String newId; // String newId;
if (v == false) { // if (v == false) {
newId = "none"; // newId = "none";
} else if (settings.xFilcId == "none") { // } else if (settings.xFilcId == "none") {
newId = SettingsProvider.defaultSettings().xFilcId; // newId = SettingsProvider.defaultSettings().xFilcId;
} else { // } else {
newId = settings.xFilcId; // newId = settings.xFilcId;
} // }
settings.update(xFilcId: newId); settings.update(analyticsEnabled: v);
}, },
value: settings.xFilcId != "none", value: settings.analyticsEnabled,
activeColor: Theme.of(context).colorScheme.secondary, activeColor: Theme.of(context).colorScheme.secondary,
), ),
), ),