简体   繁体   中英

Accessing ClientID set by Google Analytics through Google Tag Manager

I have setup a new Universal Analytics tracking and would like to store ClientID in one of the custom dimensions slots .

The tracking tags are implemented through Google Tag Manager (using the predefined UA tag) and I am having the difficulty to passing the Client ID (via custom JavaScript Macro) with the basic pageview request.

I have named my tracker so that I can access it and this code runs without any error in console, however when used with GTM, it's returning an error.

ga.getByName('trackerGTM').get('clientId'))

produces an error:

Uncaught ReferenceError: ga is not defined

Any tips?

I assume you're firing the pageview {{url}} matches RegEx .* , correct? Could be that Universal hasn't loaded yet. Have you tried {{event}} equals gtm.dom ? I haven't tested this, but it's a thought.

EDIT:

This looks like a bug. I was able to run:

function(){
  var client = ga.getAll()[0].get('clientId');
  return client;

}

And have it spit out the client ID with no problem.

The real problem is that GTM (Google Tag Manager) creates an object that is NOT called ga (it creates an object named ga followed by a random number), that's why 'ga' is not defined. You should try something on the lines of using the tag manager to put that client id into a javascript variable so you can access it from the page)

I was reading up on setting client ids and came across this blog link about accessing client ID in GA while using Google Tag Manager. Might be helpful.

Accessing Client ID in GA using custom dimensions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM