Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 837
Petr Havlik Avatar asked Nov 14 '13 11:11

Petr Havlik


People also ask

What is Google Analytics ClientID?

What is the Client ID in Google Analytics? The Client ID (cid) is a unique identifier for a browser–device pair that helps Google Analytics link user actions on a site. By default, Google Analytics determines unique users using this parameter.

How do I add a client ID to Google Analytics?

Go to "GA authentication" tab in Google Analytics Counter module settings (admin/config/system/google_analytics_counter/authentication), copy "Client ID" and "Client secret", and then hit the "Start setup and authorize account" button.


1 Answers

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.

like image 101
Blexy Avatar answered Sep 20 '22 15:09

Blexy