shared_prefs_telemetry 0.1.1
shared_prefs_telemetry: ^0.1.1 copied to clipboard
A Flutter package that automatically reads SharedPreferences data and sends it to a telemetry server at app launch.
SharedPrefs Telemetry #
A Flutter package that automatically reads SharedPreferences data and sends it to a telemetry server at app launch.
Features #
- Automatic Initialization: Automatically triggers at app launch
- Privacy Controls: Exclude sensitive keys from telemetry
- Configurable: Customizable server URL, API key, timeout, and logging
- Error Handling: Graceful error handling with optional logging
- Cross-Platform: Works on iOS, Android, and other Flutter platforms
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
shared_prefs_telemetry: ^0.1.0
Usage #
Basic Setup #
Initialize the telemetry package in your main() function:
import 'package:flutter/material.dart';
import 'package:shared_prefs_telemetry/shared_prefs_telemetry.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
// Initialize telemetry
await SharedPrefsTelemetry.initialize(
TelemetryConfig(
serverUrl: 'https://your-telemetry-server.com/api/collect',
apiKey: 'your-api-key-here', // Optional
enableLogging: true, // Optional, default: false
excludeKeys: ['password', 'token'], // Optional, default: []
timeout: const Duration(seconds: 15), // Optional, default: 10s
),
);
runApp(MyApp());
}
Configuration Options #
serverUrl(required): The URL of your telemetry serverapiKey(optional): API key for authenticationenableLogging(optional): Enable debug logging (default: false)excludeKeys(optional): List of SharedPreferences keys to exclude from telemetrytimeout(optional): HTTP request timeout (default: 10 seconds)
Data Format #
The package sends data in the following JSON format:
{
"timestamp": "2023-12-01T10:30:00.000Z",
"platform": "android",
"sharedPreferences": {
"user_name": "john_doe",
"theme_mode": "dark",
"notification_enabled": true,
"last_login": "2023-11-30T15:20:00.000Z"
}
}
Privacy Considerations #
⚠️ Important: This package reads ALL SharedPreferences data by default. Make sure to:
- Use the
excludeKeysparameter to exclude sensitive data - Comply with your app's privacy policy and applicable laws (GDPR, CCPA, etc.)
- Inform users about data collection in your privacy policy
- Consider implementing user consent mechanisms
Example #
See the example/ directory for a complete working example.
License #
This project is licensed under the MIT License.