First of all let’s start with what is a user id in GA4?
User id is a unique identifier of people who visit your website and it is the most effective way of identifying users in analytics platforms like GA4.
Another way of identifying users is through client id which is basically a user identifier generated by google analytics cookie to identify users across sessions & web pages. Client id reports can be viewed in GA4 through user explorer report.
For bigquery users, the client id is userpseudo_id.
The downside of using only client id is when users clear their cookie or visit a website from a different device then it’s counted as a new user by GA4. For this reason we use user id to identify users.
But user id can only be used for logged in users.
When someone logs into your website, you’ll have their personal information and most systems will have a unique id(primary key) to identify users other than personal information like email, phone number or social security.
We should always be cautious with user id as we are not allowed to use PII as it violates the privacy policy.
If your system doesn’t generate such ids then you can use hashing to assign a user id to your logged in users.
Why is User id so important for you?
User Id can be your holy grail to connect your ga4 data with your product analytics data, CRM, email marketing data and more. It will be the center point to build a 360 view of your customers.
let’s look at some more scenarios where user id will be extremely valuable:
->To see reports of cross device user performance- How many people browse your site using different devices and their interactions
->To get complete insights of customer journey and building 360 view of your customers
->To connect your marketing data with your other data sources and it can be easily done using user id to join tables in data warehouses like BigQuery
Now you know about what is user id, how to get it & why should we use it , now we’ll look into how to assign user id to users and send that data to analytics platforms like GA4.
To assign user_id to visitors, we can use tag management tools like GTM(google tag manager).
We’ll pass the user_id to dataLayer of your website when someone signs in to your page.
You can tell your website developer to push this code after login event:
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
'event' : 'Sign in',
'userId' : 'xxxxxxx' //write your user_id here
})
You can check your dataLayer from the developer tool in the browser and see if you’re seeing user_id when the sign in event occurs.
After you have sent user_id to dataLayer, you can create a new dataLayer variable to store the value and pass that value as event parameters to all of your ga4 events.
When a user interacts with your website without logging in then the value would be undefined and when they sign in then user_id parameter will be assigned with a value from your dataLayer.
Important note:
[If you want to export your data to bigquery then you should make sure you do not accept “user provided data collection” agreement in ga4 admin. This will disable user_id export to bigquery and it’s a permanent change to your ga4 property & you can’t undo this agreement.]
