Android Surveys installation

🚧 Note: Mobile surveys for Android is currently in beta. We'd love to hear your feedback on betas via the in-app support panel or one of our other support options.

  1. Install the dependency

    Required

    Add the PostHog Android SDK to your build.gradle dependencies:

    build.gradle
    dependencies {
    implementation("com.posthog:posthog-android:3.+")
    }
  2. Configure PostHog

    Required

    Initialize PostHog in your Application class:

    SampleApp.kt
    class SampleApp : Application() {
    companion object {
    const val POSTHOG_PROJECT_TOKEN = "<ph_project_token>"
    const val POSTHOG_HOST = "https://us.i.posthog.com"
    }
    override fun onCreate() {
    super.onCreate()
    // Create a PostHog Config with the given project token and host
    val config = PostHogAndroidConfig(
    apiKey = POSTHOG_PROJECT_TOKEN,
    host = POSTHOG_HOST
    )
    // Setup PostHog with the given Context and Config
    PostHogAndroid.setup(this, config)
    }
    }
  3. Send events

    Recommended

    Once installed, PostHog will automatically start capturing events. You can also manually send events to test your integration:

    Kotlin
    import com.posthog.PostHog
    PostHog.capture(
    event = "button_clicked",
    properties = mapOf(
    "button_name" to "signup"
    )
    )
  4. Add the surveys UI module

    Required

    Add the optional posthog-android-surveys-compose module alongside the core SDK. It provides a ready-made Jetpack Compose UI.

    build.gradle
    dependencies {
    // ... existing dependencies
    implementation("com.posthog:posthog-android-surveys-compose:0.+")
    }
  5. Enable surveys in your configuration

    Required

    Enable surveys in your PostHog configuration. The SDK auto-discovers the UI module from the classpath, so matching surveys render automatically with no extra wiring.

    SampleApp.kt
    val config = PostHogAndroidConfig(
    apiKey = POSTHOG_PROJECT_TOKEN,
    host = POSTHOG_HOST
    ).apply {
    surveys = true
    }
    PostHogAndroid.setup(appContext, config)
  6. Next steps

    Recommended

    After installing the PostHog SDK, you can create your first survey.

    ResourceDescription
    Creating surveysLearn how to build and customize your surveys
    Targeting surveysShow surveys to specific users based on properties, events, or feature flags
    How to create custom surveysBuild advanced survey experiences with custom code
    Framework guidesSetup guides for React, Next.js, Vue, and other frameworks
    More tutorialsOther real-world examples and use cases

    You should also identify users and capture events with PostHog to control who and when to show surveys to your users.

    Not all survey features are available on every SDK. See the SDK feature support matrix for a full comparison.

Supported features

Not all survey features are available on every SDK. See the SDK feature support matrix for a full comparison.

Limitations

  • HTML descriptions for questions and the thank-you screen render as plain text.

Troubleshooting

  • Update your SDK and run a clean build if you experience issues.
  • If surveys aren't shown, make sure surveys = true is set in your config and the survey is enabled in your project settings.

Community questions

Was this page useful?

Questions about this page? or post a community question.