Flutter surveys installation

  1. Add PostHog to your app

    Required

    Using it requires PostHog's Flutter SDK version >= 5.8.0, but it's recommended to always use the latest version.

    Note: For mobile surveys, you must setup the SDK manually.

    Manual installation

    First, add posthog_flutter to your pubspec.yaml:

    pubspec.yaml
    # rest of your code
    dependencies:
    flutter:
    sdk: flutter
    posthog_flutter: ^5.0.0
    # rest of your code

    Then complete the manual setup for each platform:

    Android setup

    Add your PostHog configuration to your AndroidManifest.xml file located in the android/app/src/main:

    android/app/src/main/AndroidManifest.xml
    <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="your.package.name">
    <application>
    <!-- ... other configuration ... -->
    <meta-data android:name="com.posthog.posthog.AUTO_INIT" android:value="false" />
    </application>
    </manifest>

    You'll also need to update the minimum Android SDK version to 21 in android/app/build.gradle:

    android/app/build.gradle
    // rest of your config
    defaultConfig {
    minSdkVersion 21
    // rest of your config
    }
    // rest of your config

    iOS setup

    Add your PostHog configuration to the Info.plist file located in the ios/Runner directory:

    ios/Runner/Info.plist
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
    <!-- rest of your configuration -->
    <key>com.posthog.posthog.AUTO_INIT</key>
    <false/>
    </dict>
    </plist>

    You'll need to set the minimum platform version to iOS 13.0 in your Podfile:

    ios/Podfile
    platform :ios, '13.0'
    # rest of your config

    Dart setup

    Then setup the SDK manually:

    Dart
    import 'package:flutter/material.dart';
    import 'package:posthog_flutter/posthog_flutter.dart';
    Future<void> main() async {
    // init WidgetsFlutterBinding if not yet
    WidgetsFlutterBinding.ensureInitialized();
    final config = PostHogConfig('<ph_project_api_key>');
    config.debug = true;
    config.captureApplicationLifecycleEvents = true;
    // or EU Host: 'https://eu.i.posthog.com'
    config.host = 'https://us.i.posthog.com';
    await Posthog().setup(config);
    runApp(MyApp());
    }

  2. Install PosthogObserver

    Required

    For surveys to be shown, you need to add the PosthogObserver to your app. The observer allows PostHog to determine the appropriate context for displaying surveys.

    Dart
    import 'package:flutter/material.dart';
    import 'package:posthog_flutter/posthog_flutter.dart';
    class MyApp extends StatefulWidget {
    const MyApp({super.key});
    State<MyApp> createState() => _MyAppState();
    }
    class _MyAppState extends State<MyApp> {
    void initState() {
    super.initState();
    }
    Widget build(BuildContext context) {
    return PostHogWidget(
    child: MaterialApp(
    navigatorObservers: [PosthogObserver()],
    title: 'My App',
    home: const HomeScreen(),
    ),
    );
    }
    }

    If you're using go_router, check this page to learn how to set up the PosthogObserver.

Configuration

Important: For Flutter Web, surveys are powered by the JavaScript Web SDK, so any Flutter-specific survey configuration will be ignored. Please refer to the Web installation guide for proper setup.

Surveys are enabled by default. If you want to disable surveys, you can do so when setting up your SDK instance:

Dart
final config = PostHogConfig('<ph_project_api_key>');
config.surveys = false; // Disable surveys

Supported Features

FeatureSupport
Questions
All question types
Multi-question surveys
Confirmation message
Feedback button presentation
Conditional questions
Customization / Appearance
Set colors in PostHog dashboard
Shuffle questions
PostHog branding
Delay popup after screen view
Position config❌ (always bottom sheet)
HTML content
Display conditions
Feature flag & property targeting
Screen/URL targeting
Device type targeting
Survey wait period
Event triggers
Action triggers
Partial responses

Limitations

  • On Android, requires API >= 26.
  • On iOS, minimum deployment target is iOS13.
  • On Web, surveys are powered by the JavaScript Web SDK.
  • Requires PostHog Flutter SDK version >= 5.8.0

Troubleshooting

  • Update your SDK and iOS Pods.
  • Make sure to set the minimum platform version to iOS 13.0 in your Podfile.
  • Make sure you have disabled automatic SDK initialization.
  • Run a clean build if you experience issues.
  • If surveys are not being displayed when triggered, make sure you have installed the PosthogObserver.
  • If you are using multiple navigation observers and encounter a log message [PostHog] Cannot show survey: No valid context found..., try placing PosthogObserver first in the list of observers. We've noticed that order sometimes matters due to potential interference.

Community questions

Was this page useful?

Questions about this page? or post a community question.