AdWords is now Google Ads. Our new name reflects the full range of advertising options we offer across Search, Display, YouTube, and more. Learn more

Analytics
3K members online now
3K members online now
Dive into multiple domain (Cross/Sub) tracking, implementing Ecommerce and Enhanced Ecommerce, setting up Event tracking, and Universal Analytics code.
 
Guide Me
star_border
Reply

Regarding the code implementation on Website for "Client Id" tracking

Visitor ✭ ✭ ✭
# 1
Visitor ✭ ✭ ✭

Hello Friends,

 

Here I am stuck on a query from last few days. 

 

In Google Analytics, I am trying to track "Client ID" as secondary dimension.

I have already created a custom dimension for "Client Id" and now it can be seen as in secondary dimension but with no data, it is not tracking any data. It is showing 0 value.

 

After going through many articles, have seen many confusing code and some not working.

I tried inserting the below given code(I guess its a incomplete one) on my website :- 

 

ga(function(tracker) {

var clientId = tracker.get('clientId');

});

 

And as expected, nothing is found.

 

Can anyone please help me in tracking the "Client ID"? Any suggestion will be appreciated.

1 Expert replyverified_user
1 ACCEPTED SOLUTION

Accepted Solutions
Marked as Best Answer.
Solution
Accepted by topic author Brian C
March 2017

Re: Regarding the code implementation on Website for "Client Id" tracking

[ Edited ]
Top Contributor
# 2
Top Contributor

I found the following worked fine when i tested it

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'auto');
  ga(function(tracker) {
     tracker.send('pageview', {'dimension1' : tracker.get('clientId') });
});
</script>

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

View solution in original post

Marked as Best Answer.
Solution
Accepted by topic author Brian C
March 2017

Re: Regarding the code implementation on Website for "Client Id" tracking

[ Edited ]
Top Contributor
# 2
Top Contributor

I found the following worked fine when i tested it

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','https://www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-XXXXXXXX-X', 'auto');
  ga(function(tracker) {
     tracker.send('pageview', {'dimension1' : tracker.get('clientId') });
});
</script>

 

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Visitor ✭ ✭ ✭
# 3
Visitor ✭ ✭ ✭

Hello Bronwyn,

 

Thank you for the reply.

 

Shall I replace my complete Analytics code with your's given one?

 

Will all the tracking will work fine? 

 

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

[ Edited ]
Top Contributor
# 4
Top Contributor

Hello :-)
I dont know.. i dont know what else you have going on with your tracking code.. do you have other edits/modifications made to the tracking code snippet?

are you wanting to send the clientID with each site pageview.. or say once via an event when a user performs a certain action on the website?

 

That is just an example of how i got it to populate my custom dimension while sending it with a pageview via the tracking code.

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Visitor ✭ ✭ ✭
# 5
Visitor ✭ ✭ ✭

No, there's no other changes made on the code.

Yes, I am trying to send the clientID with each site pageview.

 

I will update the given code on the website and check. 

 

 

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Top Contributor
# 6
Top Contributor

The above code should work for you then :-)
(just make sure to swap out the tracking id with yours)

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Visitor ✭ ✭ ✭
# 7
Visitor ✭ ✭ ✭

Hello Bronwyn,

 

Hope you are doing good.

 

I updated that code on my website, I replaced the tracking id with mine. 

 

But in custom reports, m still getting no data.

 

Please see the below given link, I have attached two screen shot in it about my Analytics data.

 

https://docs.google.com/document/d/1ND4erI54NmmhYB4Z4oaas8rnALLELjOxQkEyDTA_g7Q/edit

 

Please correct me if I am wrong on any place.

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Top Contributor
# 8
Top Contributor

1) What scope is the custom dimension set to?
2) Are there any filters applied to the View?

3) Occasionally i have had to wait up to 48hrs for 

them to appear in the standard reports...

 

Are you able to provide a link to the site? So as i can have a look via browser

 

Thanks :-)

Bronwyn Vourtis, Google Analytics Top Contributor
Was my response helpful? If yes, please mark it as the ‘Best Answer.’ Learn how here

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Visitor ✭ ✭ ✭
# 9
Visitor ✭ ✭ ✭

Good Morning Bronwyn,

 

 

Now I can some data now showing in my custom report on Client ID.

 

But I see less data. Why so?

 

1) What scope is the custom dimension set to?

Ans- Session
2) Are there any filters applied to the View?

Ans -Not yet

3) Occasionally i have had to wait up to 48hrs for them to appear in the standard reports...

Ans - Now I have started receiving some data.

 

Like I have traffic of 5 Session in standard report and in my custom report I can see only 1 Client ID i.es only 1 data. Can you say why?

Regarding the code implementation on Website for &quot;Client Id&quot; tracking

Visitor ✭ ✭ ✭
# 10
Visitor ✭ ✭ ✭

Hey Bronwyn,

 

Now it's working fine. I am receiving all the data. 

 

Thanks a lot for all your help and support. You were really helpful.

 

Really Thanks again. Have a nice day.

 

Regards.