Document PostHog dart-define configuration

This commit is contained in:
Juan José Mata
2026-05-24 22:39:41 +02:00
parent 89f42497a9
commit 2c2e357d73
4 changed files with 50 additions and 0 deletions

View File

@@ -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

View File

@@ -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...');

View 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.',
);
}
}

View File

@@ -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: