Post Image

Can a page belong to multiple categories within Google Analytics 4 content groups?

3 min easy
Mike Booth 23 January 2023
Follow

A quick summary to hopefully save other implementers and marketers the time I spent battling Google’s poor documentation and countless misleading blogs on this subject.

Short answer: no, there is no way to assign a page to multiple categories within a content group

Lots of blog posts indicate that a page can belong to multiple categories, but they’re incorrect. Trust me, I tried.

I exhausted every option, so you don’t have to.

Pages that belong to single categories are easy

If you used gtag.js to add Google Analytics 4 to your website, you may add a single line of code to your gtag snippet, specifying the content group. This does not allow you to declare more than one content group per page hit.

If you used Google Tag Manager to include GA4 on your site, Google’s official advice is to create a REGEX table variable, and populate it with a list of rules for each group. You may include a page within multiple categories inside your REGEX table, however it will only register a hit against the first matching rule/category.

The best workarounds

If you used gtag.js

If you used the traditional gtag.js to install Google Analytics 4 on your site, you can easily stack multiple groups together with a delimiter. For example, you could add this snippet within the <script> tags of your gtag at the top of your page

<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);} gtag('js', new Date());
gtag('config', 'UA-1234567-8');
gtag('set', 'content_group', 'womens_clothing|outdoor_clothing');
</script>


This will result in some hits showing up in Google Analytics registered to the ‘womens_clothing’ category, some registered to ‘outdoor_clothing’, and some to ‘womens_clothing|outdoor_clothing’. As such, to report on all hits to ‘womens_clothing’ pages, you’d need to set your report filters to ‘includes  womens_clothing|outdoor_clothing’, not an exact match.

Depending on the number of categories, this could result in a large numebr of ‘combined’ categories, contrary to Google’s guidance. This could also slow down your GA reports considerably.

If you installed using Google Tag Manager

If you used Google Tag Manager to install Google Analytics 4, and have pages that belong to multiple categories, my recommendation is to forget about content groups altogether. Just use custom dimensions instead. This is the solution I’ve gone with in the end: simply fire the script a little like multiple times on each page, once for each category. It can go anywhere on the page,

<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  'event': 'page_category',
  'business_unit': 'womens_clothing'
});
</script>

<script>
window.dataLayer = window.dataLayer || [];
window.dataLayer.push({
  'event': 'page_category',
  'business_unit': 'outdoor_clothing' });
</script>

Of course you will then need to register configure Google Tag Manager and Google Analytics to recognise your custom dimension. For that I’d recommend this fantastic guide, which is easy to follow.