-
Implementing User IDs in GTM and GA4
Hey there, I’ve been dabbling with GTM and GA4 recently, and in one of the lessons, I stumbled upon a nifty little thing called dataLayer, which you push to collect userId in GTM. I’ve got the gist of it but when the tutor mentioned swapping out the default userId with the actual one (highlighted in the tutorial), I was left scratching my head. I’m still new on this journey, further away from being a coder still!
I do know how to tweak the code in my header.php file and place it properly above the GTM code. Yet, I’m stumped on how to make it work so it pulls a new userId every time a user logs in. Got any ideas on this one? Remember, I’m just starting out here, so a simple explanation from my fellow developers on how I can ace this without a developer would be much appreciated. Cheers!
window.dataLayer = window.dataLayer || []; window.dataLayer.push({ 'event' : 'login', '**userId' : '1234567' //Supposedly this number needs to be swapped with an actionable User ID })
Log in to reply.