integration-ruby
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePostHog integration for Ruby
Ruby应用的PostHog集成
This skill helps you add PostHog analytics to Ruby applications.
本技能可帮助你为Ruby应用添加PostHog分析功能。
Workflow
工作流程
Follow these steps in order to complete the integration:
- - PostHog Setup - Begin ← Start here
basic-integration-1.0-begin.md - - PostHog Setup - Edit
basic-integration-1.1-edit.md - - PostHog Setup - Revise
basic-integration-1.2-revise.md - - PostHog Setup - Conclusion
basic-integration-1.3-conclude.md
按照以下步骤完成集成:
- - PostHog 设置 - 开始 ← 从此处开始
basic-integration-1.0-begin.md - - PostHog 设置 - 编辑
basic-integration-1.1-edit.md - - PostHog 设置 - 修订
basic-integration-1.2-revise.md - - PostHog 设置 - 总结
basic-integration-1.3-conclude.md
Reference files
参考文件
- - Ruby example project code
references/EXAMPLE.md - - Ruby - docs
references/ruby.md - - Identify users - docs
references/identify-users.md - - PostHog setup - begin
references/basic-integration-1.0-begin.md - - PostHog setup - edit
references/basic-integration-1.1-edit.md - - PostHog setup - revise
references/basic-integration-1.2-revise.md - - PostHog setup - conclusion
references/basic-integration-1.3-conclude.md
The example project shows the target implementation pattern. Consult the documentation for API details.
- - Ruby示例项目代码
references/EXAMPLE.md - - Ruby - 文档
references/ruby.md - - 用户识别 - 文档
references/identify-users.md - - PostHog设置 - 开始
references/basic-integration-1.0-begin.md - - PostHog设置 - 编辑
references/basic-integration-1.1-edit.md - - PostHog设置 - 修订
references/basic-integration-1.2-revise.md - - PostHog设置 - 总结
references/basic-integration-1.3-conclude.md
示例项目展示了目标实现模式。如需API详细信息,请查阅文档。
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.
- 环境变量:始终使用环境变量存储PostHog密钥,切勿硬编码。
- 最小改动:在现有集成代码旁添加PostHog代码,不要替换或重构现有代码。
- 匹配示例:你的实现应尽可能贴近示例项目的模式。
Framework guidelines
框架指南
- posthog-ruby is the Ruby SDK gem name (add to Gemfile) but require it with
gem 'posthog-ruby'(NOTrequire 'posthog')require '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 keyword syntax
distinct_id:
- posthog-ruby是Ruby SDK的gem名称(需在Gemfile中添加 ),但引用时使用
gem 'posthog-ruby'(而非require 'posthog')require 'posthog-ruby' - 在脚本和CLI中,使用PostHog::Client.new(api_key: key, host: host)进行基于实例的初始化
- 在CLI和脚本中:必须在退出前调用client.shutdown,否则所有事件都会丢失
- 使用begin/rescue/ensure结构,并在ensure块中调用shutdown以正确清理资源
- capture和identify方法接受单个哈希参数:client.capture(distinct_id: 'user_123', event: 'my_event', properties: { key: 'value' })
- capture_exception方法接受位置参数(而非关键字参数):client.capture_exception(exception, distinct_id, additional_properties) — 请勿使用关键字语法
distinct_id:
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 and headers to maintain correlation.
X-POSTHOG-DISTINCT-IDX-POSTHOG-SESSION-ID在登录和注册事件中识别用户。请参考示例代码和文档,了解适用于此框架的正确用户识别模式。如果同时存在前端和后端代码,请使用和传递客户端会话和唯一ID,以保持关联。
X-POSTHOG-DISTINCT-IDX-POSTHOG-SESSION-IDError tracking
错误追踪
Add PostHog error tracking to relevant files, particularly around critical user flows and API boundaries.
为相关文件添加PostHog错误追踪,尤其是关键用户流程和API边界附近的文件。