Add usage analytics service for app open logging

This commit is contained in:
nahnah
2026-03-17 18:14:54 +00:00
parent c50f85aec7
commit e4e17907e8
+31
View File
@@ -0,0 +1,31 @@
import 'dart:math';
import 'package:http/http.dart' as http;
import 'package:shared_preferences/shared_preferences.dart';
class UsageAnalyticsService {
static String _generateRandomInstallId() {
final random = Random();
return List.generate(10, (index) => random.nextInt(10)).join();
}
static Future<void> logAppOpen() async {
final prefs = await SharedPreferences.getInstance();
String installId = prefs.getString('install_id') ?? _generateRandomInstallId();
await prefs.setString('install_id', installId);
final response = await http.post(
Uri.parse('https://florid.knoxxbox.in/v1/app_open.php'),
headers: {
'X-Api-Key': 'YOUR_API_KEY_HERE', // Replace with actual API key.
},
body: {
'install_id': installId,
// Add any other necessary data here
},
);
if (response.statusCode != 200) {
// Handle error if needed
}
}
}