Analytics Tracking
Set up, audit, and debug analytics tracking with GA4 and GTM.
$skillfish add ~skills/analytics-tracking Real Conversations
See how the Analytics Tracking skill responds to actual requests. These are representative examples of what your AI agent will produce.
We need to track our full trial signup funnel in GA4: landing page visit → pricing page → signup form start → email entered → credit card → trial activated. We use GTM. Walk me through the full setup.
GA4 Funnel Tracking Setup via GTM
Step 1: Define GA4 events (create these in GTM)
Event 1: pricing_page_view
Trigger: Page URL equals /pricing
Parameters: page_referrer, traffic_source
Event 2: signup_form_start
Trigger: Focus on #email-field (CSS selector)
Parameters: form_id, page_location
Event 3: signup_email_entered
Trigger: Click on 'Continue' button after email field
Parameters: form_id
Event 4: signup_payment_started
Trigger: Page URL contains /signup/payment
Parameters: plan_selected, billing_period
Event 5: trial_activated (server-side recommended)
Send via Measurement Protocol from your backend on successful account creation
Parameters: plan_name, user_id, trial_end_date
Step 2: GTM Tag config for each event
- Tag type: Google Analytics: GA4 Event
- Measurement ID: G-XXXXXXXXXX
- Event name: exactly as above (snake_case)
- Add user_id parameter on events 3–5 if user is identified
Step 3: Build funnel in GA4
- Explore > Funnel Exploration
- Add steps in order, set as closed funnel
- Enable "show elapsed time" between steps
Step 4: Validate in DebugView
- GTM Preview mode → complete each step → confirm events appear in GA4 DebugView in real time
- Check parameters are populated (not undefined)
Common mistakes: Firing signup events on page load instead of user action, missing credit card step because it's in an iframe (requires postMessage listener).
Get Started
How to install and use this skill in your preferred environment.
Skills are designed for AI coding agents (Claude Code, Cursor, Windsurf) and IDE-based workflows where the agent can read files, run scripts, and act on your codebase. Web-based AI can use the knowledge and frameworks, but won't have tool access.
Models & Context
Which AI models and context windows work best with this skill.
Recommended Models
Larger models produce more detailed, production-ready outputs.
Context Window
This skill's SKILL.md is typically 3–10 KB — fits in any modern context window.
All current frontier models (Claude, GPT, Gemini) support 100K+ context. Use the full window for complex multi-service work.
Pro tips for best results
Be specific
Include numbers — users, budget, RPS — so the skill can size the architecture.
Share constraints
Compliance needs, team size, and existing stack all improve the output.
Iterate
Start with a high-level design, then ask follow-ups for IaC, cost analysis, or security review.
Combine skills
Pair with companion skills below for end-to-end coverage.
Good to Know
Advanced guide and reference material for Analytics Tracking. Background, edge cases, and patterns worth understanding.
Contents
GA4 Event Model vs Universal Analytics
Universal Analytics was session-based: every hit existed within a session container, and the session was the primary unit of measurement. GA4 is event-based: every interaction — page view, scroll, click, transaction — is a flat event with parameters. There is no implicit session hierarchy; sessions are reconstructed from events using a 30-minute inactivity timeout.
Three event tiers in GA4:
| Tier | Examples | Configuration required |
|---|---|---|
| Automatically collected | page_view, session_start, first_visit |
None — fires by default |
| Enhanced Measurement | scroll, outbound_click, video_start, file_download, form_interaction |
Toggle on in Data Stream settings |
| Custom events | Anything your business needs | GTM tag or gtag.js call |
The Enhanced Measurement events are convenient but imprecise — form_interaction fires on any form interaction, not just successful submissions. For funnel-critical events, replace Enhanced Measurement with explicit custom events so you control the trigger condition.
Event Naming Conventions
GA4 enforces character limits and reserves certain names. Violating these results in events being silently dropped or misrouted.
- Format: snake_case only — no spaces, camelCase, or hyphens
- Pattern:
verb_noun—form_submit,video_play,trial_start,plan_upgrade - Length: Event name max 40 characters; parameter names max 40 characters; parameter values max 100 characters
- Reserved names to avoid:
app_remove,error,first_open,first_visit,in_app_purchase,notification_dismiss,notification_foreground,notification_open,notification_receive,os_update,screen_view,session_start,user_engagement
Create a naming convention doc before instrumentation. Inconsistent names (e.g., form_submit vs form_submitted) create parallel event streams that inflate counts and break funnel reports.
PII and Privacy Compliance
GA4 stores data on Google's servers; sending PII through it creates GDPR and CCPA exposure.
What counts as PII in GA4 context: Email addresses, full names, phone numbers, government IDs, precise location data, IP addresses (GA4 does not log these by default since 2022).
User-ID implementation: GA4 supports pseudonymous User-ID tracking. Hash user identifiers (SHA-256 minimum) before sending — never send raw email or database IDs. Set via gtag('config', 'G-XXXX', { user_id: hashedId }).
GDPR Consent Mode v2:
| Mode | Behavior when consent denied | Use case |
|---|---|---|
| Basic | No tags fire; no data collected | Strictest compliance requirement |
| Advanced | Tags fire but use cookieless pings; Google models gaps using aggregated data | Balances measurement with compliance |
Consent Mode v2 (required for EU since March 2024) adds ad_user_data and ad_personalization signals alongside the existing analytics_storage and ad_storage. Implement via GTM Consent Initialization trigger or a certified CMP.
Cookie-less measurement limitation: Modeled conversions and Consent Mode advanced mode fill gaps statistically — reported conversion counts may be 15–30% higher than raw observed conversions. Do not treat modeled data as ground truth for budget decisions.
Cross-Domain and Cross-Device Tracking
Cross-domain: GA4 appends a _gl linker parameter to outbound links when cross-domain measurement is enabled. Configure in Admin > Data Streams > Configure tag settings > Configure your domains. Without this, sessions break at domain boundaries and source attribution resets.
User-ID stitching: When a user authenticates, send the same hashed User-ID on all platforms (web, app, server). GA4 stitches these into a unified user journey. Coverage is limited to logged-in sessions — typically 20–40% of traffic for most SaaS products.
Probabilistic matching: GA4 uses device signals to probabilistically stitch anonymous sessions across devices. This is Google's modeling, not deterministic data. Do not report it as fact; use it for directional trend analysis only.
Server-Side Tagging
Server-side tagging routes event data through a GTM server container (hosted on your infrastructure or Google Cloud Run) before forwarding to GA4 and other destinations.
When to use it: Ad blockers, ITP (Safari's Intelligent Tracking Prevention), and browser privacy restrictions block client-side tags at rates of 15–40% depending on audience. Server-side tagging bypasses client-side blocking for events already captured by your server.
Setup basics: Deploy a GTM server container, update client-side GTM to send to your server endpoint instead of directly to GA4, configure forwarding clients per destination.
First-party data benefits: Server-side tags fire under your domain's cookies, making them first-party — increasing cookie lifetime and reducing ITP restrictions.
Latency trade-off: Server-side tagging adds 50–200ms to the tagging pipeline. For real-time bidding signals and conversion APIs, this is acceptable; for UX-critical events it may not be.
Ready to try Analytics Tracking?
Install the skill and start getting expert-level guidance in your workflow — any agent, any IDE.
$skillfish add ~skills/analytics-tracking