---
name: analytics-tracking
description: When the user wants to set up, improve, or audit analytics tracking and measurement. Also use when the user mentions "set up tracking," "GA4," "Google Analytics," "conversion tracking," "event tracking," "UTM parameters," "tag manager," "GTM," "analytics implementation," or "tracking plan." For A/B test measurement, see ab-test-setup.
---

# Analytics Tracking

You're helping set up tracking that tells you what's actually happening on your site. I've implemented analytics for hundreds of WordPress sites and SaaS products. Most tracking setups fail because people track everything and measure nothing. You end up with a dashboard full of numbers that don't help you make decisions. Let's fix that.

## Initial Assessment

Before implementing anything, get clear on:

1. **What you actually need to know**
   - What decisions will this data inform?
   - What are your key conversion actions?
   - What questions do you need answered?

2. **What you already have**
   - What tracking exists?
   - What tools are you using (GA4, Mixpanel, Amplitude)?
   - What's working and what isn't?

3. **Technical reality**
   - What's your tech stack?
   - Who's implementing and maintaining this?
   - Any privacy or compliance requirements?

---

## Core Principles I Follow

### 1. Track for decisions, not data collection
- Every event should help you make a decision
- Vanity metrics waste your time
- Quality beats quantity of events

### 2. Start with questions
- What do you need to know?
- What will you do differently based on this data?
- Work backwards to figure out what to track

### 3. Name things consistently
- Naming conventions matter more than you think
- Establish patterns before you start implementing
- Document everything

### 4. Maintain data quality
- Validate your implementation
- Monitor for issues
- Clean data beats more data every time

---

## Tracking Plan Framework

### Basic structure

```
Event Name | Event Category | Properties | Trigger | Notes
---------- | ------------- | ---------- | ------- | -----
```

### Event types you'll track

**Pageviews**
- Automatic in most tools
- Add page metadata for context

**User actions**
- Button clicks
- Form submissions
- Feature usage
- Content interactions

**System events**
- Signup completed
- Purchase completed
- Subscription changed
- Errors occurred

**Custom conversions**
- Goal completions
- Funnel stages
- Business-specific milestones

---

## Event Naming Conventions

### Format options

**Object-Action (what I recommend)**
```
signup_completed
button_clicked
form_submitted
article_read
```

**Action-Object**
```
click_button
submit_form
complete_signup
```

**Category_Object_Action**
```
checkout_payment_completed
blog_article_viewed
onboarding_step_completed
```

### What works

- Lowercase with underscores
- Be specific: `cta_hero_clicked` not `button_clicked`
- Put context in properties, not the event name
- No spaces or special characters
- Document your decisions

---

## Events Worth Tracking

### Marketing site

**Navigation**
- page_view (enhanced with metadata)
- outbound_link_clicked
- scroll_depth (25%, 50%, 75%, 100%)

**Engagement**
- cta_clicked (button_text, location)
- video_played (video_id, duration)
- form_started
- form_submitted (form_type)
- resource_downloaded (resource_name)

**Conversion**
- signup_started
- signup_completed
- demo_requested
- contact_submitted

### Product/App

**Onboarding**
- signup_completed
- onboarding_step_completed (step_number, step_name)
- onboarding_completed
- first_key_action_completed

**Core usage**
- feature_used (feature_name)
- action_completed (action_type)
- session_started
- session_ended

**Monetization**
- trial_started
- pricing_viewed
- checkout_started
- purchase_completed (plan, value)
- subscription_cancelled

### E-commerce (WooCommerce, etc.)

**Browsing**
- product_viewed (product_id, category, price)
- product_list_viewed (list_name, products)
- product_searched (query, results_count)

**Cart**
- product_added_to_cart
- product_removed_from_cart
- cart_viewed

**Checkout**
- checkout_started
- checkout_step_completed (step)
- payment_info_entered
- purchase_completed (order_id, value, products)

---

## Event Properties (Parameters)

### Standard properties to include

**Page/Screen**
- page_title
- page_location (URL)
- page_referrer
- content_group

**User**
- user_id (if logged in)
- user_type (free, paid, admin)
- account_id (for B2B)
- plan_type

**Campaign**
- source
- medium
- campaign
- content
- term

**Product** (e-commerce)
- product_id
- product_name
- category
- price
- quantity
- currency

**Timing**
- timestamp
- session_duration
- time_on_page

### What I've learned

- Use consistent property names everywhere
- Include relevant context
- Don't duplicate GA4's automatic properties
- Never put PII in properties
- Document expected values

---

## GA4 Implementation

### Configuration

**Data Streams**
- One stream per platform (web, iOS, Android)
- Enable enhanced measurement

**Enhanced Measurement (automatic)**
- page_view
- scroll (90% depth)
- outbound_click
- site_search
- video_engagement
- file_download

**Recommended events**
- Use Google's predefined events when possible
- You get better reporting with standard names
- See: https://support.google.com/analytics/answer/9267735

### Custom events

```javascript
// gtag.js
gtag('event', 'signup_completed', {
  'method': 'email',
  'plan': 'free'
});

// Google Tag Manager (dataLayer)
dataLayer.push({
  'event': 'signup_completed',
  'method': 'email',
  'plan': 'free'
});
```

### Setting up conversions

1. Collect the event in GA4
2. Mark as conversion in Admin > Events
3. Set conversion counting (once per session or every time)
4. Import to Google Ads if you're running campaigns

### Custom dimensions and metrics

**When you need them:**
- Properties you want to segment by
- Metrics you want to aggregate
- Anything beyond standard parameters

**How to set up:**
1. Create in Admin > Custom definitions
2. Pick scope: Event, User, or Item
3. Parameter name must match exactly

---

## Google Tag Manager Implementation

### Container structure

**Tags**
- GA4 Configuration (base)
- GA4 Event tags (one per event or grouped)
- Conversion pixels (Facebook, LinkedIn, etc.)

**Triggers**
- Page View (DOM Ready, Window Loaded)
- Click - All Elements / Just Links
- Form Submission
- Custom Events

**Variables**
- Built-in: Click Text, Click URL, Page Path, etc.
- Data Layer variables
- JavaScript variables
- Lookup tables

### What works

- Use folders to organize
- Consistent naming (Tag_Type_Description)
- Version notes on every publish
- Preview mode before publishing
- Workspaces for team collaboration

### Data layer pattern

```javascript
// Push custom event
dataLayer.push({
  'event': 'form_submitted',
  'form_name': 'contact',
  'form_location': 'footer'
});

// Set user properties
dataLayer.push({
  'user_id': '12345',
  'user_type': 'premium'
});

// E-commerce event
dataLayer.push({
  'event': 'purchase',
  'ecommerce': {
    'transaction_id': 'T12345',
    'value': 99.99,
    'currency': 'USD',
    'items': [{
      'item_id': 'SKU123',
      'item_name': 'Product Name',
      'price': 99.99
    }]
  }
});
```

---

## UTM Parameter Strategy

### Standard parameters

| Parameter | Purpose | Example |
|-----------|---------|---------|
| utm_source | Where traffic comes from | google, facebook, newsletter |
| utm_medium | Marketing medium | cpc, email, social, referral |
| utm_campaign | Campaign name | spring_sale, product_launch |
| utm_content | Differentiate versions | hero_cta, sidebar_link |
| utm_term | Paid search keywords | running+shoes |

### Naming conventions that work

**Lowercase everything**
- google, not Google
- email, not Email

**Use underscores or hyphens consistently**
- product_launch or product-launch
- Pick one and stick with it

**Be specific but concise**
- blog_footer_cta, not cta1
- 2024_q1_promo, not promo

### Track your UTMs

Keep a spreadsheet or use a tool:

| Campaign | Source | Medium | Content | Full URL | Owner | Date |
|----------|--------|--------|---------|----------|-------|------|
| ... | ... | ... | ... | ... | ... | ... |

---

## Debugging and Validation

### Testing tools I use

**GA4 DebugView**
- Real-time event monitoring
- Enable with ?debug_mode=true
- Or use the Chrome extension

**GTM Preview Mode**
- Test triggers and tags
- See data layer state
- Validate before you publish

**Browser extensions**
- GA Debugger
- Tag Assistant
- dataLayer Inspector

### Validation checklist

- [ ] Events firing on correct triggers
- [ ] Property values populating correctly
- [ ] No duplicate events
- [ ] Works across browsers
- [ ] Works on mobile
- [ ] Conversions recorded correctly
- [ ] User ID passing when logged in
- [ ] No PII leaking

### Common issues I see

**Events not firing**
- Trigger misconfigured
- Tag paused
- GTM not loading on page

**Wrong values**
- Variable not configured
- Data layer not pushing correctly
- Timing issues (tag fires before data ready)

**Duplicate events**
- Multiple GTM containers
- Multiple tag instances
- Trigger firing multiple times

---

## Privacy and Compliance

### What to consider

- Cookie consent required in EU/UK/CA
- No PII in analytics properties
- Data retention settings
- User deletion capabilities
- Cross-device tracking consent

### Implementation

**Consent Mode (GA4)**
- Wait for consent before tracking
- Use consent mode for partial tracking
- Integrate with your consent management platform

**Data minimization**
- Only collect what you actually need
- IP anonymization
- No PII in custom dimensions

---

## Output Format

### Tracking plan document

```
# [Site/Product] Tracking Plan

## Overview
- Tools: GA4, GTM
- Last updated: [Date]
- Owner: [Name]

## Events

### Marketing Events

| Event Name | Description | Properties | Trigger |
|------------|-------------|------------|---------|
| signup_started | User initiates signup | source, page | Click signup CTA |
| signup_completed | User completes signup | method, plan | Signup success page |

### Product Events
[Similar table]

## Custom Dimensions

| Name | Scope | Parameter | Description |
|------|-------|-----------|-------------|
| user_type | User | user_type | Free, trial, paid |

## Conversions

| Conversion | Event | Counting | Google Ads |
|------------|-------|----------|------------|
| Signup | signup_completed | Once per session | Yes |

## UTM Convention

[Your guidelines]
```

### Implementation code

Provide ready-to-use code snippets

### Testing checklist

Specific validation steps for this implementation

---

## Questions I'll Ask

If I need more context:
1. What tools are you using (GA4, Mixpanel, etc.)?
2. What key actions do you want to track?
3. What decisions will this data inform?
4. Who implements - dev team or marketing?
5. Are there privacy/consent requirements?
6. What's already tracked?

---

## Related Skills

- **ab-test-setup**: For experiment tracking
- **seo-audit**: For organic traffic analysis
- **page-cro**: For conversion optimization (uses this data)
