
exploring-autocapture-events
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 elementschain, 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 autocapture.
- Installs
- 229
- Last 24h
- —
- Trending rank
- —
- Security
- Not audited
Install
Works with every agent the skills CLI supports.
npx skills add https://github.com/posthog/ai-plugin --skill exploring-autocapture-events- 01
Install
Run the command in your project. The CLI asks which agents to install for.
- 02
Describe the task
Ask your agent for something this skill covers. It loads exploring-autocapture-events automatically when relevant.
- 03
Review the result
The agent follows the SKILL.md steps, scripts and references bundled with the skill.
SKILL.md
The instructions your agent reads when the skill is triggered.
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 data-attr value is found, construct a selector like [data-attr="value"] or button[data-attr="value"].
4. Evaluate selector uniqueness
A selector is only useful if it matches the intended interaction and not unrelated events.
Run a uniqueness check using elements_chain =~ with the regex pattern for the selector.
Then sample matching events to inspect what the selector actually captures.
Compare the count against total autocapture volume to understand selectivity.
A good selector matches a single logical interaction. If it matches too many distinct elements, refine it in the next step.
5. Refine with additional filters
If the selector alone is not unique enough, layer on additional filters:
- Text filter — match by element text content using
elements_chain_texts - URL filter — restrict to a specific page using
properties.$current_url - Href filter — match by link target using
elements_chain_href
Re-run the uniqueness check after each refinement. Only include filters that are needed — fewer filters means more resilience to minor DOM changes.
6. Filter autocapture inside an insight query
When the user wants a funnel, trend, or other insight, the filter shape is different from HogQL.
Each step in a FunnelsQuery / TrendsQuery is an EventsNode (or ActionsNode) with event: "$autocapture" and a properties array.
Two distinct property type values matter — they are not interchangeable:
type: "element"— keys:selector,tag_name,text,href. Matched against the parsedelements_chain. Operator support is split:selectorandtag_nameonly supportexactandis_not— any other operator is rejected by the query engine and the query errors.textandhrefaccept the full string operator set (exact,is_not,icontains,not_icontains,regex,not_regex,is_set,is_not_set).
type: "event"— keys: any of the canonical autocapture properties ($event_type,$el_text,$current_url) or anything else on the event. Standard event-property operators (exact,icontains,regex, etc.).
Example funnel from clicking one button to clicking another:
{
"kind": "FunnelsQuery",
"series": [
{
"kind": "EventsNode",
"event": "$autocapture",
"properties": [
{
"type": "element",
"key": "selector",
"value": ["[data-attr=\"autocapture-series-save-as-action-banner-shown\"]"],
"operator": "exact"
}
]
},
{
"kind": "EventsNode",
"event": "$autocapture",
"properties": [
{
"type": "element",
"key": "selector",
"value": ["[data-attr=\"autocapture-save-as-action\"]"],
"operator": "exact"
}
]
}
]
}
Two things easy to get wrong:
valueis an array even when matching a single selector- The selector string includes the
[data-attr="..."]wrapper — it is a CSS selector, not a bare attribute value
Decision rule: prefer an action (ActionsNode referencing an existing action — see Step 8) when the interaction will be referenced more than once; inline type: "element" / type: "event" filters when it's a one-off insight; raw HogQL (Step 7) when joining across events or doing custom aggregations.
7. Use in ad-hoc queries
The discovered selector can be used directly in HogQL without creating an action.
Trends — count matching clicks over time:
SELECT
toStartOfDay(timestamp) as day,
count() as clicks
FROM events
WHERE event = '$autocapture'
AND timestamp > now() - INTERVAL 14 DAY
AND elements_chain =~ '(^|;)button.*?data-attr="checkout"'
GROUP BY day
ORDER BY day
Funnel — pageview to click conversion:
SELECT
person_id,
first_pageview,
first_click_after
FROM (
SELECT
p.person_id,
p.pageview_time as first_pageview,
min(c.click_time) as first_click_after
FROM (
SELECT person_id, min(timestamp) as pageview_time
FROM events
WHERE event = '$pageview'
AND timestamp > now() - INTERVAL 14 DAY
AND properties.$current_url ILIKE '%/pricing%'
GROUP BY person_id
) p
INNER JOIN (
SELECT person_id, timestamp as click_time
FROM events
WHERE event = '$autocapture'
AND timestamp > now() - INTERVAL 14 DAY
AND elements_chain =~ '(^|;)button.*?data-attr="signup"'
) c ON p.person_id = c.person_id AND c.click_time > p.pageview_time
GROUP BY p.person_id, p.pageview_time
)
For recurring analysis, prefer creating an action (next step) or using posthog:query-trends / posthog:query-funnel with the action.
8. Create an action
Actions are the durable version of ad-hoc selector queries.
Once the criteria uniquely identify the interaction, create an action using posthog:action-create.
Construct the step with only the filters needed for uniqueness:
{
"name": "Clicked checkout button",
"steps": [
{
"event": "$autocapture",
"selector": "button[data-attr='checkout']",
"text": "Complete Purchase",
"text_matching": "exact",
"url": "/checkout",
"url_matching": "contains"
}
]
}
Available step fields for $autocapture:
selector— CSS selector (e.g.button[data-attr='checkout'])tag_name— HTML tag name (e.g.button,a,input)text/text_matching— element text (exact,contains, orregex)href/href_matching— link href (exact,contains, orregex)url/url_matching— page URL (exact,contains, orregex)
After creation, verify with matchesAction():
SELECT count() as matching_events
FROM events
WHERE matchesAction('Clicked checkout button')
AND timestamp > now() - INTERVAL 7 DAY
Tips
- Always set timestamp filters —
$autocaptureis high volume - Use
LIMITgenerously when samplingelements_chain— the strings can be long - The
elements_chain =~operator matches CSS selectors as regex internally; prefer materialized columns when possible for performance - This workflow only applies to posthog-js — other SDKs do not capture elements
FAQ
What does the exploring-autocapture-events skill do?
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 elementschain, 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 autocapture.
How do I install exploring-autocapture-events?
Run npx skills add https://github.com/posthog/ai-plugin --skill exploring-autocapture-events in your project. The skills CLI detects the agents you use and copies the skill into the right folder. For Claude Code you can also place the skill folder at ~/.claude/skills/exploring-autocapture-events/ (personal) or .claude/skills/exploring-autocapture-events/ (project).
Which AI agents can use exploring-autocapture-events?
Any agent that supports the open Agent Skills format (a folder with a SKILL.md file), including Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, Windsurf, Cline, OpenCode and more.
Is exploring-autocapture-events safe to install?
No partner security audit is available yet. Skills can run commands and scripts, so read the SKILL.md and any bundled files before installing.
Who maintains exploring-autocapture-events?
It is published by posthog in posthog/ai-plugin, and it is an official skill from the maker of the technology it covers. It has 229 recorded installs.
More from posthog/ai-plugin
instrument-product-analytics
posthog/ai-plugin
Add PostHog product analytics events to track user behavior. Use after implementing new features or reviewing PRs to ensure meaningful user actions are captured. Also handles initial PostHog SDK setup if not yet installed.
instrument-feature-flags
posthog/ai-plugin
Add PostHog feature flags to gate new functionality. Use after implementing features or reviewing PRs to ensure safe rollouts with feature flag controls. Also handles initial PostHog SDK setup if not yet installed.
cleaning-up-stale-feature-flags
posthog/ai-plugin
Identify stale feature flags in a PostHog project and clean up the code that checks them. Use when the user wants to find, audit, or remove unused, fully rolled out, or abandoned feature flags, run a feature flag hygiene review or a weekly cleanup, reduce feature flag tech debt, or asks "which flags can I remove?". When the agent can read and edit a repository it performs the code cleanup itself: tested local changes, and one draft PR per flag when the user authorizes publishing. Agents without repository access generate a tailored cleanup prompt instead. Covers staleness detection, dependency checking, retained-path rules, and the code-first ordering. This skill does not archive or otherwise change a flag in PostHog.
auditing-experiments-flags
posthog/ai-plugin
Audit PostHog experiments and feature flags for configuration issues, staleness, and best-practice violations. Read when the user asks to audit, health-check, or review experiments or feature flags, check flag hygiene, or verify experiment setup.
querying-posthog-data
posthog/ai-plugin
Explains how to query PostHog data, defaulting to typed runners for supported product analytics. Read it before you write HogQL/SQL. Also read it before you call execute-sql against PostHog. Use it to find or aggregate PostHog entities. These entities include insights, dashboards, cohorts, feature flags, experiments, surveys, hog flows, warehouse data, and persons. Use it for trends, funnels, retention, lifecycle, paths, stickiness, web analytics, error tracking, logs, sessions, and LLM traces. Before you calculate a governed business or telemetry measure, check system.informationschema.metrics for an approved definition. Examples include MRR, activation, billable usage, active organizations, and failure rates. Use the approved definition before you derive a measure from raw events or use a typed domain tool. It also covers HogQL differences, system table schemas, functions, query examples, and schema discovery.
creating-experiments
posthog/ai-plugin
Guides agents through experiment creation: reading the project's setup with experiment-setup-context, defining the hypothesis, configuring rollout and bucketing, setting up analytics and running time, and reporting which choices are guesses. Delegates rollout decisions to configuring-experiment-rollout and metric setup to configuring-experiment-analytics. TRIGGER when: user asks to create a new experiment or A/B test, OR when you are about to call experiment-create. DO NOT TRIGGER when: user is updating an existing experiment, managing lifecycle, or only browsing experiments.
Popular frontend & design skills
setup-matt-pocock-skills
mattpocock/skills
Configure this repo for the engineering skills: set up its issue tracker, triage label vocabulary, and domain doc layout. Run once before first use of the other engineering skills.
frontend-design
anthropics/skills
Guidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.
hyperframes-animation
heygen-com/hyperframes
All animation knowledge for HyperFrames — atomic motion rules, multi-phase scene blueprints, scene transitions, broader motion-design techniques, AND the seven runtime adapters (GSAP default, plus Lottie, Three.js, Anime.js, CSS keyframes, Web Animations API, TypeGPU). Use for any motion or animation task: pick 2-4 rules and compose, or load a blueprint, or look up runtime-specific API (e.g. GSAP eases / Lottie player / Three.js mixer). Also covers auditing an existing composition's choreography (animation map) and 24 named text-animation effects. HyperFrames-native: single paused timeline, seek-safe, deterministic.
prototype
mattpocock/skills
Build a throwaway prototype to answer a design question. Use when the user wants to sanity-check whether a state model or logic feels right, or explore what a UI should look like.
hyperframes-core
heygen-com/hyperframes
The HyperFrames composition contract — build one renderable project. Use for composition structure, the data- timing attributes, class="clip", tracks, sub-compositions, variables, framework-owned media playback, deterministic-render rules, and validation. Read before writing composition HTML.
vercel-react-best-practices
vercel-labs/agent-skills
React and Next.js performance optimization guidelines from Vercel Engineering. This skill should be used when writing, reviewing, or refactoring React/Next.js code to ensure optimal performance patterns. Triggers on tasks involving React components, Next.js pages, data fetching, bundle optimization, or performance improvements.