Sending personally identifiable information (PII) to Google Analytics is strictly prohibited, but sending a unique user ID is permitted. This is a tutorial to aide users of the PII for Google Analytics Chrome extension. The extension allows you to map the user ID stored in Google Analytics to locally-stored PII such as name and email address.

The test scenario we're using gives a pseudo-randomly generated User ID to each web page visitor. The "User ID" feature in Google Analytics (Universal Analytics) is currently (April 2014) being rolled out, so in the meantime, we're using a Custom Dimension to store our own "Custom User ID".

This configuration is for testing purposes only and has no real value as meaningful data unless you replace the pseudo-randomly generated User ID with a real user ID from your custom database or CRM.

There are 2 parts to this tutorial:

  1. Create a custom dimension for the "Custom User ID"
  2. Add tracking code to populate the custom dimension

Create a custom dimension for the "Custom User ID"

In Google Analytics, browse to Google Analytics Administration.

  • Select an Account and then a Property within that account
  • Expand Custom Definitions below a selected Property
  • Select Custom Dimensions
  • Click on the Custom Dimension Name button
  • In the Add Custom Dimension screen
    • Type Custom User ID in the Name field
    • Select Visit from the Scope dropdown menu
    • Check the Active checkbox
    • Click the Create button

Congratulations, you now have a Custom Dimension named Custom User ID which is available for use within the Google Analytics interface. Next, you'll need to populate this custom dimension with some data.

Add tracking code to populate the custom dimension

On your test website, add the following Universal Analytics tracking code:

<script>

// IMPORTANT: This is just example data for demonstration purposes to send *something* to GA. Populate your `customUserId` some other way. DO NOT COPY THIS.
var prefix = ['abc', 'def', 'ghi'],
middle = ['123', '456', '789'],
suffix = ['rst', 'uvw', 'xyz'],
random = function() {
return Math.floor(Math.random() * 3);
};

// IMPORTANT: POPULATE YOUR OWN `customUserId` HERE...
// Simple pseudo-random user id - 27 possible values
// This is *just* some "random" text that we're using as userIds. DO NOT COPY THIS.
// You'll need to implement something here linked to your customer database, CRM system, mailing list or whatever you're using
var customUserId = prefix[random()] + '-' + middle[random()] + '-' + suffix[random()]; // e.g. abc-123-rst

// Standard Google Universal Analytics code
(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','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-XXXXXX-Y', {'userId': customUserId}); // If "User ID" feature is available
ga('require', 'displayfeatures');
ga('set', 'dimension1', customUserId); // Set a `customUserId` dimension at page level
ga('send', 'pageview');

</script>

Note that we're storing our customUserId in the custom dimension dimension1. This is assigned back to the Custom User ID configured in Google Analytics. For test purposes, and to ensure that dimension1 is always assigned, we're setting its value on every page view.

As we've specified a Visitor scope for this custom dimension, all visits from a single user will take the last recorded value set as the value for the "Custom User ID" dimension.

If all goes well, you should now see the Custom User ID as a dimension in Google Analytics:

custom_user_id

Next Steps

Having created this tracking code, we have also created a set of sample personas in sample.csv which contains the 27 possible "User ID" values along with some personal information. As I'm sharing this publicly, I'd like to reiterate that these are just made up personas. They are not real people.

sample.csv:

user_id,display_name,email,company,country
abc-123-rst,Albert Cox,acox@realcube.info,Real Cube,Colombia
abc-123-uvw,Justine Bishop,jbishop@youspan.name,You Span,Panama
abc-123-xyz,Paula Smith,psmith@skinte.name,Skinte,Romania
abc-456-rst,Louise Mcdonald,lmcdonald@meezzy.com,Meezzy,Turkey
abc-456-uvw,Christopher Burns,cburns@midel.biz,Midel,Algeria
abc-456-xyz,Laura Ruiz,lruiz@zooveo.biz,Zoo Veo,Austria
abc-789-rst,Julie Ramirez,jramirez@meetz.org,Meetz,Ukraine
abc-789-uvw,Jimmy Elliott,jelliott@twitterlist.biz,TwitterList,China
abc-789-xyz,Amanda Owens,aowens@avamba.edu,Avamba,Indonesia
def-123-rst,Denise Stephens,dstephens@tagtune.mil,TagTune,India
def-123-uvw,Betty Watkins,bwatkins@photobug.name,PhotoBug,"Congo, Republic of"
def-123-xyz,Daniel Rose,drose@skipstorm.biz,SkipStorm,Djibouti
def-456-rst,Paula Baker,pbaker@bluezoom.net,Blue Zoom,Luxembourg
def-456-uvw,Kevin Arnold,karnold@dynabox.net,DynaBox,New Zealand
def-456-xyz,Gerald Black,gblack@skybar.org,Sky Bar,Ukraine
def-789-rst,Donald Dixon,ddixon@trilia.gov,Trilia,Turkey
def-789-uvw,Julia Tucker,jtucker@centizu.name,Centizu,Ascension Island
def-789-xyz,Elizabeth Gilbert,egilbert@kanoodle.mil,Kanoodle,Bulgaria
ghi-123-rst,Barbara Ross,bross@digitube.edu,DigiTube,Gambia
ghi-123-uvw,Rose Oliver,roliver@vitz.org,Vitz,Morocco
ghi-123-xyz,Louis Mills,lmills@skyble.org,Skyble,Bosnia and Herzegovina
ghi-456-rst,Angela Dunn,adunn@wikibox.gov,WikiBox,Saint Barthelemy
ghi-456-uvw,Anna Ward,award@dabjam.net,DAB Jam,United States
ghi-456-xyz,Evelyn Simpson,esimpson@rhyzio.edu,Rhyzio,Canada
ghi-789-rst,Joe Green,jgreen@jaloo.gov,JA Loo,Kiribati
ghi-789-uvw,Patricia Hayes,phayes@lazzy.gov,Lazzy,Chad
ghi-789-xyz,Bruce Chavez,bchavez@eire.org,EireOrg,United Kingdom

The tracking code and the related persona data allows us to demonstrate how PII for Google Analytics Chrome extension would work in a real world scenario. More on that in a future post.

Aside: Users of Google Tag Manager can push data to custom dimensions by following this guide: Custom dimensions with Google Tag Manager