> ## Documentation Index
> Fetch the complete documentation index at: https://docs.segmentstream.com/llms.txt
> Use this file to discover all available pages before exploring further.

# User ID

> Implement user ID tracking in Google Analytics to improve cross-device attribution in SegmentStream.

To improve cross-device attribution, it's necessary to implement the tracking of the user ID in Google Analytics.

## For GA4 via Tag Manager

<Steps>
  <Step title="Pass the parameter to dataLayer">
    On every page load after login, pass the relevant parameter `user_id` to your `dataLayer`.
  </Step>

  <Step title="Create a GTM variable">
    Create a Variable inside GTM that reads that value from the dataLayer.

    <img src="https://mintcdn.com/segmentstream/ZFr6pt66noWB70nu/images/gtm-user-id-datalayer-variable.png?fit=max&auto=format&n=ZFr6pt66noWB70nu&q=85&s=1942606cf2ffd0dc7a8dce2a036ac874" alt="GTM user_id dataLayer variable" width="2738" height="1048" data-path="images/gtm-user-id-datalayer-variable.png" />
  </Step>

  <Step title="Send the property to GA4">
    Under the Configuration Parameter section of your GA4 Google Tag, add a new row with the **user\_id** property and the corresponding **Value** (the Data Layer variable you created in step 2).

    <img src="https://mintcdn.com/segmentstream/ZFr6pt66noWB70nu/images/gtm-user-id-config-parameter.png?fit=max&auto=format&n=ZFr6pt66noWB70nu&q=85&s=0fe44be10625c5280a2dd15aa017424a" alt="GTM user_id config parameter" width="2744" height="916" data-path="images/gtm-user-id-config-parameter.png" />
  </Step>
</Steps>

## For GA4 using gtag.js

Pass a unique user ID after login to track users across sessions on different devices using the `user_id` config parameter.

```javascript theme={null}
gtag('config', 'STREAM_ID', {
  'user_id': 'USER_ID'
});
```
