Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tracking user id using with Google Tag Manager

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?

  1. In Cookie?
  2. In pages with a metatag?
  3. Or something else?
like image 858
Cemo Avatar asked Aug 09 '14 08:08

Cemo


2 Answers

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.

like image 136
Łukasz Rysiak Avatar answered Jan 01 '23 13:01

Łukasz Rysiak


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.

like image 26
Blexy Avatar answered Jan 01 '23 13:01

Blexy