Skip to content

feat: track registry installs and copy events#76

Merged
starc007 merged 1 commit into
mainfrom
feat/analytics-tracking
Jun 28, 2026
Merged

feat: track registry installs and copy events#76
starc007 merged 1 commit into
mainfrom
feat/analytics-tracking

Conversation

@starc007

Copy link
Copy Markdown
Owner

What

GA4 analytics for two actions: copy-to-clipboard and registry installs.

Copy events (client-side)

  • lib/analytics.tstrackEvent() helper + gtag window types. No-ops when GA absent (id unset, ad-blocker, SSR), so callers never guard.
  • CopyButton fires a labeled GA4 event with char count.
  • Wired:
    • install command → copy_install_command (label = slug)
    • code blocks → copy_code (label = filename/lang)
    • playground → copy_playground

Registry 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 is force-static (no per-request handler).

  • middleware.ts runs on /r/*, tags .json item fetches, and reports them to GA4 via the Measurement Protocol (server-side) using event.waitUntil so install latency is unaffected. Route stays on the CDN.
  • is_cli param flags node/bun/shadcn UAs to segment installs from browser/bot noise.
  • Stable 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 typecheck clean
  • bun run lint clean (one pre-existing warning in install-command.tsx, unrelated)

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
@starc007 starc007 merged commit c23df29 into main Jun 28, 2026
2 checks passed
@starc007 starc007 deleted the feat/analytics-tracking branch June 28, 2026 16:17
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.

1 participant