Repository navigation
feat: Tag copy buttons with data attributes for PostHog autocapture - #875
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PostHog is loaded on the docs through Google Tag Manager with autocapture on, so copy-button clicks already reach PostHog as
$autocaptureevents. Until now they could only be identified by the genericaria-label("Copy code to clipboard"), with no way to tell which block was copied.This adds
data-*attributes, which autocapture records on every click:data-attr="copy-code",data-block-title,data-languagedata-attr="copy-page-markdown",data-docs-instance,data-docs-versiondata-attris 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-labeltext and the GAcopy_code_block/copy_page_markdownevents are unchanged.data-block-titleis only set on blocks that have atitle, for example the agent setup prompt on the installation page.Checked on the dev server: all five code-block copy buttons on
/installationand the Copy as Markdown button render the attributes with the expected values.🤖 Generated with Claude Code