About integration-ruby
A skill for Ruby developers integrating PostHog analytics into applications. It includes a staged workflow and examples, plus guidance on SDK initialization, event calls, and shutting down the client before exit.
Key features
- 01Step-by-step integration workflow
- 02Ruby example and documentation
- 03Environment-based key configuration
- 04SDK initialization and event-call guidance
- 05User identification and error tracking guidance
Use cases
- 01Add PostHog analytics to a Ruby application
- 02Send analytics events from a script or CLI
- 03Identify users during login and signup
Install
Copy the command and run it in a terminal.
npx skills add https:/ / github.com/ posthog/ skills --skill integration-rubyAfter installing, type/integration-rubyin Claude Code to confirm it loaded.
Bundled files
References and scripts installed along with SKILL.md.
references/basic-integration-1.0-begin.mdbasic-integration-1.1-edit.mdbasic-integration-1.2-revise.mdbasic-integration-1.3-conclude.mdEXAMPLE.mdidentify-users.mdruby.mdDetails
From the project READMEPostHog integration for Ruby
This skill helps you add PostHog analytics to Ruby applications.
Workflow
Follow these steps in order to complete the integration:
basic-integration-1.0-begin.md- PostHog Setup - Begin ← Start herebasic-integration-1.1-edit.md- PostHog Setup - Editbasic-integration-1.2-revise.md- PostHog Setup - Revisebasic-integration-1.3-conclude.md- PostHog Setup - Conclusion
Reference files
references/EXAMPLE.md- Ruby example project codereferences/ruby.md- Ruby - docsreferences/identify-users.md- Identify users - docsreferences/basic-integration-1.0-begin.md- PostHog setup - beginreferences/basic-integration-1.1-edit.md- PostHog setup - editreferences/basic-integration-1.2-revise.md- PostHog setup - revisereferences/basic-integration-1.3-conclude.md- PostHog setup - conclusion
The example project shows the target implementation pattern. Consult the documentation for API details.
Key principles
- Environment variables: Always use environment variables for PostHog keys. Never hardcode them.
- Minimal changes: Add PostHog code alongside existing integrations. Don't replace or restructure existing code.
- Match the example: Your implementation should follow the example project's patterns as closely as possible.
Framework guidelines
- posthog-ruby is the Ruby SDK gem name (add
gem 'posthog-ruby'to Gemfile) but require it withrequire 'posthog'(NOTrequire 'posthog-ruby') - Use PostHog::Client.new(api_key: key, host: host) for instance-based initialization in scripts and CLIs
- In CLIs and scripts: MUST call client.shutdown before exit or all events are lost
- Use begin/rescue/ensure with shutdown in the ensure block for proper cleanup
- capture and identify take a single hash argument: client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' })
- capture_exception takes POSITIONAL args (not keyword): client.capture_exception(exception, distinct_id, additional_properties) — do NOT use
distinct_id:keyword syntax
Identifying users
Identify users during login and signup events. Refer to the example code and documentation for the correct identify pattern for this framework. If both frontend and backend code exist, pass the client-side session and distinct ID using X-POSTHOG-DISTINCT-ID and X-POSTHOG-SESSION-ID headers to maintain correlation.
Error tracking
Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.