Setting Up User ID & Login Data for Cross-Device Attribution in GA4

Standard

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

  1. Go to Variables > New
  2. Type: Data Layer Variable
  3. Name: user_id
  4. Data Layer Variable Name: user_id
  5. 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}}

โœ… 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

 

Leave a Reply

Your email address will not be published. Required fields are marked *