Skip to content

Commit

Permalink
Move plausible init to own method and fix disabled check
Browse files Browse the repository at this point in the history
  • Loading branch information
Codel1417 committed Jun 5, 2024
1 parent 7e6474c commit 9f1565e
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/Backend/plausible_dio.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class PlausibleDio extends Plausible {
/// Post event to plausible
@override
Future<int> event({String name = "pageview", String referrer = "", String page = "", Map<String, String> props = const {}}) async {
if (!enabled && HiveProxy.getOrDefault(settings, allowAnalytics, defaultValue: allowAnalyticsDefault)) {
if (!enabled || HiveProxy.getOrDefault(settings, allowAnalytics, defaultValue: allowAnalyticsDefault)) {
return 0;
}
final transaction = Sentry.startTransaction('Plausible Event', 'http');
Expand Down
8 changes: 6 additions & 2 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -185,12 +185,16 @@ Future<void> initLocale() async {
mainLogger.info("Loaded locale: $defaultLocale $localeLoaded");
}

void initPlausible({bool enabled = false}) {
plausible = PlausibleDio(serverUrl, domain);
plausible.enabled = enabled;
}

class TailApp extends StatefulWidget {
TailApp({super.key}) {
//Init Plausible
initPlausible();
// Platform messages may fail, so we use a try/catch PlatformException.
plausible = PlausibleDio(serverUrl, domain);
plausible.enabled = true;
mainLogger.info('Starting app');
if (kDebugMode) {
mainLogger.info('Debug Mode Enabled');
Expand Down

0 comments on commit 9f1565e

Please sign in to comment.