I am working on a next project, and from the \_app.tsx file, I am pushing this dummy data to the dataLayer of google tag manager
<Script id="gtm" strategy="beforeInteractive"> {
window.dataLayer = window.dataLayer || \[\];
window.dataLayer.push({event: 'test', 'userId': 'abc098'});
}</Script>
The objective I am trying to attain is that when I pass this userId to dataLayer in google tag manager; I want to be able to view this under Google Analytics -> Explore -> User Explorer Section
In google tag manager, I have done the following steps:
- Created a variable with the name
'userId'(just as in mydataLayer) - Then in my GA4 tag as you can see in the image I have attached below, under fields to set, I have added a field for :
user_idalong with the variable I created- setting
debug_modewith value 'true' - Under Property Name: I have added
user_id_dimensionwith theuserIdvariable GA4 Tag Configuration
- Under triggers, I have created a custom event with the name 'test', referenced under my GA4 tag Trigger Configuration
In google analytics:
- For web data streams - I have enhanced measurement on
- Also created a custom definition for userId with
user_id_dimensionas created under property in gtm
When I preview my website on GTM; I am able to see that my test event is being pushed to dataLayer along with the userId, and my GA4 tag is also being fired.
But on Google Analytics, I am not able to see the userId in events or in the User Explorer section
I also have all my changes submitted on GTM.
In your current setup, you're trying to pass the
user_idas an event parameter, but what you need to do is pass it as a user property.In GA4, user properties are attributes you define to describe segments of your user base, such as language preference or geographic location. Analytics automatically logs some user properties; you don't need to add any code to enable them. If you need to collect additional data, you can set up to 25 different Analytics user properties in your project.
In this case, you need to set the
user_idas a user property so that it appears in the User Explorer section.In GTM, instead of putting
user_idunder "Event Parameters", you should put it under "User Properties".Here's how to do it:
user_idfield from this section.user_id. This is the reserved parameter name in GA4 for the user ID.userIdvariable.Now, your
userIdshould be passed to GA4 as a user property, and it should appear in the User Explorer section.Remember to test your changes in GTM's preview mode and verify in the GA4 real-time report before publishing the changes. Also, user properties might take up to 24 hours to populate in the User Explorer section in GA4.