I'm planning to integrate PostHog into my Flutter program. After the user logs in to my app, I want to modify the PostHog project.
Add your PostHog configuration to the AndroidManifest.xml file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.package.name"> <application> <meta-data android:name="com.posthog.posthog.API_KEY" android:value="YOUR_API_KEY" /> <meta-data android:name="com.posthog.posthog.POSTHOG_HOST" android:value="https://app.posthog.com" /> <meta-data android:name="com.posthog.posthog.TRACK_APPLICATION_LIFECYCLE_EVENTS" android:value="true" /> <meta-data android:name="com.posthog.posthog.DEBUG" android:value="true" /> </application> </manifest> Update the minimum Android SDK version to 21 in android/app/build.gradle:
defaultConfig { minSdkVersion 21 } main.dart file:
import 'package:flutter/material.dart'; import 'package:posthog_flutter/posthog_flutter.dart'; void main() { runApp(MyApp()); } class MyApp extends StatelessWidget { @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Analytics', theme: ThemeData( primarySwatch: Colors.blue, ), home: HomePage(), ); } } class HomePage extends StatelessWidget { @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: Text('Home'), ), body: Center( child: ElevatedButton( onPressed: () { Posthog().capture(event: 'button_clicked'); }, child: Text('Click me'), ), ), ); } } How can I use Flutter to make runtime changes to the PostHog project?