exploring-autocapture-events
它能做什么
本技能探索 PostHog 从你的网站自动记录的点击、表单和页面切换事件。适合希望了解用户点击了什么,并想根据这些点击创建动作的分析师和产品团队。
适用场景
- ✓当你想了解用户在你的网站上点击了什么的时候。
- ✓当你需要为某个按钮或链接找到可靠的 CSS 选择器,以创建动作时。
- ✓当你想在不写代码的情况下,根据一次点击创建动作的时候。
技能链接
https://github.com/PostHog/posthog/blob/master/products/product_analytics/skills/exploring-autocapture-events/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“用户在我们的定价页面上点击了什么?我如何为注册按钮制作一个可靠的选择器?”
每周 5 个新技能,1 分钟读完。
工作原理
它会读取每个事件中记录的被点击元素,检查某个选择器是否只匹配一个元素,并对匹配的点击运行查询。随后,它可以帮你创建动作。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Exploring autocapture events
if users opt in then posthog-js automatically captures clicks, form submissions, and page changes as $autocapture events.
Each event records the clicked DOM element and its ancestors in the elements_chain column.
$autocapture is intentionally excluded from the posthog:read-data-schema taxonomy
because it is only useful with autocapture-specific filters (selector, tag, text, href).
This skill fills that gap.
Materialized columns
The events table provides fast access to common element fields without parsing the full chain string.
| Column | Type | Description |
|---|---|---|
elements_chain |
String | Full semicolon-separated element chain (see format reference) |
elements_chain_href |
String | Last href value from the chain |
elements_chain_texts |
Array(String) | All text values from elements |
elements_chain_ids |
Array(String) | All id attribute values |
elements_chain_elements |
Array(String) | Useful tag names: a, button, input, select, textarea, label |
Use materialized columns for exploration queries whenever possible — they avoid regex parsing.
Canonical autocapture properties
Every $autocapture event from posthog-js ships with a fixed set of properties.
Do not query the schema to "look them up" — they are these:
| Property | Examples | Notes |
|---|---|---|
$event_type |
click, submit, change |
the kind of interaction |
$el_text |
Sign up, Submit |
text of the clicked element |
$current_url |
https://app.example.com/pricing |
page the interaction happened on |
$elements_chain |
semicolon-separated chain | parsed via the elements_chain* materialized columns above |
Standard event properties ($browser, $os, $device_type, etc.) are also present.
Workflow
1. Confirm autocapture data exists
Run a count query before doing anything else. If the count is zero, autocapture may be disabled. There are two ways this happens:
- Project settings — the team can set
autocapture_opt_outin PostHog project settings - SDK config — the posthog-js
init()call can passautocapture: false
Tell the user if no data is found so they can check both settings.
SELECT count() as cnt
FROM events
WHERE event = '$autocapture'
AND timestamp > now() - INTERVAL 7 DAY
2. Explore what users are interacting with
Start broad using the materialized columns. The goal is to understand what users are clicking before narrowing down.
Useful explorations:
- Top clicked tag names (via
elements_chain_elements) - Top clicked text values (via
elements_chain_texts) - Top clicked hrefs (via
elements_chain_href) - Raw
elements_chainvalues for a specific page (filtered byproperties.$current_url)
See example queries for all patterns.
3. Find candidate selectors
Once the user identifies an interaction they care about, find a CSS selector that identifies it.
Priority order for selector attributes (best first):
data-attror otherdata-*attributes — highest specificity, stable across deploys, developer-intended anchors. Search withmatch(elements_chain, 'data-attr=')orextractAll.- Element ID (
attr_id) — also highly stable, queryable viaelements_chain_ids. - Tag + class combination — moderately stable but classes change with CSS refactors.
- Text content — fragile (changes with copy edits, i18n) but sometimes the only option.
- Tag name alone — too broad on its own, useful as a qualifier.
When a
常见问题
自动捕获记录什么?
当网站开启该功能时,它会将点击、表单提交和页面切换记录为自动捕获事件。
什么是元素链?
它是被点击元素及其父元素的记录,本技能会读取它来查找选择器。
为什么本技能要检查选择器是否唯一?
匹配多个元素的选择器,会统计你并不想追踪的点击,因此本技能会先检查每个选择器。
详情
作者的原始描述
Guides exploration of $autocapture events captured by posthog-js to understand user interactions, find CSS selectors (especially data-attr attributes), evaluate selector uniqueness, query matching clicks ad-hoc, and create actions. Use when the user asks about autocapture data, wants to find what users are clicking, needs to build actions from click events, asks about elements_chain, wants to build a trend or funnel filtered by clicks or other autocapture interactions, asks which properties autocapture sends, or asks how to filter $autocapture events. Only applies to projects using posthog-js
repo: PostHog/posthog
热度
- GitHub 星标
- 41k
- 排名
- #6902
- 许可证
- —
- 更新时间
- 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,并以不会让文件臃肿的方式写下,确保规则真正生效。