PostHog Ruby
Please see the main PostHog docs.
Specifically, the Ruby integration details.
Important
Supports Ruby 3.2 and above
We will lag behind but generally not support versions which are end-of-life as listed here https://www.ruby-lang.org/en/downloads/branches/
All 2.x versions of the PostHog Ruby library are compatible with Ruby 2.0 and above if you need Ruby 2.0 support.
Rails Integration
Using Rails? Check out posthog-rails for automatic exception tracking, ActiveJob instrumentation, and Rails-specific features.
Developing Locally
- Install
asdfto manage your Ruby version:brew install asdf - Install Ruby's plugin via
asdf plugin add ruby https://github.com/asdf-vm/asdf-ruby.git - Make
asdfinstall the required version by runningasdf install - Run
bundle installto install dependencies
Running example file
- Build the
posthog-rubygem by calling:gem build posthog-ruby.gemspec. - Install the gem locally:
gem install ./posthog-ruby-<version>.gem - Run
ruby example.rb
Testing
- Run
bin/test(this ends up callingbundle exec rspec) - An example of running specific tests:
bin/test spec/posthog/client_spec.rb:26
How to release
Both posthog-ruby and posthog-rails are released together with the same version number.
-
Create a PR that:
- Updates
lib/posthog/version.rbwith the new version - Updates
CHANGELOG.mdwith the changes and current date
- Updates
-
Add the
releaselabel to the PR -
Merge the PR to
main -
The release workflow will:
- Notify the Client Libraries team in Slack
- Wait for approval via the GitHub
Releaseenvironment - Publish both gems to RubyGems (via trusted publishing)
- Create and push a git tag
-
Approve the release in GitHub when prompted
The workflow handles publishing both posthog-ruby and posthog-rails in the correct order (since posthog-rails depends on posthog-ruby).