Custom Content Grouping in Data Studio
Read Time: 7 Minutes

Custom Content Grouping in Data Studio

16 Nov, 2021 Read Time: 7 Minutes
Published by
Nick Hood
Director of Analytics
Inspire Inform Ignite

When providing a top-level overview report on website traffic, it's common to want charts that show basic traffic counts to key areas of the site. Say you have a website with 100 unique pages that sit within 5 key site sections, while understanding traffic to each of these pages is certainly valuable, it is also useful to see as a group, which broader areas of the site users are engaging with.

There isn’t currently an “out of the box” report in Google Analytics that can show you this but It can be achieved through the use of segments, manually creating charts or perhaps the best option, by defining Custom Content Groupings.

Custom content groupings allow you to allocate a set of pages to a logical grouping and then report on them in Google Analytics as a collective. E.g. all pages where the path contains /blog we’ll group as Blog, all pages that contain /shop we’ll group as Shop. You can then view your standard Google Analytics reports using this grouping as the Dimension.

Custom channel grouping in GA

One of the major drawbacks of Custom Content Groupings is that they only take effect from the date you define them, so if you want to go back and review historic data under custom channel groupings you’re out of luck. Fortunately, Google Data Studio has a solution that will allow you to define content groups and apply them to all your historic data.

Setting Custom Content Groupings in Google Data Studio

With your G.A data connected to your Data Studio report click the Edit data source pencil alongside your data source.

Edit data source in Data Studio

This will bring up a table of all the fields in your Database. Click the plus icon towards the top of the table to create a new calculated field.

Create new field in Data Studio

Give the field a name. We will call this one Content Groups.

Calculate field name in Data Studio

Then we add our calculation into the formula field. For this calculated field, we are going to use the Case Statement function which lets you write if x then y type rules. So we’re going to say if a page path contains x, put it in content group y.

The basic format for this calculated field is:

CASE WHEN (Page = “/page-type”) THEN “Group name” ELSE “Other” END

We have a few options for how we do the page matching. The main ones we’ll be using are the simple if page=”this” or page =”this” then “content group”  and REGEXP_MATCH for grouping things based on Regular Expression.  The page= method is mostly useful if your matching one or two pages. E.g. In our example, we want to group just the homepage in a group called Home, so we would do:

CASE WHEN (Page=”/”) THEN “Home” ELSE “Other” END

If you had two urls that matched the homepage you could do:

CASE WHEN (Page=”/” OR Page=”/index”) THEN “Home” ELSE “Other” END

We will then use REXEXP_MATCH to match our site sections based on their page path, I'll separate the components out so it's easier to read e.g.:


WHEN (Page=”/”) THEN “Home”

WHEN (REGEXP_MATCH(Page, '.*who-we-are.*')) THEN “About us”

WHEN (REGEXP_MATCH(Page, '.*blog.*')) THEN “Blog”

WHEN (REGEXP_MATCH(Page, '.*what-we-do.*')) THEN “What we do”

WHEN (Page=”/contact-us”) THEN “Contact”

ELSE “Other”


So using this statement we will define six content groups Home, About Us, Blog, What we do, Contact and Other.

The format for the REGEXP_MATCH is:

(REGEXP_MATCH(Dimension, ‘regex’)) THEN “Grouping Name”

Dimension = the name of the dimension you are wanting to match against, for our example we’re using Page, but this could also be used for Source/Medium, Device Type, Previous Page Path etc

Regex = The regular expression that will match the items you want to include in the group, in our example we’ve set it to match against our page paths with any character before or any character after, so any path that contains the string we’ve included.

Grouping Name = The label you’re defining for the group. It doesn’t need to match anything, just type in what you want it to be called.

So now that we have our CASE statement we'll insert it into the Formula field in our calculated field.

IMPORTANT TIP! Always keep a copy of the formulas in a txt file, because it looks like once the string gets to a certain length, while it will still work if you try to go in to edit the formula later the tail end gets cut off and you end up losing half your statement.

Now that our formula is set, we click Done, go back to our dashboard and add a new chart and our newly created field will be available for selection in the Dimensions drop panel.

It should appear under the Default Groups header under the name we’ve given it.

Dimension picker in Data Studio

We then select our Metric which in this case is Pageviews.

And we now have a nice simple bar chart that shows us our pageview counts by site section

Bar chart channel group

Or maybe a pie

Pie chart channel group

Or just a table

table chart channel group

There are a bunch of other great uses for this function, most notably Custom Channel Grouping, but even for things as simple as giving your report items friendly labels e.g. CASE WHEN(Page="/website-section/products/application-process/application-step1") THEN "Product Step One". Rolling out the Content Groupings to the previous and next page dimensions also provides some great opportunities for simplified "User journey" reporting which I will expand upon in my next blog.


Share this article
Further learning
Blog Posts
24 Dec, 2021
In the many years we have been setting up tracking for our clients, the standout and one of the most requested tasks has to be form submits or, as we like to...
Read More
Blog Posts
01 Dec, 2021
If you have worked with a website that uses iframes then it's likely you have felt the tracking pain points that arise. Generally, you will encounter one or ...
Read More
Blog Posts
25 Nov, 2021
If there’s been one good thing to come out of the last couple of years of Covid, it’s that the restrictions imposed on all our lives have been a boon for...
Read More
Blog Posts
25 Nov, 2021
Lately, I’ve found myself using a number of window functions in BigQuery. They are really handy functions but can be difficult to wrap your head around. In...
Read More
We have trained thousands of people all over the world, helping them learn more and achieve more.