Search code examples
google-analyticsgoogle-tag-manager

User ID not being sent in collect request


I have a problem with sending user id through GTM. I'm trying to configure it with Analytics - Web + App on web.

I have added a dataLayer variable, with following properties:

  • Name (for use in GTM): User ID
  • Variable name: user_id
  • Version: 2

Then, in my app I'm executing:

window.dataLayer.push({ "user_id" : "some_user_id" });

But this variable never gets sent via collect request for GTM. Could anyone tell me where the problem can be?

I also tried

window.dataLayer.push({ "User ID" : "some_user_id" }); 

but that didn't work too.


Solution

  • If you send it after GTM snippet (so after gtm.js native trigger) you have to add an event in dataLayer and use it to trigger the hit with userId field.