Partners
2.8K members online now
2.8K members online now
Gain advanced product knowledge to help you make the most of your campaigns
Guide Me
star_border
Reply

Client ID in Google Tag manager

Follower ✭ ✭ ☆
# 1
Follower ✭ ✭ ☆

Hi!

 

How can I extract the client id?? I'm using google tag manager and I need to extrat for to use it in measurement protocol

 

ga(function(tracker) {
 
var clientId = tracker.get('clientId');
});

 

 

Thanks! 

1 Expert replyverified_user

Client ID in Google Tag manager

Top Contributor
# 2
Top Contributor

Hi Javier,

 

Please utilize this documentation to extract the Client ID. 

 

Kind Regards,

 

James

____________________________________________________________
Google My Business & Google AdWords Top Contributor
Google Partner | GYBO Agency | Local Guide | My Profile


 


 


 

Client ID in Google Tag manager

Follower ✭ ✭ ☆
# 3
Follower ✭ ✭ ☆

But The function ha doesn't work using gtm

Client ID in Google Tag manager

Top Contributor
# 4
Top Contributor

Hi Javier,

 

You have to use the link I provided to learn how to modify your Google Analytics tracking code to perform the action you want, then use Google Tag Manager to implement it to the web page, then use Google Tag Assistant (free Google Chrome web browser extension) to test & verify the proper firing of the tag (tracking code).   

 

When you click on the link I provided, please look in the right hand menu and go through each section.

 

Kind Regards,

 

James

____________________________________________________________
Google My Business & Google AdWords Top Contributor
Google Partner | GYBO Agency | Local Guide | My Profile


 


 


 

Client ID in Google Tag manager

Follower ✭ ✭ ☆
# 5
Follower ✭ ✭ ☆

Hi

 

Just for clarify

 

The ga tag should be a custom html that we modify and then I can store the client and use it?

Client ID in Google Tag manager

Top Contributor
# 6
Top Contributor

Hi Javier,

 

Yes, you take your typical/standard Google Analytics tracking code and modify it with the info I provided. Then add it to the website's coding or to Google Tag Manager for pulling the data you instructed it to.

 

Kind Regards,

 

James

____________________________________________________________
Google My Business & Google AdWords Top Contributor
Google Partner | GYBO Agency | Local Guide | My Profile


 


 


 

Re: Client ID in Google Tag manager

[ Edited ]
Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

GTM names the tracker automatically and creates new trackers for every tag you have it takes a little digging around the output of `ga.getAll()` to find the clientID.

 

for(var results = {}, trackers = ga.getAll(), i = 0; i<trackers.length; i++){
results[trackers[i].a.data.values[":clientId"]] = trackers[i].a.data.values[":name"];
}
console.log(results);

or using the ga syntax from the documentation:

for(var results = {}, trackers = ga.getAll(), i = 0; i<trackers.length; i++){
  results[trackers[i].get("clientId")] = trackers[i].get("name");
}
console.log(results);

 

This will return you all the ga trackers active on the page as well as the corresponding clientID that is set.

 

Here is what it looks like: 

 

Object {"123456789.123456789": "gtm5"}

If you're just interested in the client IDs you can get them from `Object.keys(results)` or if you only have one UA active on the site `Object.keys(results)[0]`

 

Depending on use-case you can throw that either in a Custom HTML tag and output the result to the dataLayer or have it return in a Custom JavaScript variable

 

 

Client ID in Google Tag manager

Visitor ✭ ✭ ✭
# 8
Visitor ✭ ✭ ✭

Hey guys! I found that this is the way to extract values from a site that uses a traditional Google Tag Manager. 

The interesting part of this is that you have to explicitly call the final object because they contain ':'. 

 

This should return the users clientId from the ga object:

ga.getAll()[0].b.data.values[':clientId']