Google Analytics - Simple way to get Client ID with Universal Analytics

Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Fusce tellus odio, dapibus id fermentum quis, suscipit id erat. Mauris metus. Maecenas aliquet accumsan leo. Fusce tellus. Duis pulvinar. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Duis pulvinar.

This is an easy method of being able to query user-level information using the Google Analytics API because everyone will have the ability to do it, and it's ridiculously easy to implement. This ID is Google's identifier for the user's browser. So, with this method, you will be able to track users across sessions if they're in the same, cookied browser, but you won't be able to track cross-browser/device behavior without some additional set up. The downside is you won't be able to use this on historical data because the change is not retroactive - you'll have to wait and collect some data before you can use it.

Here's how to do it...

1.) First, you'll create a new dimenion in Google Analytics. Go to Admin > Property > Custom Definitions > Custom Dimensions.

2.) Create a new dimension - name it, and set it as "user" scoped.

3.) Update your Google Analytics code on your website to bring in the Google Analytics Client ID. This example is done with analytics.js, but can also be done with gtag implementation or in Google Tag Manager - just Google it. Also, be sure to update your "UA" code with the one from your tracking script in the Google Analytics admin.

< 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', '', 'ga');
ga('create', 'UA-12555617-1', 'auto');
ga(function (tracker) {
  var GAClientID = tracker.get('clientId');
  ga('set', 'dimension1', GAClientID);
< /script>

4.) Finally... wait. Obviously, this dimension won't be filled retroatively for previous visitors, so you'll have to wait for a while to create some data to work with.

Back To Blog

Google Maps