Cross-device attribution helps you understand user behavior when the same person interacts across mobile, desktop, and other platforms. By implementing User ID tracking, you create a unified view of the customer journey—leading to better personalization, attribution accuracy, and conversion analysis.
🎯 Why Use User ID?
- ✅ Recognize users across devices and browsers
- ✅ Combine anonymous and authenticated sessions
- ✅ Improve conversion funnel visibility
- ✅ Reduce inflated user counts
- ✅ Enable richer audience segmentation
✅ Prerequisites
- GA4 property created
- Web GTM and Server-Side GTM containers
- Your platform supports user authentication (login)
- Server-side endpoint or backend access to enrich user ID
- Optionally: Consent Mode compliance
🔧 Step-by-Step Guide
🔹 Step 1: Make User ID Available on Login/Authenticated Pages
Expose the authenticated user ID from your server into the frontend via JavaScript or dataLayer.
Example (dataLayer push):
<script>
dataLayer.push({
event: 'user_authenticated',
user_id: 'USER_12345'
});
</script>
👉 Ideally fire this on all pages where the user is logged in (post-login, dashboard, checkout, etc.)
🔹 Step 2: Create a User ID Variable in Web GTM
- Go to Variables > New
- Type: Data Layer Variable
- Name:
user_id - Data Layer Variable Name:
user_id - Save as:
DLV - user_id
🔹 Step 3: Pass User ID in GA4 Configuration Tag
Modify your GA4 Configuration Tag to include the user_id.
gtag('config', 'G-XXXXXXX', {
user_id: 'USER_12345'
});
In GTM:
- Edit GA4 Config Tag
- Under Fields to Set:
- Field Name:
user_id - Value:
{{DLV - user_id}}
- Field Name:
✅ This automatically adds user_id to all GA4 events.
🔹 Step 4: Forward User ID to Server-Side GTM
If you’re using Server-Side GTM, your GA4 Config tag should point to:
https://gtm.yourdomain.com
GA4 event hits sent to this endpoint will now include user_id.
🔹 Step 5: Capture User ID in Server-Side GTM
In ssGTM, extract user_id from GA4 Client request:
Create a Variable:
- Variable Type: Event Data
- Variable Name:
user_id
return event.data.user_id || request.body?.events?.[0]?.user_id;
🔹 Step 6: Forward to GA4 (Server-Side Event Tag)
In ssGTM:
- Create a GA4 Event Tag
- Set
user_idas a User Property
User Properties:
| Property Name | Value |
|---|---|
| user_id | {{Event Data - user_id}} |
✅ Also attach to custom events like purchase, login, lead_submit, etc.
🔹 Step 7: (Optional) Sync User ID with CRM via HTTP Request
To connect GA4 activity to your CRM, you can send the user_id with event context:
Example HTTP POST Tag in ssGTM:
POST /user-event-sync
{
"user_id": "USER_12345",
"event": "purchase",
"transaction_id": "ORD789",
"timestamp": "2024-05-30T08:01:00Z"
}
✅ Use it to push activity into Salesforce, HubSpot, or your own backend.
🔹 Step 8: GA4 Reporting with User ID
Go to GA4 Admin > Reporting Identity
Set Blended or Observed (GA will combine User ID + Device ID)
Once set:
- Go to User Explorer Report
- You’ll see User ID-based journeys
- Filter by segments like “logged-in users” or “multi-session buyers”
🔹 Step 9: Ensure Consent Compliance
If you use Consent Mode, make sure user_id is only sent after consent.
gtag('consent', 'update', {
ad_storage: 'granted',
analytics_storage: 'granted'
});
Only push user_id to dataLayer after consent granted.
🔹 Step 10: Debug and QA
- Use GA4 DebugView to verify
user_id - Use Chrome DevTools > Network > collect? to inspect payload
- Use Server GTM Preview Mode to inspect forwarded
user_id - Enable Realtime Reports > filter by device & user ID
🔒 Tips for Security and Privacy
- Never expose PII (email, name, phone) in GTM or GA4
- Use hashed values if needed (SHA256)
- Sanitize and validate user ID before sending to GA
- Apply Consent Mode & Privacy Policy disclosures
✅ Summary Table
| Step | Action |
|---|---|
| 1 | Add user_id to dataLayer |
| 2 | Create GTM variable |
| 3 | Add to GA4 Config tag |
| 4 | Route via Server GTM |
| 5 | Extract in ssGTM |
| 6 | Send as user property to GA4 |
| 7 | (Optional) Sync with CRM |
| 8 | Enable GA4 Reporting Identity |
| 9 | Respect consent mode |
| 10 | Debug thoroughly |