A Claude Code skill that audits, installs, and fixes Google Analytics 4 tracking on a website — so the data actually tells you what to change.
Most GA4 installs measure page views and nothing else. You end up knowing how many people visited, but not which button they clicked, which form they abandoned, or whether they called instead. This skill installs the event layer that answers those questions, and refuses to ship the things that quietly poison a property: duplicate events, PII in parameters, and dev traffic in production reports.
git clone https://github.com/RamzanReshi/forge-analytics.git ~/.claude/skills/forge-analyticsThen in Claude Code:
/forge-analytics
Or just describe the task — "audit my analytics", "set up GA4 with G-XXXXXXXXXX", "am I tracking the right things" — and it triggers on its own.
| Mode | When | Output |
|---|---|---|
| Audit | "check my analytics", no tag given | Report card, plain English. No code changes. |
| Install / Fix | "set up GA4", tag given, or audit found gaps | Helper file, wired events, ANALYTICS.md |
| Verify | "are events firing" | Live data check, conversion grading |
Unclear requests default to Audit — it is read-only and tells the other modes what to do.
Conversions (you mark these as key events in GA4): generate_lead · phone_click · whatsapp_click · email_click · booking_click
Engagement: cta_click · form_start · form_error · section_view · scroll_depth · nav_click · outbound_click · menu_toggle · video_play · faq_open · file_download
Names are static snake_case and identical across projects, so one GA4 report layout works for every site you build. Variation lives in parameters — button_text, section_name, form_name, location, link_domain, cta_variant — never in the event name, which would fragment reports into hundreds of useless rows.
The goal is being able to answer five questions:
- Which page or section produces the most contacts?
- Which CTA copy and placement converts best?
- How many start the form vs finish it, and which field loses them?
- Which contact channel do people actually prefer?
- Where do visitors stop reading?
No PII, ever. No emails, phone numbers, names, addresses, or message bodies. The helper scrubs email- and phone-shaped parameter values as a backstop even if a call site gets it wrong. Tracks that a form was submitted, never its contents. This is a GA4 ToS violation and a property-deletion risk, not a style preference.
Production only. Gating is a hostname allowlist, not a preview-URL blocklist — an unknown host never sends data. Disabled on localhost, private LAN ranges, *.local, preview deploys, dev builds, and test runners. A blocklist always falls behind new preview URL patterns; an allowlist fails safe.
No duplicate events. Structural guards, not hope: once-only keys for form starts, section views, and scroll thresholds; unobserve after firing; capture-phase delegation that does not double-count clicks already tracked by a component's own onClick.
No fake page views. On single-page anchor-scroll sites there are no route changes, and firing page_view on anchor scroll inflates sessions and destroys bounce-rate meaning. The skill detects this and uses section_view instead. On real routers it sets send_page_view: false and fires manually, so the initial view is not double-counted.
Two things live in the GA4 UI and cannot be set from code. The skill outputs both as a checklist:
- Mark the conversion events as key events. Unmarked, they never appear in conversion reports and cannot be imported into Google Ads.
- Register the custom dimensions. Unregistered parameters are collected correctly but never appear in reports — the most common reason a technically correct install still produces useless data.
SKILL.md mode routing, workflow, hard rules
references/event-taxonomy.md events, parameters, what each answers
references/implementation.md gating, route changes, dedupe, testing
references/reporting.md plain-English summary format
scripts/audit_analytics.py codebase scanner (stdlib only, no deps)
templates/analytics.ts helper starter, typechecks under strict
templates/ANALYTICS.md per-project documentation template
The scanner detects measurement IDs, existing events, competing vendors (GTM, Plausible, PostHog, Meta Pixel, and others), every tel:/wa.me/mailto:/booking/form surface worth tracking, and reliability flags: PII risk, dynamic event names, query strings in page_path, missing production gating, duplicate gtag snippets, legacy Universal Analytics.
The scanner and the helper template are tested: the scanner runs clean against real production sites and correctly flagged two genuine bugs on the first site it was pointed at, and the template typechecks under strict with 26 unit cases passing on the gating and PII-scrub logic.
A full Install-mode run start-to-finish, with events confirmed landing in GA4 Realtime, has not been done yet. Treat the timing estimates as estimates.
MIT