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_id
as 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 |