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.

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

import { StepDefinition } from '../steps'

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

    return [
        {
            title: 'Install the gems',
            badge: 'required',
            content: (
                <>
                    <Markdown>
                        {dedent`
                            Add the \`posthog-ruby\` and \`posthog-rails\` gems to your Gemfile:
                        `}
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'ruby',
                                file: 'Gemfile',
                                code: dedent`
                                    gem "posthog-ruby"
                                    gem "posthog-rails"
                                `,
                            },
                        ]}
                    />
                    <Markdown>Then run:</Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'bash',
                                file: 'Terminal',
                                code: dedent`
                                    bundle install
                                `,
                            },
                        ]}
                    />
                </>
            ),
        },
        {
            title: 'Generate the initializer',
            badge: 'required',
            content: (
                <>
                    <Markdown>
                        {dedent`
                            Run the install generator to create the PostHog initializer:
                        `}
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'bash',
                                file: 'Terminal',
                                code: dedent`
                                    rails generate posthog:install
                                `,
                            },
                        ]}
                    />
                    <Markdown>
                        {dedent`
                            This will create \`config/initializers/posthog.rb\` with sensible defaults and documentation.
                        `}
                    </Markdown>
                </>
            ),
        },
        {
            title: 'Configure PostHog',
            badge: 'required',
            content: (
                <>
                    <Markdown>
                        {dedent`
                            Update \`config/initializers/posthog.rb\` with your project token and host:
                        `}
                    </Markdown>
                    <CodeBlock
                        blocks={[
                            {
                                language: 'ruby',
                                file: 'config/initializers/posthog.rb',
                                code: dedent`
                                    PostHog.init do |config|
                                      config.api_key = '<ph_project_token>'
                                      config.host = '<ph_client_api_host>'
                                    end
                                `,
                            },
                        ]}
                    />
                </>
            ),
        },
    ]
}

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

    return {
        title: 'Send events',
        badge: 'recommended',
        content: (
            <>
                <Markdown>Once installed, you can manually send events to test your integration:</Markdown>
                <CodeBlock
                    blocks={[
                        {
                            language: 'ruby',
                            file: 'Ruby',
                            code: dedent`
                                    PostHog.capture({
                                        distinct_id: 'user_123',
                                        event: 'button_clicked',
                                        properties: {
                                            button_name: 'signup'
                                        }
                                    })
                                `,
                        },
                    ]}
                />
            </>
        ),
    }
}

export const getRubyOnRailsSteps = (ctx: OnboardingComponentsContext): StepDefinition[] => [
    ...getRubyOnRailsInstallSteps(ctx),
    getRubyOnRailsEventStep(ctx),
]

export const RubyOnRailsInstallation = createInstallation(getRubyOnRailsSteps)