From 8cc6b838de56223a730a37b52f370afd0c948c95 Mon Sep 17 00:00:00 2001 From: Frederik Benoist Date: Thu, 1 Jun 2023 23:20:02 +0200 Subject: [PATCH] refactor:plausible --- lib/main.dart | 22 +++++++++++++--------- lib/service/plausible.dart | 4 ++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 923f00a..520b253 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -96,16 +96,20 @@ class MyApp extends StatelessWidget with WidgetsBindingObserver { } else if (state == AppLifecycleState.resumed) { LoggerUtil.logNStackInfo("The application is resumed"); - // check if plausible is UP - await PlausibleUtil.hello(); + if (PlausibleUtil.isPlausibleInitialized()) { + // check if plausible is UP + await PlausibleUtil.hello(); - PlausibleUtil.addEvent( - name: 'access', - page: 'access', - referrer: 'referrerPage', - props: { - 'name': SharedPrefs().login, - }); + PlausibleUtil.addEvent( + name: 'access', + page: 'access', + referrer: 'referrerPage', + props: { + 'name': SharedPrefs().login, + }); + } else { + await PlausibleUtil.initializePlausible(window.physicalSize.width); + } } else if (state == AppLifecycleState.inactive) { LoggerUtil.logNStackInfo("The application is inactive"); } else if (state == AppLifecycleState.detached) { diff --git a/lib/service/plausible.dart b/lib/service/plausible.dart index 1cdc376..1a0dfc2 100644 --- a/lib/service/plausible.dart +++ b/lib/service/plausible.dart @@ -5,6 +5,10 @@ import 'package:mobdr/network/get_ip_address.dart'; class PlausibleUtil { static PlausibleTracker? plausible; + static bool isPlausibleInitialized() { + return plausible != null; + } + static Future initializePlausible(double screenWidth) async { plausible = PlausibleTracker( "https://plausible.q2ii.fr",