installing-posthog-in-a-codebase
它能做什么
这项技能让智能体在它可以读取和编辑的代码库中安装 PostHog 分析库。适合希望为应用添加产品分析和会话回放的开发者。
适用场景
- ✓当你要求为应用添加 PostHog、产品分析或会话回放的时候。
- ✓当你希望为你的框架(例如 React 或 Next.js)安装 PostHog 库的时候。
- ✓当你希望智能体把项目令牌和主机设置放在正确位置的时候。
技能链接
https://github.com/PostHog/posthog/blob/master/products/wizard/skills/installing-posthog-in-a-codebase/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请按照 PostHog 文档中的最新设置,为我的 Next.js 应用添加 PostHog 分析。”
每周 5 个新技能,1 分钟读完。
工作原理
智能体会从项目文件中识别你的框架,并阅读对应的 PostHog 文档页面。然后它会安装最新的软件包,添加项目令牌和主机设置,并编写设置代码。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Installing PostHog in a codebase
Use this skill when you can read and edit the user's code.
If you can't access their code, as is common in ChatGPT on the web or Claude on the web, use installing-posthog-from-chat.
PostHog's docs are the source of truth for each SDK's setup. Init options, file locations and recommended settings change between SDK releases, so read the docs page for the framework before you write code, and follow it rather than what you remember.
1. Find the framework and read its docs
Detect the framework from the manifest files (package.json, pyproject.toml, requirements.txt, Gemfile, composer.json, go.mod, and so on) and the app's entry points.
A web app with its own backend usually needs a client SDK and a server SDK, so read both pages.
For a framework that isn't listed, call docs-search with the framework name.
2. Install the latest SDK
Add each package with the project's own package manager and no version, for example npm install posthog-js, pnpm add posthog-node, uv add posthog or bundle add posthog-ruby.
That resolves the newest release.
Don't type a version into the manifest from memory, because that pins an old release.
In a monorepo, install into the package that runs the app, not the workspace root.
3. Get the token and host
Call project-get without an ID.
Use api_token as the project token and api_host as the SDK's host option.
- Read both from environment variables in code, using the names the docs page uses (for example
NEXT_PUBLIC_POSTHOG_PROJECT_TOKENandNEXT_PUBLIC_POSTHOG_HOST). - Write the real values to the env file the framework loads, such as
.env.localor.env. If the project has an example env file, add the variable names there with empty values. - Never hard-code the
常见问题
智能体会凭记忆进行 PostHog 设置吗?
不会。它会先阅读你所用框架的最新文档,因为设置细节会随版本变化。
如果我不能让智能体访问我的代码怎么办?
那就会改用另一项技能,它会在聊天中逐步指导设置,并以拉取请求的形式交付。
涵盖哪些框架?
常见的网页框架,如 React、Next.js、Vue 和 Nuxt,以及几种服务器端语言,每种都有其专属的文档页面。
详情
作者的原始描述
Install and configure a PostHog SDK in a repository you can read and edit, following PostHog's docs for the framework. Use when a user working in their codebase asks to add, install, or set up PostHog, product analytics, session replay, or a PostHog SDK. Covers finding the right docs page, installing the latest package, getting the project token and ingestion host from project-get, keeping them in the env file, server-side setup, identifying users, and verifying the change. If you can't access the user's code, as is common in ChatGPT on the web or Claude on the web, use installing-posthog-from
repo: PostHog/posthog
热度
- GitHub 星标
- 41k
- 排名
- #6979
- 许可证
- —
- 更新时间
- 2026/11/2
评论
- …
同一仓库的更多技能
depot-ci
41k帮你的智能体设置并运行 Depot CI 工作流(GitHub Actions 的替代方案),包括迁移现有工作流和读取运行日志。
depot-container-builds
41k帮你的智能体在 Depot 的远程构建器上构建 Docker 镜像,包括多平台镜像、推送到镜像仓库,以及修复构建失败。
depot-github-runners
41k帮你的智能体把 GitHub Actions 任务迁移到 Depot 托管的运行器上,选择运行器规格和标签,并排查运行器设置问题。
editing-agents-md
41k帮你的智能体判断某条规则应写入 AGENTS.md 还是 CLAUDE.md,并以不会让文件臃肿的方式写下,确保规则真正生效。