I am fairly new to Google Analytics and Tag Manager world. I am trying to add user id to ga events. For example I would like to add user id in case a google analytic event occurred.
What is the best practice to store userId at client side?
you have to pass it as a dataLayer variable and add a macro to pass it to the GA, by setting additional fields in GA UA code: https://support.google.com/tagmanager/answer/4565987
So to answer your question, you should store it in dataLayer (so basically in javascript) and pass on to GTM.
If you know how to use GTM properly it actually doesn't matter if you store this value directly in dataLayer, or in cookie, or in metatag, since you could then extract it from all mentioned locations by using js, but simplest one is the dataLayer.
I would store it in the dataLayer.
dataLayer = [{
'userId': 'abcdefg123456'
}]
Then if you want to reference it in an event, just pass {{userId}}
as a custom dimension.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With