Useful custom dimensions to send to Google Analytics for added context

Here are 5 additional details to send as custom dimensions into Google Analytics to help you get more context into your reports. They can come in very useful when evaluating stickiness, campaign efficiency as well revisit behaviour. I recommend sending these dimensions every time data is sent to your GA account(s).

1. ClientID

This is the value of the _ga cookie for your website in each browser being used to access your site. This is a wonderful custom dimension to get a sense of how individuals behave on your site.

Here’s a snapshot of this dimension in a custom report along with number of sessions and number of actions the clientIDs took. This is really handy for evaluating all kinds of site behaviour specific to users.

More about this dimension can be found in this earlier post: How are users tracked in Google Analytics and how else to use this tracker

To track this: Create a client_ID custom dimension with a user scope. For instructions on how to set-this up using Google Tag Manager, follow this link.

2. Referrer-URL

Knowing the URL of the previous page before any hit can be extremely useful when better understand conversion as well as landing pages.

To track this: Create a referrerURL custom dimension with a hit scope. In Google Tag Manager, create a javascript variable with the value ‘document.referrer’ and have this included every time data is sent.

Note: Referrer information will not be passed from a https domain to a http domain so you have to have SSL on your site. (no-referrer-when-downgrade – not sent to less secure destinations (HTTPS→HTTP)) See this link for detailed explanation.

3. Timestamp

This dimension can be very useful for sorting report by time sequence. Take a look at the example below where I’ve sorted a series of event actions by timestamp. If I add another report column for page URL, I can get a pretty clear idea of the journey this user made to get to the contact action.

Follow this link for instructions and the code snippet needed for this.

To track this: Create a timeStamp custom dimension with a hit scope. In Google Tag Manager, create a custom javascript variable following the instructions in the link above.

4. Number of pages viewed (multiple sessions)

Have you wondered how many pages your users click through before making a conversion? The number of pages a visitor has viewed (over multiple visits) can be tracked with this handy code stored in the local storage of browsers.

Note: the solution shared below stores this page count number in the local storage of browsers and not via a cookie.

This dimension is useful for evaluating site / content stickiness. Take a look at the example below where I’m matching clientID with page counts to see how many times a user keeps coming back. Combined this event report with page URLs to get a clear idea of pages that have good engagement.

To track this: Create a page_count custom dimension with a hit scope. Then move on to step 4A and 4B.

Step 4A: To count pages viewed, the code snippet shared below should be include on every page in the <head> </head>tags.

<!-- start viewed-pages count local storage -->
<script>if (localStorage.viewpagescount)
 {
 localStorage.viewpagescount=Number(localStorage.viewpagescount) +1;
 }
else
 {
 localStorage.viewpagescount=1;
 }
;
</script>
<!-- end viewed-pages count local storage -->

Step 4B: Use this code snippet to retrieve the value from local storage and store it as a custom javascript variable using Google Tag Manager.

function() {
  var location = localStorage.getItem('viewpagescount');
  return location;
}

Note: Local storage will be cleared when cache & browsing data is deleted.

5. Number of pages viewed (session)

This value counts of number of pages viewed within a session. This is how a sample report looks with this value.

A use-case example: when paired with the count of pages viewed (multiple sessions) + timestamp, it provides clarity to conversion durations or if users convert on their 1 visit.

To track this: Create a session_page_count custom dimension with a hit scope. Then move on to step 5A and 5B.

Step 5A: To count pages viewed, the code snippet shared below should be include on every page in the <head> </head>tags.

<!-- start viewed-pages count session storage -->
<script>if (sessionStorage.sesspagescount)
 {
 sessionStorage.sesspagescount=Number(sessionStorage.sessspagescount) +1;
 }
else
 {
 sessionStorage.sesspagescount=1;
 }
;
</script>
<!-- end viewed-pages count session storage -->

Step 5B: Use this code snippet to retrieve the value from session storage via a custom javascript variable using Google Tag Manager. Then include it as a custom dimension to send to your Google Analytics account.

function() {
  var location = sessionStorage.getItem('sesspagescount');
  return location;
}

Note: Session storage is cleared once a browser session is concluded.

For (4) & (5), you can also get both code snippets insert into every page using one custom HTML tag via Google Tag Manager. Be careful not to overdo the use of custom HTML tags as each injection causes everything to be processed again. The result of multiple custom HTML tags adding code → pages needing to be processed multiple times before it completes loading (longer load times).

Closing Notes

Whether to include these dimensions every time data is sent to your GA account depends on what change / improvement actions you are looking to make on your site & how the perspectives provided by each dimension is useful to decision making. Hopefully the sample report snapshots help give an idea about the potential of these dimensions.

Thanks for reading!