Note: This post originally appeared on the blog of my since-shuttered analytics firm: Axiomatic. That said, if you need some analytics work, get in touch

Hi again. Earlier, we talked about Google Analytics' Custom Alerts and this week we're going to dive into another dark, dank corner of GA customization - Custom Dimensions.

In the Universal Analytics, Custom Dimensions are a replacement of sorts for the older system's custom variables - they allow you to tag hits, sessions, user and the like with extra bits of data that you can then use for later segmenting and analysis.

What you can do with them

I've been digging into Custom Dimensions quite a bit lately and they've sparked some ideas like the below:

  • Running a SaaS application and want to segment your marketing analytics just to visitors who aren't already customers? Set up and use a custom dimension that tags your application's existing userbase.
  • Have different types of users who might be using your application or site differently? Set a custom dimension for their customer type and you can segment away.
  • Want to run some retention analysis on how long users stick around and use your product? Tag them with their start week in a format such as 23-2014 (where 23 is the week of the year) and you're off to the races.
  • Running on many different sites/platform or tracking both your main application and embeds through the same GA account? Set a dimension for that platform so you can see how the different environments affect usage.
  • Want to know which visitors buy which editions of your ebook package? You can set a product-scoped dimension and get breakdowns of sales by product category (and then further segmented by referral source or campaign. Nifty!).

And so forth. Essentially, any time there's some extra piece of data it'd be handy to have when analyzing your Google Analytics data, you can stick it in a Custom Dimension to have it available in the GA interface just like any other first-class dimension.

How to set them up

You can manage custom dimensions from the Admin area of Google Analytics. They're listed under Custom Definitions in the Property column.

The next page lists any dimensions you've already setup and includes the familiar big, red create button to make a new one.

Then you'll get the short form above (I've already expanded the drop-down menu for you).

The name is completely arbitrary, but will show up in the GA interface menus and such. Make it something descriptive about what it is you're attempting to measure.

Next comes scope and you have four options:

  • Hit: Associates that bit of data just with the ping you sent to GA. It doesn't stick around for anything else at all. But if, for instance, you have a pricing page with multiple sections and want to track where deep links might be landing using anchor tags - hit-level scope might be the way to go.
  • Session: Tags along for all the interaction for that particular session. This is the scope I use most frequently because sessions tend to be a more-reliable metric than users/visitors (more info). If the data is about a particular session on your site, this is the route to go.
  • User: Will track GA's idea of who the user is (if you want more detail on how GA does that, mash the reply button) and tie the dimension to them all along the way. We just mentioned above that any analytics package's sense of "visitor" or "user" is inherently flawed, which is why I tend to avoid User. If you're in an environment where a) users are going to be on one device for your site and b) users are extremely unlikely to clear cookies, then you can rely on User-based metrics. For everyone else, those numbers can get funky - especially if you take the linked doc's advice and just tag them once when they enter the bucket.
  • Product: This one's mostly relevant if you're doing e-commerce tracking. Essentially, it allows you to tag extra metadata to the product you're selling at time of sale.

To recap: In almost all cases, you're going to want Hit or Session scope. Use Hit for metadata about an interaction and Session for metadata about a user.

After you have the dimension set up, you need to start sending that data to Google Analytics, naturally. And after it's created, GA will provided you with some handy-dandy code samples.

var dimensionValue = 'SOME_DIMENSION_VALUE';
ga('set', 'dimension1', dimensionValue);

And that's pretty much it. One quick note, though: Because custom dimension work by adding extra parameters to the tracking calls, this need to be in code before you actually trigger the analytics call. Take our standard code embed below:

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-55900826-1', 'auto');
  ga('send', 'pageview');

</script>

In order for our custom dimension to fire, we'd need to nestle it right between the ga('create'...); and ga{'send'...); lines, giving us something like the below:

<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','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-55900826-1', 'auto');
  var dimensionValue = 'SOME_DIMENSION_VALUE';
  ga('set', 'dimension1', dimensionValue);
  ga('send', 'pageview');

</script>

If you're doing any sort of event tracking and the like, keep in mind that dimension values need to be set before you fire the associated tracking event.

Reporting

Once you have data flowing in, our custom dimensions are first-class reporting citizens, available anywhere you'd like to segment or report on.

However, as far as I can tell, you're not going to find a report or dashboard for them in the primary navigation.

Instead, you'll have them available for segmenting and reporting. Below, for instance, is the segment creation screen.

They're also available in the main interface as secondary dimensions.

All this means is that you can use your new custom dimensions just like you would any other: You can trigger custom alerts, generate custom reports, create segments using them and ultimately export them.