mirror of
https://github.com/we-promise/sure.git
synced 2026-05-30 07:49:01 +00:00
Document PostHog dart-define configuration
This commit is contained in:
@@ -67,6 +67,20 @@ static String _baseUrl = 'http://localhost:3000';
|
||||
static String _baseUrl = 'https://your-sure-server.com';
|
||||
```
|
||||
|
||||
### 6. (Optional) Configure PostHog Session Recording
|
||||
|
||||
PostHog is configured with **compile-time** Dart defines (not `.env`):
|
||||
|
||||
```bash
|
||||
flutter run \
|
||||
--dart-define=POSTHOG_API_KEY=phc_your_project_key \
|
||||
--dart-define=POSTHOG_HOST=https://us.i.posthog.com
|
||||
```
|
||||
|
||||
- `POSTHOG_API_KEY` is required to enable PostHog.
|
||||
- `POSTHOG_HOST` is optional and defaults to `https://us.i.posthog.com`.
|
||||
- If `POSTHOG_API_KEY` is not passed, the app logs that PostHog is disabled and continues normally.
|
||||
|
||||
### 5. Run the App
|
||||
|
||||
```bash
|
||||
|
||||
@@ -17,10 +17,12 @@ import 'services/api_config.dart';
|
||||
import 'services/connectivity_service.dart';
|
||||
import 'services/log_service.dart';
|
||||
import 'services/preferences_service.dart';
|
||||
import 'services/posthog_service.dart';
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
await ApiConfig.initialize();
|
||||
await PostHogService.initialize();
|
||||
|
||||
// Add initial log entry
|
||||
LogService.instance.info('App', 'Sure app starting...');
|
||||
|
||||
33
mobile/lib/services/posthog_service.dart
Normal file
33
mobile/lib/services/posthog_service.dart
Normal file
@@ -0,0 +1,33 @@
|
||||
import 'package:posthog_flutter/posthog_flutter.dart';
|
||||
|
||||
import 'log_service.dart';
|
||||
|
||||
class PostHogService {
|
||||
PostHogService._();
|
||||
|
||||
static const String _apiKey = String.fromEnvironment('POSTHOG_API_KEY');
|
||||
static const String _host = String.fromEnvironment(
|
||||
'POSTHOG_HOST',
|
||||
defaultValue: 'https://us.i.posthog.com',
|
||||
);
|
||||
|
||||
static Future<void> initialize() async {
|
||||
if (_apiKey.isEmpty) {
|
||||
LogService.instance.info(
|
||||
'PostHog',
|
||||
'PostHog disabled: POSTHOG_API_KEY is not configured.',
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final config = PostHogConfig(_apiKey, host: _host);
|
||||
config.sessionReplay = true;
|
||||
|
||||
await Posthog().setup(config);
|
||||
|
||||
LogService.instance.info(
|
||||
'PostHog',
|
||||
'PostHog initialized with session replay enabled.',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,7 @@ dependencies:
|
||||
package_info_plus: ^8.0.0
|
||||
local_auth: ^2.3.0
|
||||
flutter_markdown: ^0.7.2
|
||||
posthog_flutter: ^5.24.2
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user