Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

4.2 KB
Raw Blame
import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'

import { getReactNativeSteps as getReactNativeStepsPA } from '../product-analytics/react-native'
import { StepDefinition } from '../steps'

export const getReactNativeSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
    const { CodeBlock, Markdown, dedent } = ctx

    // Get installation steps from product-analytics
    const installationSteps = getReactNativeStepsPA(ctx)

    // Add flag-specific steps
    const flagSteps: StepDefinition[] = [
        {
            title: 'Use feature flags',
            badge: 'required',
            content: (
                <>
                    <Markdown>
                        {dedent`
                            PostHog provides hooks to make it easy to use feature flags in your React Native app. Use \`useFeatureFlagEnabled\` for boolean flags:
                        `}
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'tsx',
                                file: 'Component.tsx',
                                code: dedent`
                                    import { usePostHog } from 'posthog-react-native'

                                    function MyComponent() {
                                        const posthog = usePostHog()
                                        const isMyFlagEnabled = posthog.isFeatureEnabled('flag-key')

                                        if (isMyFlagEnabled) {
                                            // Do something differently for this user
                                            // Optional: fetch the payload
                                            const matchedFlagPayload = posthog.getFeatureFlagResult('flag-key')?.payload
                                        }

                                        return <View>...</View>
                                    }
                                `,
                            },
                        ]}
                    />
                    <Markdown>
                        {dedent`
                            ### Multivariate flags

                            For multivariate flags, use \`getFeatureFlag\`:
                        `}
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'tsx',
                                file: 'Component.tsx',
                                code: dedent`
                                    import { usePostHog } from 'posthog-react-native'

                                    function MyComponent() {
                                        const posthog = usePostHog()
                                        const enabledVariant = posthog.getFeatureFlag('flag-key')

                                        if (enabledVariant === 'variant-key') { // replace 'variant-key' with the key of your variant
                                            // Do something differently for this user
                                            // Optional: fetch the payload
                                            const matchedFlagPayload = posthog.getFeatureFlagResult('flag-key')?.payload
                                        }

                                        return <View>...</View>
                                    }
                                `,
                            },
                        ]}
                    />
                </>
            ),
        },
        {
            title: 'Running experiments',
            badge: 'optional',
            content: (
                <Markdown>
                    {dedent`
                        Experiments run on top of our feature flags. Once you've implemented the flag in your code, you run an experiment by creating a new experiment in the PostHog dashboard.
                    `}
                </Markdown>
            ),
        },
    ]

    return [...installationSteps, ...flagSteps]
}

export const ReactNativeInstallation = createInstallation(getReactNativeSteps)