We are thrilled to announce that Unilytics has joined Optimus SBR
Learn more

Posted by John Strykowski

September 14, 2015


Leave Reply

Improve 1:1 Marketing with Google Analytics

A common request for marketers is to better understand their audience, web visitors and customers. But that’s tricky when Google Analytics (GA) doesn’t report on unique user information. The purpose of this blog post is to show you how this can be accomplished. We will expose you to concepts and functionalities which when implemented, will add a new way of segmenting some of your report data: by Unique Visitor ID.

GA currently provides an out of the box dimension called Users which can be used to segment report data but it has serious limitations. For one thing, Users, when used as a dimension in a report isn’t persistent across sessions. The method provided in this guide is. In other words, the ID you’ll be generating for each user to your site will stay the same for each visitor on subsequent returning visits. This solution can be customized to allow you to match a unique ID in GA with user data from your own back-end database or CRM system. It should also be noted that the GA User dimension isn’t as versatile is a custom dimension. For example, our unique ID can be used in a User Flow analysis while the GA User dimension can’t be.

The bottom line is that a unique visitor identifier was never exposed in GA. This in turn limited segmentation capabilities. We’re now overcoming this limitation. Seeing as there’s no shortage of how-to guides out there, I will emphasize a bit more on the Why [things are done in a particular manner] rather than the How-to aspect. It’s also a habit I have when providing classroom training, focusing as much on concepts as on methodology.


You will need a Google Analytics Account with a web property using Google Tag Manager to follow along as well as a cup of tea or coffee. This post assumes you have some degree of familiarity with GA, GTM and you know how to prepare a hot beverage.


First let’s get the obvious out of the way. The accuracy and reliability with which we track individuals across sessions depends on the method we use to identify those visitors. This means that in the context of persistent cookies, the term Visitor doesn’t carry the same weight as when we use a Login User ID to track our visitors.

For the purpose of this little tutorial, I will use a persistent cookie value to uniquely identify our visitors. It’s not as good as a Login User ID, but its reliability is generally deemed acceptable in the analytics community and it’s simple enough to implement. Towards the end of this post, in the Next Step section, I broach on some additional options regarding user identification.


Google prohibits sending Personally Identifiable Information (PII) to Google Analytics (GA). That’s it. Any unique identifier that doesn’t identify a person or device will do. For the purpose of this exercise we will be generating a persistent cookie with a unique string that will serve as the cookie value and as visitor identifier. If your endgame is to correlate unique IDs in GA with your own internal data, CRM data for example, you’ll want to use an ID generated by your own internal database or CRM or whichever, so you can match it with your own data down the road.


The first thing we’ll want to do is set up a custom dimension in GA. In the GA Admin tab, in the list of features pertaining to your GA Property, find the Custom Definitions and select Custom Dimensions. At this point, if you’re wondering “should I click on it?” you might enjoy checking this out first.

Create a new custom dimension and give it a name such as Unique ID for example. The scope should be Session and we’ll definitely want this custom dimension Active. The reason there’s an option to have our custom dimension Active is that you can’t delete a custom dimension once it’s been created. You can re-purpose it by modifying it or you can simply deactivate it, if and when you’re no longer using it.

You might or might not be wondering why we selected Session and not User as a scope since we specifically want to track individual users across visits. When selecting User, GA looks for its own User-ID so if you’ve enabled the GA User-ID feature in your property then by all means, select the User scope. I didn’t want to make any assumption which is why I suggested the Visit scope. It’ll work either way and is adequate for our little exercise.

A word about the GA User-ID feature. Say your site has a web and a mobile version and let’s pretend a user navigates your site from their computer and then switches to their tablet to continue their visit and then to their phone where they’ll probably be looking at the mobile version of your site. The GA User-ID is how GA will track this visitor’s activity across all platforms and devices. The thing is it’s all happening behind the scenes so we can’t use this User-ID feature by itself in our reports, hence the use of a custom dimension.


Now let’s go into GTM and find the Universal Analytics tag that has the Tracking ID and ties into our GA property. If you don’t know what I’m talking about, you’ll probably enjoy reading this first and if you’re wondering if GTM is worth the learning curve, the short answer is: so worth it!

Once you’re inside the tag, select the Configure Tag section by clicking on it. You now have two options which will achieve the same goal. What we want to do is populate the custom dimension we just created in GA with some data, specifically a unique ID for each visitor. We can do that by either using a custom field in the Fields to Set area or by adding a custom dimension in the Custom Dimensions area located just below the Fields to Set. All of this happens under the More settings accordion view and that’s located directly below the Track Type option. I’m getting pretty confused re-reading all of this and I’m the one writing it so just this once I’ll provide a screenshot but don’t get used to it!


Did you notice the {{UA-FPC}} inside the Value field?

That’s a variable (GTM used to call it a Macro) which we have to go create first then we’ll come back into the tag and finish setting up our custom dimension. This variable will hold our unique ID however we chose to generate it.

So let’s leave the tag for now and go to the Variables section. You may discard the changes or not. It doesn’t matter since we still have to publish our modifications for any of them to take effect so there’s no problem saving our work “in progress.” In the Variables section, we’ll want to create a Custom JavaScript Variable and all you need to do here is copy-paste the code below into the Custom JavaScript code window and click Save.

function () {
function genID () {
var d = new Date().getTime();
var nuid = ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx’.replace(/[xy]/g,function (c) {
var r = (d + Math.random() * 16) % 16 | 0;
d = Math.floor(d / 16);
return (c == ‘x’ ? r : (r & 0x3 | 0x8)).toString(16);
return nuid;
if (/(^|;)\s*userid=/.test(document.cookie)) {
function readCookie(name) {
name += ‘=’;
for (var ca = document.cookie.split(/;\s*/), i = ca.length – 1; i >= 0;i–)
if (!ca[i].indexOf(name))
return ca[i].replace(name, ”);
//alert(“Your ID is “+ readCookie(“userid”));
return readCookie(“userid”);
} else {
document.cookie=”userid=” + genID() + “; expires=Thu, 31 Dec 2050 12:00:00 UTC”;

//alert(“This is your first time, “+genID());
return genID();

What this code does is look for the cookie with the unique user ID so it can pass its value to the GTM variable and if it doesn’t find that cookie, it generates it and assigns it a unique ID. That’s pretty much it.

Don’t forget to give your variable a name, otherwise it’ll show up as Untitled Variable in all the drop-down menus across the GTM.


We’re ready to configure our tag now. In the Custom Dimension of our tag, if this is your first declared custom dimension, in the index field, you’ll want to type 1 and in the Dimension Value select the variable you just created. See Figure 1.

The little Image 4 icon to the right of the value field brings up the drop-down menu; your new variable should be in the list. Save it, Publish it, aaaandyou’re done.


Now to validate our work and make sure it’s all coming together nicely. We’ll of course have to wait for traffic to be generated and come back in 24 hours or in a few days to confirm that the new custom dimension generates adequate data. Incidentally, you’ll probably want to create a simple Custom Report to view data from the custom dimension. How to create a custom report is a bit out of scope with this blog post so here’s a screenshot of what it could look like.


In the meantime, I suggest using an HTTP analyzer to make sure the Google Tag Manager was properly configured and that the right data is being sent to our custom dimension. As far as HTTP analyzers go, I have four suggestions for you:

  • Fiddler, that’s my first choice
  • Fiddler, it’s also my second choice
  • HttpFox, a Firefox extension
  • Google Analytics Debugger, that one’s for Chrome
  • The web dev tool shipped in IE, Firefox, Chrome and Safari will also do

Because browser-based web debuggers work during or after the page has already been rendered, I find that the results can sometimes be misleading which can lead to drawing the wrong conclusion. Just sayin’.

Whichever tool you use, you’re looking for a CD1 variable (unless this wasn’t your first custom dimension) which will look something like this:



In terms of matching the custom dimension data in GA with your own, be it from a CRM or any other data repository, remember never to upload any PII in GA. The reason I’m pointing this out again is because GA does provide a means to upload lookup tables for the purpose of matching SKU numbers, for campaign identification or any other type of content but not for user matching. Never for user matching! There is a simple workaround though. Google Chrome provides an extension that allows you to use a CSV file, stored locally on your computer, to match unique IDs in GA with your own data. It’s actually called: PII Viewer for Google Analytics. Other options include Google Big Query which will allow you to slice and dice all the log data from your Google Analytics reports, disaggregated, in a data analysis environment using SQL-like query language. Exporting GA data is another option, either through CSV exports from the web UI or by using the Google Analytics API.


Tracking individual IDs in GA creates opportunities to further improve your insights into visitor behavior and get freaky with your GA data by giving you a new visitor-based dimension to segment your traffic by. You also now have a prototype for correlating user IDs in GA with your own back-end data. Let me know what questions or comments you have.

Leave a Reply

Your email address will not be published. Required fields are marked *

Explore Posts By Category



Want to know more?

Contact us