error-tracking-android

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PostHog error tracking for Android

适用于Android的PostHog错误追踪

This skill helps you add PostHog error tracking to Android applications.
本技能可帮助你为Android应用添加PostHog错误追踪功能。

Reference files

参考文件

  • references/android.md
    - Android error tracking installation - docs
  • references/fingerprints.md
    - Fingerprints - docs
  • references/alerts.md
    - Send error tracking alerts - docs
  • references/monitoring.md
    - Monitor and search issues - docs
  • references/assigning-issues.md
    - Assign issues to teammates - docs
  • references/upload-source-maps.md
    - Upload source maps - docs
Consult the documentation for API details and framework-specific patterns.
  • references/android.md
    - Android错误追踪安装文档
  • references/fingerprints.md
    - 指纹识别文档
  • references/alerts.md
    - 发送错误追踪告警文档
  • references/monitoring.md
    - 监控与搜索问题文档
  • references/assigning-issues.md
    - 向团队成员分配问题文档
  • references/upload-source-maps.md
    - 上传源文件映射文档
如需API详情和特定框架模式,请查阅相关文档。

Key principles

核心原则

  • Environment variables: Always use environment variables for PostHog keys and host URLs. Never hardcode them.
  • Minimal changes: Add error tracking alongside existing error handling. Don't replace or restructure existing error handling code.
  • Autocapture first: Enable exception autocapture in the SDK initialization before adding manual captures.
  • Source maps: Upload source maps so stack traces resolve to original source code, not minified bundles.
  • Manual capture for boundaries: Use
    captureException()
    at error boundaries and catch blocks for errors that don't propagate to the global handler.
  • 环境变量:始终使用环境变量存储PostHog密钥和主机URL,切勿硬编码。
  • 最小改动:在现有错误处理基础上添加错误追踪,不要替换或重构现有错误处理代码。
  • 自动捕获优先:在SDK初始化时启用异常自动捕获,再添加手动捕获。
  • 源文件映射:上传源文件映射,以便将堆栈跟踪解析为原始源代码而非压缩包代码。
  • 边界处手动捕获:在错误边界和catch块中使用
    captureException()
    捕获那些不会传播到全局处理器的错误。

Framework guidelines

框架指南

  • Adapt dependency configuration to the appropriate build.gradle(.kts) file according to the project gradle version
  • Call
    PostHogAndroid.setup()
    only once in the Application class's
    onCreate()
    method, so it's initialized as early as possible and only once.
  • Initialize PostHog in the Application class's
    onCreate()
    method
  • Ensure every activity has a
    android:label
    to accurately track screen views.
  • 根据项目gradle版本,将依赖配置适配到对应的build.gradle(.kts)文件中
  • 仅在Application类的
    onCreate()
    方法中调用一次
    PostHogAndroid.setup()
    ,确保尽早且仅初始化一次。
  • 在Application类的
    onCreate()
    方法中初始化PostHog
  • 确保每个Activity都设置了
    android:label
    ,以准确追踪屏幕视图。