| name | ga4-user-tracking |
| description | Complete guide to User ID implementation, user properties, and cross-device tracking in GA4. Use when implementing User ID for authenticated users, setting user properties, enabling cross-device tracking, configuring Reporting Identity, or tracking user attributes. Covers gtag('set') for user properties, User ID setup, cross-domain tracking, and user data management. |
GA4 User ID and Cross-Device Tracking
Overview
User ID enables cross-device tracking for authenticated users and user properties allow tracking custom user attributes across all events.
When to Use This Skill
Invoke this skill when:
- Implementing User ID for logged-in users
- Setting up cross-device tracking
- Configuring user properties for custom attributes
- Setting Reporting Identity options
- Tracking user lifecycle across devices
- Implementing authentication-based analytics
- Setting user-scoped custom dimensions
- Working with gtag.js user property commands
- Debugging user identification issues
- Implementing cross-domain tracking with User ID
- Analyzing user journeys across multiple devices
Core Capabilities
User ID Implementation
What is User ID:
- Persistent identifier for authenticated users
- Enables cross-device tracking
- Requires explicit user opt-in
- Must not contain PII (hash if needed)
Implementation Methods:
Method 1: gtag.js
// Set User ID when user logs in
gtag('config', 'G-XXXXXXXXXX', {
'user_id': 'USER_12345'
});
// Or use gtag('set')
gtag('set', 'user_id', 'USER_12345');
Method 2: GTM (Data Layer)
// Push User ID to dataLayer
dataLayer.push({
'user_id': 'USER_12345'
});
In GTM:
- Create Data Layer Variable:
user_id - In GA4 Configuration tag, add parameter:
- Parameter:
user_id - Value:
{{DL - User ID}}
- Parameter:
Method 3: Measurement Protocol
{
"client_id": "client_123",
"user_id": "USER_12345",
"events": [...]
}
Best Practices:
- Set when user logs in
- Clear when user logs out:
gtag('set', 'user_id', null) - Use internal IDs (not emails)
- Hash sensitive IDs
- Document User ID policy
Reporting Identity
Path: Admin → Data Settings → Data Collection → Reporting Identity
Options:
Blended (Recommended)
- Uses User ID when available
- Falls back to device ID + Google signals
- Most complete user view
Observed
- Uses User ID and device ID only
- No Google signals
- More privacy-focused
Device-based
- Uses only device ID (client_id)
- No cross-device tracking
- Most restrictive
Recommendation: Use "Blended" for most comprehensive tracking
User Properties
What are User Properties:
- Custom attributes set at user level
- Persist across all events
- Max 25 properties per property
- Property names ≤24 characters
- Values ≤36 characters
Setting User Properties:
gtag.js:
gtag('set', 'user_properties', {
'user_tier': 'premium',
'account_age_days': 365,
'preferred_category': 'electronics'
});
GTM (Data Layer):
dataLayer.push({
'user_properties': {
'user_tier': 'premium',
'account_age_days': 365
}
});
Measurement Protocol:
{
"client_id": "client_123",
"user_properties": {
"user_tier": {
"value": "premium"
},
"account_age_days": {
"value": 365
}
},
"events": [...]
}
Common User Properties:
user_tier: "free", "premium", "enterprise"signup_date: "2024-01-15"subscription_status: "active", "trial", "cancelled"customer_ltv: Lifetime value bucketindustry: User's industrycompany_size: Employee count rangeinterests: Comma-separated interests
Avoid PII:
- ❌
email,name,phone_number,address - ✅
email_domain,first_name_initial,user_segment
Custom Dimensions for Users
Creating User-Scoped Custom Dimension:
- Admin → Custom Definitions → Custom Dimensions
- Click Create custom dimension
- Dimension name: User Tier
- Scope: User
- User property:
user_tier - Save
Using in Reports:
- Add as dimension in Explorations
- Filter/segment by custom dimension
- Analyze user cohorts
Cross-Device Tracking
Requirements:
- User ID implemented
- Google signals enabled (for Blended identity)
- Users opt in to personalization
How it Works:
- User visits on mobile (logged in) →
user_idset - User visits on desktop (logged in) → same
user_id - GA4 stitches sessions together
- Reports show unified user journey
Verifying Cross-Device:
- Enable DebugView
- Log in on Device 1 with
debug_mode=true - Note
user_idparameter in events - Log in on Device 2 with same account
- Verify same
user_idin events - Check reports for unified sessions
Cross-Domain Tracking
Setup for User ID Across Domains:
gtag.js Configuration:
gtag('config', 'G-XXXXXXXXXX', {
'linker': {
'domains': ['example.com', 'shop.example.com', 'blog.example.com']
}
});
What This Does:
- Passes client_id between domains via URL parameter
- Preserves user_id if set
- Maintains session continuity
GTM Setup:
- In GA4 Configuration tag
- Expand Configuration Settings
- Add parameter:
linker:{"domains": ["example.com", "shop.example.com"]}
Testing:
- Visit domain1.com
- Click link to domain2.com
- Verify
_glparameter in URL - Check session continues in GA4
User Data Deletion
Deleting User Data by User ID:
Path: Admin → Data Deletion Requests
Process:
- Click Create deletion request
- Select parameter: User ID
- Enter User ID to delete
- Choose deletion scope (all data or date range)
- Submit request
Processing:
- Takes ~72 hours to complete
- Deletes all events for that User ID
- Cannot be undone
Use Cases:
- GDPR/CCPA compliance requests
- User account deletion
- Data cleanup
Testing User ID
Workflow:
- Implement User ID (gtag or GTM)
- Enable DebugView
- Test Login:
- Before login: Check events have only
client_id - After login: Verify
user_idappears in event details
- Before login: Check events have only
- Test Logout:
- After logout: Verify
user_idcleared/null
- After logout: Verify
- Test Cross-Device:
- Login on Device 1
- Login on Device 2 with same account
- Verify same
user_id
DebugView Verification:
- Click any event
- Expand event details
- Check "User ID" field populated
Reports Verification:
- Wait 24-48 hours
- Admin → DebugView or Realtime
- Check user count vs sessions
- Lower user count = User ID working (same user, multiple sessions)
Integration with Other Skills
- ga4-setup - Initial property setup for User ID
- ga4-gtag-implementation - Implementing User ID via gtag.js
- ga4-gtm-integration - Implementing User ID via GTM
- ga4-custom-dimensions - Creating user-scoped dimensions
- ga4-audiences - Building audiences based on User ID
- ga4-privacy-compliance - User data deletion and compliance
- ga4-debugview - Testing User ID implementation
References
- references/user-id-implementation.md - Complete User ID setup guide
- references/user-properties-guide.md - User properties reference and examples
- references/cross-device-tracking.md - Cross-device implementation and testing
- references/reporting-identity.md - Reporting identity options explained
Quick Reference
Set User ID (gtag.js):
gtag('config', 'G-XXXXXXXXXX', {'user_id': 'USER_123'});
Set User Properties (gtag.js):
gtag('set', 'user_properties', {
'user_tier': 'premium'
});
Clear User ID (gtag.js):
gtag('set', 'user_id', null);
Limits:
- 25 user properties per property
- User property name ≤24 characters
- User property value ≤36 characters
- User ID must not contain PII