55 lines
1.4 KiB
Dart
55 lines
1.4 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 Future<void> initializePlausible() async {
|
|
final ipAddress = await getPublicIPAddress();
|
|
|
|
plausible = PlausibleTracker(
|
|
serverUrl: "https://plausible.q2ii.fr",
|
|
domain: "mobdr.ikksgroup.com",
|
|
userAgent: SharedPrefs().mobileUserAgent,
|
|
screenWidth: SharedPrefs().screenWidth.toString(),
|
|
xForwardedFor: ipAddress,
|
|
);
|
|
}
|
|
|
|
static bool isPlausibleEnabled() {
|
|
return plausible?.enabled ?? false;
|
|
}
|
|
|
|
static Future<void> checkPlausibleUp() async {
|
|
await plausible?.hello();
|
|
|
|
if (isPlausibleEnabled() && SharedPrefs().login.isNotEmpty) {
|
|
// track application access
|
|
PlausibleUtil.addEventAsync(
|
|
name: 'access',
|
|
page: 'access',
|
|
referrer: 'referrerPage',
|
|
props: {
|
|
'name': SharedPrefs().login,
|
|
});
|
|
}
|
|
}
|
|
|
|
static void addEventAsync({
|
|
required String name,
|
|
required String page,
|
|
String? referrer,
|
|
Map<String, String>? props,
|
|
}) async {
|
|
if (isPlausibleEnabled()) {
|
|
plausible?.event(
|
|
name: name,
|
|
page: page,
|
|
referrer: referrer ?? '',
|
|
props: props ?? {},
|
|
);
|
|
}
|
|
}
|
|
}
|