Skip to content

feat: Tag copy buttons with data attributes for PostHog autocapture - #875

Merged
Isakdl merged 1 commit into
mainfrom
docs/copy-button-data-attributes
Oct 6, 2026
Merged

Isakdl merged 1 commit into
mainfrom
docs/copy-button-data-attributes

Conversation

@Isakdl

@Isakdl Isakdl commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

PostHog is loaded on the docs through Google Tag Manager with autocapture on, so copy-button clicks already reach PostHog as $autocapture events. Until now they could only be identified by the generic aria-label ("Copy code to clipboard"), with no way to tell which block was copied.

This adds data-* attributes, which autocapture records on every click:

Button Attributes
Code block copy data-attr="copy-code", data-block-title, data-language
Copy as Markdown data-attr="copy-page-markdown", data-docs-instance, data-docs-version

data-attr is the project's configured PostHog data attribute, so the toolbar, heatmaps, and actions use it to identify the element. The page is already on every autocapture event as $pathname.

The aria-label text and the GA copy_code_block / copy_page_markdown events are unchanged. data-block-title is only set on blocks that have a title, for example the agent setup prompt on the installation page.

Checked on the dev server: all five code-block copy buttons on /installation and the Copy as Markdown button render the attributes with the expected values.

🤖 Generated with Claude Code

Code block copy buttons get data-attr="copy-code" plus data-block-title
and data-language. The Copy as Markdown button gets
data-attr="copy-page-markdown" plus data-docs-instance and
data-docs-version. PostHog autocapture records these on every click, so
copies can be filtered per block and per page without custom events.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@Isakdl
Isakdl requested a review from SandPod October 6, 2026 16:07

@SandPod SandPod left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Isakdl
Isakdl merged commit f85b264 into main Oct 6, 2026
5 checks passed
@Isakdl
Isakdl deleted the docs/copy-button-data-attributes branch October 6, 2026 16:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants