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:


  // 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);
  // 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
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  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');

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:


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.


abc-123-rst,Albert Cox,,Real Cube,Colombia
abc-123-uvw,Justine Bishop,,You Span,Panama
abc-123-xyz,Paula Smith,,Skinte,Romania
abc-456-rst,Louise Mcdonald,,Meezzy,Turkey
abc-456-uvw,Christopher Burns,,Midel,Algeria
abc-456-xyz,Laura Ruiz,,Zoo Veo,Austria
abc-789-rst,Julie Ramirez,,Meetz,Ukraine
abc-789-uvw,Jimmy Elliott,,TwitterList,China
abc-789-xyz,Amanda Owens,,Avamba,Indonesia
def-123-rst,Denise Stephens,,TagTune,India
def-123-uvw,Betty Watkins,,PhotoBug,"Congo, Republic of"
def-123-xyz,Daniel Rose,,SkipStorm,Djibouti
def-456-rst,Paula Baker,,Blue Zoom,Luxembourg
def-456-uvw,Kevin Arnold,,DynaBox,New Zealand
def-456-xyz,Gerald Black,,Sky Bar,Ukraine
def-789-rst,Donald Dixon,,Trilia,Turkey
def-789-uvw,Julia Tucker,,Centizu,Ascension Island
def-789-xyz,Elizabeth Gilbert,,Kanoodle,Bulgaria
ghi-123-rst,Barbara Ross,,DigiTube,Gambia
ghi-123-uvw,Rose Oliver,,Vitz,Morocco
ghi-123-xyz,Louis Mills,,Skyble,Bosnia and Herzegovina
ghi-456-rst,Angela Dunn,,WikiBox,Saint Barthelemy
ghi-456-uvw,Anna Ward,,DAB Jam,United States
ghi-456-xyz,Evelyn Simpson,,Rhyzio,Canada
ghi-789-rst,Joe Green,,JA Loo,Kiribati
ghi-789-uvw,Patricia Hayes,,Lazzy,Chad
ghi-789-xyz,Bruce Chavez,,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