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.

10.0 KB
Raw Blame
import {
    AndroidInstallation,
    AngularInstallation,
    AstroInstallation,
    BubbleInstallation,
    DjangoInstallation,
    DotNetInstallation,
    ExperimentImplementationSnippet,
    FlutterInstallation,
    FramerInstallation,
    GoInstallation,
    IOSInstallation,
    KMPInstallation,
    WebInstallation,
    LaravelInstallation,
    NextJSInstallation,
    NodeJSInstallation,
    NuxtInstallation,
    PHPInstallation,
    PythonInstallation,
    ReactInstallation,
    ReactNativeInstallation,
    ReactRouterInstallation,
    RemixInstallation,
    RubyInstallation,
    RubyOnRailsInstallation,
    SvelteInstallation,
    VueInstallation,
    WebflowInstallation,
} from '@posthog/shared-onboarding/experiments'
import {
    BooleanFlagSnippet,
    FlagPayloadSnippet,
    MultivariateFlagSnippet,
    OnFeatureFlagsCallbackSnippet,
    OverridePropertiesSnippet,
    ReloadFlagsSnippet,
} from '@posthog/shared-onboarding/feature-flags'
import { JSEventCapture, NodeEventCapture, PythonEventCapture } from '@posthog/shared-onboarding/product-analytics'

import { JS_WEB_SNIPPETS as BASE_JS_WEB_SNIPPETS } from 'scenes/onboarding/shared/jsWebSnippets'

import { SDKInstructionsMap, SDKKey } from '~/types'

import { withMobileReplay, withOnboardingDocsWrapper } from '../shared/onboardingWrappers'

// Snippet configurations
// JS Web SDKs - client-side with full JS capabilities
const JS_WEB_SNIPPETS = {
    ...BASE_JS_WEB_SNIPPETS,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    FlagPayloadSnippet,
    OnFeatureFlagsCallbackSnippet,
    ReloadFlagsSnippet,
    ExperimentImplementationSnippet,
}

// React - client-side with React hooks
const REACT_SNIPPETS = {
    ...BASE_JS_WEB_SNIPPETS,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    FlagPayloadSnippet,
    ExperimentImplementationSnippet,
}

// Node.js - server-side
const NODE_SNIPPETS = {
    NodeEventCapture,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    OverridePropertiesSnippet,
    ExperimentImplementationSnippet,
}

// Python - server-side
const PYTHON_SNIPPETS = {
    PythonEventCapture,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    OverridePropertiesSnippet,
    ExperimentImplementationSnippet,
}

// Server SDKs without specific event capture (PHP, Ruby, Go)
const SERVER_SDK_SNIPPETS = {
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    OverridePropertiesSnippet,
    ExperimentImplementationSnippet,
}

// Mobile/Native SDKs - basic flag support
const MOBILE_SNIPPETS = {
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    ExperimentImplementationSnippet,
}

// SSR Framework snippets (Next.js, Remix, Nuxt, Svelte)
const SSR_FRAMEWORK_SNIPPETS = {
    JSEventCapture,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    ExperimentImplementationSnippet,
}

// JS-based frameworks (Angular, Astro, Bubble, Framer, Vue, Webflow)
const JS_FRAMEWORK_SNIPPETS = {
    JSEventCapture,
    BooleanFlagSnippet,
    MultivariateFlagSnippet,
    ExperimentImplementationSnippet,
}

// Wrapped instruction components
const ExperimentsWebInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: WebInstallation,
    snippets: JS_WEB_SNIPPETS,
})
const ExperimentsReactInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: ReactInstallation,
    snippets: REACT_SNIPPETS,
    wizardIntegrationName: 'React',
})
const ExperimentsNodeInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: NodeJSInstallation,
    snippets: NODE_SNIPPETS,
})
const ExperimentsPythonInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: PythonInstallation,
    snippets: PYTHON_SNIPPETS,
    wizardIntegrationName: 'Python',
})
const ExperimentsPHPInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: PHPInstallation,
    snippets: SERVER_SDK_SNIPPETS,
})
const ExperimentsRubyInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: RubyInstallation,
    snippets: SERVER_SDK_SNIPPETS,
    wizardIntegrationName: 'Ruby',
})
const ExperimentsRubyOnRailsInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: RubyOnRailsInstallation,
    snippets: SERVER_SDK_SNIPPETS,
    wizardIntegrationName: 'Ruby on Rails',
})
const ExperimentsGoInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: GoInstallation,
    snippets: SERVER_SDK_SNIPPETS,
})
const ExperimentsDotNetInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: DotNetInstallation,
    snippets: SERVER_SDK_SNIPPETS,
})

// Mobile SDKs with AdvertiseMobileReplay
const ExperimentsAndroidInstructionsWrapper = withMobileReplay({
    Installation: AndroidInstallation,
    sdkKey: SDKKey.ANDROID,
    onboardingContext: 'experiments-onboarding',
    snippets: MOBILE_SNIPPETS,
    wizardIntegrationName: 'Android',
})
const ExperimentsIOSInstructionsWrapper = withMobileReplay({
    Installation: IOSInstallation,
    sdkKey: SDKKey.IOS,
    onboardingContext: 'experiments-onboarding',
    snippets: MOBILE_SNIPPETS,
    wizardIntegrationName: 'Swift',
})
const ExperimentsFlutterInstructionsWrapper = withMobileReplay({
    Installation: FlutterInstallation,
    sdkKey: SDKKey.FLUTTER,
    onboardingContext: 'experiments-onboarding',
    snippets: MOBILE_SNIPPETS,
})
const ExperimentsKMPInstructionsWrapper = withMobileReplay({
    Installation: KMPInstallation,
    sdkKey: SDKKey.KMP,
    onboardingContext: 'experiments-onboarding',
    snippets: MOBILE_SNIPPETS,
})
const ExperimentsRNInstructionsWrapper = withMobileReplay({
    Installation: ReactNativeInstallation,
    sdkKey: SDKKey.REACT_NATIVE,
    onboardingContext: 'experiments-onboarding',
    snippets: MOBILE_SNIPPETS,
    wizardIntegrationName: 'React Native',
})

// SSR Frameworks (with wizard support where available)
const ExperimentsNextJSInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: NextJSInstallation,
    snippets: SSR_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Next.js',
})
const ExperimentsSvelteInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: SvelteInstallation,
    snippets: SSR_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Svelte',
})
const ExperimentsReactRouterInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: ReactRouterInstallation,
    snippets: SSR_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'React Router',
})
const ExperimentsRemixJSInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: RemixInstallation,
    snippets: SSR_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'React Router',
})
const ExperimentsNuxtJSInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: NuxtInstallation,
    snippets: SSR_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Nuxt',
})

// JS Frameworks (with wizard support where available)
const ExperimentsAngularInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: AngularInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Angular',
})
const ExperimentsAstroInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: AstroInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Astro',
})
const ExperimentsBubbleInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: BubbleInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
})
const ExperimentsFramerInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: FramerInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
})
const ExperimentsVueInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: VueInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
    wizardIntegrationName: 'Vue',
})
const ExperimentsWebflowInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: WebflowInstallation,
    snippets: JS_FRAMEWORK_SNIPPETS,
})

// Python frameworks (with wizard support)
const ExperimentsDjangoInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: DjangoInstallation,
    snippets: PYTHON_SNIPPETS,
    wizardIntegrationName: 'Django',
})

// PHP frameworks
const ExperimentsLaravelInstructionsWrapper = withOnboardingDocsWrapper({
    Installation: LaravelInstallation,
    snippets: SERVER_SDK_SNIPPETS,
    wizardIntegrationName: 'Laravel',
})

export const ExperimentsSDKInstructions: SDKInstructionsMap = {
    [SDKKey.JS_WEB]: ExperimentsWebInstructionsWrapper,
    [SDKKey.ANDROID]: ExperimentsAndroidInstructionsWrapper,
    [SDKKey.ANGULAR]: ExperimentsAngularInstructionsWrapper,
    [SDKKey.ASTRO]: ExperimentsAstroInstructionsWrapper,
    [SDKKey.BUBBLE]: ExperimentsBubbleInstructionsWrapper,
    [SDKKey.DJANGO]: ExperimentsDjangoInstructionsWrapper,
    [SDKKey.DOTNET]: ExperimentsDotNetInstructionsWrapper,
    [SDKKey.FLUTTER]: ExperimentsFlutterInstructionsWrapper,
    [SDKKey.FRAMER]: ExperimentsFramerInstructionsWrapper,
    [SDKKey.GO]: ExperimentsGoInstructionsWrapper,
    [SDKKey.IOS]: ExperimentsIOSInstructionsWrapper,
    [SDKKey.KMP]: ExperimentsKMPInstructionsWrapper,
    [SDKKey.LARAVEL]: ExperimentsLaravelInstructionsWrapper,
    [SDKKey.NEXT_JS]: ExperimentsNextJSInstructionsWrapper,
    [SDKKey.NODE_JS]: ExperimentsNodeInstructionsWrapper,
    [SDKKey.NUXT_JS]: ExperimentsNuxtJSInstructionsWrapper,
    [SDKKey.PHP]: ExperimentsPHPInstructionsWrapper,
    [SDKKey.PYTHON]: ExperimentsPythonInstructionsWrapper,
    [SDKKey.REACT]: ExperimentsReactInstructionsWrapper,
    [SDKKey.REACT_NATIVE]: ExperimentsRNInstructionsWrapper,
    [SDKKey.REACT_ROUTER]: ExperimentsReactRouterInstructionsWrapper,
    [SDKKey.TANSTACK_START]: withOnboardingDocsWrapper({
        Installation: ReactInstallation,
        snippets: REACT_SNIPPETS,
        wizardIntegrationName: 'React',
    }),
    [SDKKey.REMIX]: ExperimentsRemixJSInstructionsWrapper,
    [SDKKey.RUBY]: ExperimentsRubyInstructionsWrapper,
    [SDKKey.RUBY_ON_RAILS]: ExperimentsRubyOnRailsInstructionsWrapper,
    [SDKKey.SVELTE]: ExperimentsSvelteInstructionsWrapper,
    [SDKKey.VITE]: withOnboardingDocsWrapper({
        Installation: ReactInstallation,
        snippets: REACT_SNIPPETS,
        wizardIntegrationName: 'React',
    }),
    [SDKKey.VUE_JS]: ExperimentsVueInstructionsWrapper,
    [SDKKey.WEBFLOW]: ExperimentsWebflowInstructionsWrapper,
}