1

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 my dataLayer)
  • 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 :
  1. user_id along with the variable I created
  2. setting debug_mode with value 'true'
  3. Under Property Name: I have added user_id_dimension with the userId variable 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_dimension as 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.

2 Answers 2

0

In your current setup, you're trying to pass the user_id as 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_id as a user property so that it appears in the User Explorer section.

In GTM, instead of putting user_id under "Event Parameters", you should put it under "User Properties".

Here's how to do it:

  1. In GTM, open your GA4 Configuration Tag.
  2. In the tag configuration, scroll down to the "Event Parameters". Remove the user_id field from this section.
  3. Further down, you'll find the "User Properties" section. Here, add a new row.
  4. In the "Parameter" column, enter user_id. This is the reserved parameter name in GA4 for the user ID.
  5. In the "Value" column, select your userId variable.
  6. Save your changes.

Now, your userId should 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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for taking time out to help me fix this, I have added user_id in my user property section with the variable userId, and here is my dataLayer script from which I am passing userId: <script async> {` window.dataLayer = window.dataLayer || []; window.dataLayer.push({event: 'test', 'userId': '${user_id_hash}'}); `} </script> So now after 24 hours, this userid that I am passing here, it should get showed in user explorer report right
Also, under my Realtime Report, in users by user property, I dont have any data showing up, so how can I check if all is okay, or there is some issue
0

You shouldn't add the userid as a user property, may sound counterintuitive but it has to be sent as an event property. Remember that GA4 has cardinality limitation so sending high cardinality identifiers is not a good idea.

You can set it up two ways using Google Tag Manager:

  1. In your configuration tag, set it up as a Configuration Parameter.
  2. In an event tag, set it up as a Event Parameter.

You can then find this user id using User Exploration inside Explorer > User Explorer.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.