跳到正文
Skillpedia
通用编程41k · #6979

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。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/PostHog/posthog/blob/master/products/wizard/skills/installing-posthog-in-a-codebase/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 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.

Framework Docs page
JavaScript web (any framework) https://posthog.com/docs/libraries/js.md
React, including Vite apps https://posthog.com/docs/libraries/react.md
Next.js https://posthog.com/docs/libraries/next-js.md
Vue.js https://posthog.com/docs/libraries/vue-js.md
Nuxt https://posthog.com/docs/libraries/nuxt-js.md
Svelte and SvelteKit https://posthog.com/docs/libraries/svelte.md
Angular https://posthog.com/docs/libraries/angular.md
Astro https://posthog.com/docs/libraries/astro.md
Remix https://posthog.com/docs/libraries/remix.md
React Router https://posthog.com/docs/libraries/react-router.md
TanStack Start https://posthog.com/docs/libraries/tanstack-start.md
Node.js, including Express https://posthog.com/docs/libraries/node.md
Python, including FastAPI https://posthog.com/docs/libraries/python.md
Django https://posthog.com/docs/libraries/django.md
Flask https://posthog.com/docs/libraries/flask.md
Ruby https://posthog.com/docs/libraries/ruby.md
Ruby on Rails https://posthog.com/docs/libraries/ruby-on-rails.md
PHP https://posthog.com/docs/libraries/php.md
Laravel https://posthog.com/docs/libraries/laravel.md
Go https://posthog.com/docs/libraries/go.md
Java https://posthog.com/docs/libraries/java.md
.NET https://posthog.com/docs/libraries/dotnet.md
Elixir https://posthog.com/docs/libraries/elixir.md
Rust https://posthog.com/docs/libraries/rust.md
React Native https://posthog.com/docs/libraries/react-native.md
Flutter https://posthog.com/docs/libraries/flutter.md
iOS https://posthog.com/docs/libraries/ios.md
Android https://posthog.com/docs/libraries/android.md

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_TOKEN and NEXT_PUBLIC_POSTHOG_HOST).
  • Write the real values to the env file the framework loads, such as .env.local or .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

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能