44 lines
1.1 KiB
Dart
44 lines
1.1 KiB
Dart
import 'package:mobdr/core/routes/plausible_tracker.dart';
|
|
import 'package:mobdr/service/shared_prefs.dart';
|
|
import 'package:mobdr/network/get_ip_address.dart';
|
|
|
|
class PlausibleUtil {
|
|
static PlausibleTracker? plausible;
|
|
|
|
static bool isPlausibleInitialized() {
|
|
return plausible != null;
|
|
}
|
|
|
|
static Future<void> initializePlausible(double screenWidth) async {
|
|
plausible = PlausibleTracker(
|
|
"https://plausible.q2ii.fr",
|
|
"mobdr.ikksgroup.com",
|
|
);
|
|
|
|
await plausible!.hello();
|
|
|
|
plausible!.userAgent = SharedPrefs().mobileUserAgent;
|
|
plausible!.xForwardedFor = await getPublicIPAddress();
|
|
plausible!.screenWidth = screenWidth.toString();
|
|
plausible!.enabled = await plausible!.hello();
|
|
}
|
|
|
|
static Future<void> hello() async {
|
|
plausible!.enabled = await plausible!.hello();
|
|
}
|
|
|
|
static void addEvent({
|
|
required String name,
|
|
required String page,
|
|
String? referrer,
|
|
Map<String, String>? props,
|
|
}) {
|
|
PlausibleUtil.plausible?.event(
|
|
name: name,
|
|
page: page,
|
|
referrer: referrer ?? '',
|
|
props: props ?? {},
|
|
);
|
|
}
|
|
}
|