Ruby product analytics installation

  1. Install the gem

    Required

    Add the PostHog Ruby gem to your Gemfile:

    Gemfile
    gem "posthog-ruby"
  2. Configure PostHog

    Required

    Initialize the PostHog client with your API key and host:

    Ruby
    posthog = PostHog::Client.new({
    api_key: "<ph_project_api_key>",
    host: "https://us.i.posthog.com",
    on_error: Proc.new { |status, msg| print msg }
    })
  3. Send events

    Capture custom events using the PostHog client:

    Ruby
    posthog.capture({
    distinct_id: 'user_123',
    event: 'button_clicked',
    properties: {
    button_name: 'signup'
    }
    })

    By default, for backwards compatibility reasons, events are sent with person profile processing enabled. This means a person profile will be created for each user who triggers an event.

    If you want to disable person profile processing for certain events, send the event with the following property:

    Ruby
    "$process_person_profile": false

Community questions

Was this page useful?

Questions about this page? or post a community question.