Send GA Client ID as custom dimension with GTM

Want create site? Find Free WordPress Themes and plugins.

There are many reasons why you would want the GA client ID collected.  Let’s just say getting the value of the GA cookie gives you a lot of options for extra reports and extra info. In the future I’ll use the GA client ID for some fancy stuff, so you’ll see some practical uses of collecting it.

For the moment let’s keep to the point!

What is the GA Client ID?

First – let’s start with the fact I am writing about Universal Analytics. If you are still using the Classic Analytics code (the ga.js library) don’t expect me to give you a solution for it. It may sounds harsh, but there is no reason not to use Universal Analytics, so if you don’t – just upgrade your analytics account. It’s just 2 clicks hassle and you get a lot of benefits (including this guide).

So what is GA client ID?

The GA Client Id is a unique, randomly generated string (actually it’s combination of timestamp of your first visit and random number) that gets stored in the browsers cookies, so subsequent visits to the same site can be associated with the same user (copy-pasted right from the Google Analytics documentation).

While a visitor don’t change the browser/device or don’t clear his/her cookies – the client Id is used to identify if the visitor is new or returning.

How to collect the GA User ID with Google Tag manager?

Grabbing the Client Id is as easy as writing (or copy-pasting) a few rows of code:

Just place this code in a new Custom JavaScript Variable and you are good to go.

Sending the GA User ID to Google Analytics

Now, after you collected the Client ID you’ll need to send it. Just create an Universal Analytics Event tag and send the collected Client Id as a custom dimension. Go to your Google Analytics admin panel, select “Custom Definitions” and then “Custom Dimension”. Create a new dimension with the name “Client Id” and remember the dimension’s index! Make the scope of this dimension as “User“, because you want to catch the value and assign it to the user.

Creating Custom Dimension in Google Analytics

When you have this ready it’s time to send the event with Google Tag Manager. This is easier done than said. Just create new GA event tag like this:

Client ID tag

The {{Constant - UA Code}} is your UA code (check this article for more information) and the {{CJS - Client ID}} is the variable we just created the previous step. Don’t forget to put true in the “Non-Interaction” option, so your tag won’t trigger an interaction.

Add the custom dimension you created in the previous step (it’s 1 in the screenshot, don’t forget to change that number depending on your dimension index).

Fire the Client ID event

As the Client Id is in direct dependency with your Pageview tag – you don’t need to make any trigger for the moment. In order to be sure you sent the Client Id you need to be sure you have the Client Id in the first place!

Your Pageview tag is the one that creates the Id, so you want to trigger your event right after the GA Pageview tag fired. That’s why instead of using regular trigger you will want to save the tag without one. Then go to your Pageview Tag and add the Client Id event to fire right after the Pageview Tag fired (this will make sure that you already collected the Client Id value when you are firing the Client Id tag):
Fire your client Id event

After that step it’s time to debug and publish your setup.

Now you have everything ready to start collecting the Client Id values of your users! In this blog you’ll find some great practical uses of this Client Id for some great custom reporting!

Did you find apk for android? You can find new Free Android Games and apps.

Check these related articles:

Leave a Reply

2 Comments on "Send GA Client ID as custom dimension with GTM"

Notify of
avatar
trackback
GTM Trigger for X days after the first user visit | GTM Tips

[…] wrote about extracting the Client Id from the GA cookie before (and you’ll need to check it out, as it’s vital part of this trigger setup). As […]

trackback
Add Timestamp to all of your GA Events | GTM Tips

[…] timeline whenever you need it without any hassle. Even more – if you use it with the Client ID Tracking – you will have your own User […]

wpDiscuz