ga4-implementation.md
304 lines · skills/analytics/references/ga4-implementation.md at 88c79f6
Contents
- Configuration (data streams, enhanced measurement events, recommended events)
- Custom Events (gtag.js implementation, Google Tag Manager)
- Conversions Setup (creating conversions, conversion values)
- Custom Dimensions and Metrics (when to use, setup steps, examples)
- Audiences (creating audiences, audience examples)
- Debugging (DebugView, real-time reports, common issues)
- Data Quality (filters, cross-domain tracking, session settings)
- Integration with Google Ads (linking, audience export)
Configuration
Raw lines 15 to 16Data Streams
- One stream per platform (web, iOS, Android)
- Enable enhanced measurement for automatic tracking
- Configure data retention (2 months default, 14 months max)
- Enable Google Signals (for cross-device, if consented)
Enhanced Measurement Events (Automatic)
| Event | Description | Configuration |
|---|---|---|
| page_view | Page loads | Automatic |
| scroll | 90% scroll depth | Toggle on/off |
| click | Outbound link click (outbound: true); cross-domain measurement domains are excluded | Toggle on/off |
| view_search_results | Search results page with a configured search query parameter | Configure query parameters |
| video_start, video_progress, video_complete | Embedded YouTube start, progress and completion | Toggle on/off; JS API support required |
| file_download | PDF, docs, etc. | Configurable extensions |
Use these exact names in event filters and triggers. The option labels "outbound clicks", "site search" and "video engagement" are not automatic event names. For video, report starts, progress milestones and completions separately; adding all three counts double-counts a viewing journey. A custom event with one of the old labels needs its own implementation. Verify enabled options and observed parameters in DebugView before expecting data.
Contract: Google enhanced measurement events.
Raw lines 24 to 38Recommended Events
Use Google's predefined events when possible for enhanced reporting:
All properties:
- login, sign_up
- share
- search
E-commerce:
- view_item, view_item_list
- add_to_cart, remove_from_cart
- begin_checkout
- add_payment_info
- purchase, refund
Games:
- level_up, unlock_achievement
- post_score, spend_virtual_currency
Reference: https://support.google.com/analytics/answer/9267735
Raw lines 39 to 62
Custom Events
Raw lines 63 to 64gtag.js Implementation
// Recommended event (your plan's signup_completed maps to GA4's sign_up)
gtag('event', 'sign_up', {
'method': 'email',
'plan': 'free'
});
// Event with value
gtag('event', 'purchase', {
'transaction_id': 'T12345',
'value': 99.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'item_name': 'Product Name',
'price': 99.99
}]
});
// User properties
gtag('set', 'user_properties', {
'user_type': 'premium',
'plan_name': 'pro'
});
// User ID (for logged-in users)
gtag('config', 'GA_MEASUREMENT_ID', {
'user_id': 'USER_ID'
});Raw lines 65 to 97Google Tag Manager (dataLayer)
// Internal event name; a GTM GA4 Event tag sends it to GA4 as sign_up
dataLayer.push({
'event': 'signup_completed',
'method': 'email',
'plan': 'free'
});
// Set user properties
dataLayer.push({
'user_id': '12345',
'user_type': 'premium'
});
// E-commerce purchase
dataLayer.push({
'event': 'purchase',
'ecommerce': {
'transaction_id': 'T12345',
'value': 99.99,
'currency': 'USD',
'items': [{
'item_id': 'SKU123',
'item_name': 'Product Name',
'price': 99.99,
'quantity': 1
}]
}
});
// Clear ecommerce before sending (best practice)
dataLayer.push({ ecommerce: null });
dataLayer.push({
'event': 'view_item',
'ecommerce': {
// ...
}
});Raw lines 98 to 141
Conversions Setup
Raw lines 142 to 143Creating Conversions
- Collect the event - Ensure event is firing in GA4
- Mark as conversion - Admin > Events > Mark as conversion
- Set counting method:
- Once per session (leads, signups)
- Every event (purchases)
- Import to Google Ads - For conversion-optimized bidding
Conversion Values
// Event with conversion value
gtag('event', 'purchase', {
'value': 99.99,
'currency': 'USD'
});Or set default value in GA4 Admin when marking conversion.
Raw lines 153 to 166
Custom Dimensions and Metrics
Raw lines 167 to 168When to Use
Custom dimensions:
- Properties you want to segment/filter by
- User attributes (plan type, industry)
- Content attributes (author, category)
Custom metrics:
- Numeric values to aggregate
- Scores, counts, durations
Setup Steps
- Admin > Data display > Custom definitions
- Create dimension or metric
- Choose scope:
- Event: Per event (content_type)
- User: Per user (account_type)
- Item: Per product (product_category)
- Enter parameter name (must match event parameter)
Examples
| Dimension | Scope | Parameter | Description |
|---|---|---|---|
| User Type | User | user_type | Free, trial, paid |
| Content Author | Event | author | Blog post author |
| Product Category | Item | item_category | E-commerce category |
Raw lines 190 to 199
Audiences
Raw lines 200 to 201Creating Audiences
Admin > Data display > Audiences
Use cases:
- Remarketing audiences (export to Ads)
- Segment analysis
- Trigger-based events
Audience Examples
High-intent visitors:
- Viewed pricing page
- Did not convert
- In last 7 days
Engaged users:
- 3+ sessions
- Or 5+ minutes total engagement
Purchasers:
- Purchase event
- For exclusion or lookalike
Raw lines 211 to 227
Debugging
Raw lines 228 to 229DebugView
Enable with:
- URL parameter:
?debug_mode=true - Chrome extension: GA Debugger
- gtag:
'debug_mode': truein config
View at: Reports > Configure > DebugView
Raw lines 230 to 238Common Issues
Events not appearing:
- Check DebugView first
- Verify gtag/GTM firing
- Check filter exclusions
Parameter values missing:
- Custom dimension not created
- Parameter name mismatch
- Data still processing (24-48 hrs)
Conversions not recording:
- Event not marked as conversion
- Event name doesn't match
- Counting method (once vs. every)
Raw lines 244 to 262
Data Quality
Raw lines 263 to 264Filters
Admin > Data streams > [Stream] > Configure tag settings > Define internal traffic
Exclude:
- Internal IP addresses
- Developer traffic
- Testing environments
Cross-Domain Tracking
For multiple domains sharing analytics:
- Admin > Data streams > [Stream] > Configure tag settings
- Configure your domains
- List all domains that should share sessions
Session Settings
Admin > Data streams > [Stream] > Configure tag settings
- Session timeout (default 30 min)
- Engaged session duration (10 sec default)
Raw lines 282 to 290
Integration with Google Ads
Raw lines 291 to 292Linking
- Admin > Product links > Google Ads links
- Enable auto-tagging in Google Ads
- Import conversions in Google Ads