Generating Custom Dimensions from Page Names

Peter O’Neill
Reading time: 3 minutes
22nd October 2015

Note: This post has moved from to Ayima as part of the 2018 acquisition.

Custom Dimensions

I discovered a few months back that you can use Custom Dimensions within Google Analytics filters. This was great as it allowed us to created segmented Views based on session/user level custom dimensions (created using GTM via a Data Layer) for segments like Subscriber Traffic, Free Traffic, Desktop website and Mobile website.

But I had an idea in the back of my mind and finally found an excuse to test it out a couple of weeks ago.

We have a client that we are working with to implement enhanced Google Analytics tracking. Like most organisations, there is a development cycle and the new Data Layer is scheduled to be worked on in a couple of months’ time (ideally it is worked on sooner but we have experienced far longer waits as well). So we were looking for quick wins in the meantime.

Reviewing page names, their core page is a product details page. And the URL includes an ID, a code for the previous page and even the index for the location of this product within the product list on that previous page. All great information but excessive for these page names (they were actually breaking the GA table limit).

Back to my idea. Could we use GA View Filters to create hit level custom dimensions? This client is still on classic GA so can’t create custom dimensions via the code. Only one way to find out.

The current page name uses the structure below. It is not the sort of URL I would construct for SEO purposes but happy to take it for analytics as it was about to become very useful.

/product-<product id>/<source index>/<source description>
e.g. /product-456827/5/hpg

The first step is to create the Custom Dimensions within the Google Analytics configuration. Just enter the name you want to use and leave the scope as Hit (as per the screenshot at the top of this post)

Then you will discover that these custom dimensions appear in the list of dimensions that can be used within the GA View Filters. They are right at the bottom of the list.

Selecting Custom Dimensions in View Filter

To populate these new custom dimensions, you need to create three View Filters. As always, use a good naming convention so it is easy to identify the purpose of the filter. The filter type we need is a Custom Advanced filter.

With this example, Field A needs to be the Request URI (which is the page name). I used a regular expression to identify the page naming convention that I need. A key point in this is to enclose any element that you wish GA to remember within brackets. All three key elements are wrapped in brackets for this example.


Then set the Output Field to the desired custom dimension and populate it with the element extracted from the page name. In this example, we have used $A1 e.g. the first element in brackets within Field A. The other two custom dimensions will need to use $A2 and $A3.

Populating a Custom Dimension using View Filter

Checking the data a day later showed success. The custom dimensions are populated with the product ID, access method and access index values. Through another filter, we even renamed all the product pages to /product-page, bringing the number of unique page names within GA table limits without losing any data.

With custom reports or secondary dimensions, we can now review performance of these pages in more detail than previously possible. All without any need for dev involvement or even the use of Google Tag Manager (and I know you could do all this via GTM but this was easier still). Long term we will do this properly via the Data Layer but short term, a big win with a small amount of work.

Written By Peter O’Neill
Asset 1 Asset 1 Asset 3