feat: track registry installs and copy events#76
Merged
Conversation
Add GA4 analytics for copy-to-clipboard actions and registry installs.
- lib/analytics.ts: trackEvent helper with gtag types, no-ops when GA absent
- CopyButton fires labeled GA4 events; wired through install command, code
blocks and playground
- middleware.ts: reports registry installs (headless shadcn CLI fetch of
/r/{slug}.json) to GA4 via Measurement Protocol, keeping the route static
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.
What
GA4 analytics for two actions: copy-to-clipboard and registry installs.
Copy events (client-side)
lib/analytics.ts—trackEvent()helper +gtagwindow types. No-ops when GA absent (id unset, ad-blocker, SSR), so callers never guard.CopyButtonfires a labeled GA4 event with char count.copy_install_command(label = slug)copy_code(label = filename/lang)copy_playgroundRegistry installs (server-side)
The real install is
npx shadcn add @beui/x, which is a headless CLI fetch of/r/{slug}.json— no browser, no gtag, and the route isforce-static(no per-request handler).middleware.tsruns on/r/*, tags.jsonitem fetches, and reports them to GA4 via the Measurement Protocol (server-side) usingevent.waitUntilso install latency is unaffected. Route stays on the CDN.is_cliparam flags node/bun/shadcn UAs to segment installs from browser/bot noise.client_id= SHA-256(ip + ua); no cookie, no storage.Setup
Requires env var
GA_API_SECRET(GA4 → Data Streams → Measurement Protocol API secrets). Already added to prod. Without it the middleware no-ops safely.Events in GA4
Reports → Engagement → Events:
registry_install,copy_install_command,copy_code,copy_playground.Verification
bun run typecheckcleanbun run lintclean (one pre-existing warning ininstall-command.tsx, unrelated)