Content Groups is a powerful feature in Google Analytics 4 (GA4) that allows you to categorize your content or e-commerce traffic into logical groups, such as blog categories, page sections, products, or article types, for better performance analysis across different content themes.
When using WordPress as your CMS, leveraging built-in categories is a logical way to group content. This guide walks you through implementing content grouping using WordPress categories, Google Tag Manager (GTM), and Google Analytics 4 (GA4).
Table of Contents
Step 1: Understand How Content Groups Work in GA4
In GA4, content grouping is achieved by creating a custom dimension that can be used in reports to view metrics grouped by your defined logic. Unlike UA, GA4 does not offer a native content grouping setting in the user interface. Instead, you must send a parameter such as content_group
with each event, typically the pageview event.
Step 2: Expose WordPress Categories to the Front End
Google Tag Manager can only access data rendered in the page or exposed via JavaScript. Therefore, you must ensure your WordPress theme outputs the current post’s categories in a format that GTM can access.
Use a Data Layer Push in Your Child Theme
Insert the following snippet into your theme’s functions.php
file to push category data to the GTM data layer:
add_action('wp_head', 'inject_primary_category_data_layer');
function inject_primary_category_data_layer() {
if (is_single()) {
global $post;
$category_name = 'Uncategorized';
// For standard posts, use category logic
elseif ($post_type === 'post') {
// Rank Math's primary category
if ($category_name === 'Uncategorized') {
$rank_math_primary_id = get_post_meta($post->ID, 'rank_math_primary_category', true);
if ($rank_math_primary_id) {
$term = get_term($rank_math_primary_id);
if (!is_wp_error($term) && isset($term->name)) {
$category_name = $term->name;
}
}
}
// Fallback to first assigned category
if ($category_name === 'Uncategorized') {
$categories = get_the_category($post->ID);
if (!empty($categories) && !is_wp_error($categories)) {
$category_name = $categories[0]->name;
}
}
}
// Output the result to the dataLayer
echo "<script>
window.dataLayer = window.dataLayer || [];
dataLayer.push({
'postCategory': '$category_name'
});
</script>";
}
}
On my site, I use Rank Math to set a primary category for my articles, and I want to use that category in my analytics reporting. If Rank Math isn’t installed or the primary category isn’t set, I use the first selected category.
Step 3: Create a GTM Variable to Capture the Categories
In Google Tag Manager:
- Go to Variables > New
- Choose Data Layer Variable
- Name it
Post Categories
- Set Data Layer Variable Name to
postCategory
- Click Save

This variable will now pull in the array of categories pushed to the data layer.
Step 4: Modify your GA4 pageview tag to include the content group
- Go to Tags and locate your GA4 Configuration Tag
- Under Fields to Set, click Add Row
- Field Name:
content_group
- Value:
{{Post Categories}}
- Save the tag and publish your container

This ensures that every pageview event includes the content_group
parameter, which is set to the WordPress post’s primary category.
Step 6: Register a Custom Definition in GA4
- Click the Admin gear icon in the lower-left corner.
- In the Property column, click Custom definitions.

- Click the Create custom dimension button.
- Fill in the fields:
- Dimension name: For example,
Content Group
- Scope: Select
Event
- Description: Optional, but something like “Post Category”
- Event parameter: Enter the exact parameter name you’re passing via GTM—in your case, it should be:
content_group
- Dimension name: For example,

- Click Save
Now GA4 will recognize and store the content_group
parameter for reporting purposes.
Step 7: Build Reports Using the Content Group Dimension
After data starts flowing (this can take up to 24 hours):
- Go to Explore > Free Form in GA4
- Add
Content Group
as a dimension - Add metrics like Views, Average Engagement Time, or Conversions
- Segment or filter based on Content Group to analyze performance by category
Here’s a great walkthrough of Google Analytics 4 dimensions, Metrics, and utilization in reporting:
Further Customization
This setup can be easily customized to support other content grouping strategies beyond standard post categories. Examples:
- You can also use the Content Group dimension in standard reports or build a custom dashboard in Looker Studio for more detailed visualizations.
- You could use WordPress tags instead of categories by retrieving them with
get_the_tags()
and pushing the primary tag to the data layer. - For custom post types, you might assign the post type name itself as the content group, or use a custom taxonomy term associated with that type (retrieved via
wp_get_post_terms()
). - WooCommerce product categories can be handled similarly using the
'product_cat'
taxonomy, allowing you to group sales or product views by category.
Using WordPress categories for content grouping in GA4 is an elegant and scalable approach. By leveraging GTM’s flexibility and WordPress’s structured taxonomy, you can generate actionable insights into how different types of content perform. This can help you shape editorial direction, refine content marketing strategies, and optimize conversion pathways across your site.
©2025 DK New Media, LLC, All rights reserved | Disclosure
Originally Published on Martech Zone: How to Set Up Content Grouping in Google Analytics 4 for WordPress via Google Tag Manager
