Shopify - Content Grouping for GA4 / GTM

Learn how to automatically tag Shopify pages with content groupings for richer GA4 reporting and better user behavior insights.

Ceyhun Enki Aksan
Ceyhun Enki Aksan Entrepreneur, Maker

In the article titled “GA4 Property Content Grouping”, I explained how to send content grouping information to Google Analytics 4 properties using the Global Site Tag and Google Tag Manager. Accordingly, I prepared a snippet tailored to the Shopify store template structure, enabling Shopify page URLs to properly pass the GA4 content_group dimension.

The Shopify template object provides us with information about which template type the displayed page is associated with within the templates directory of its theme. This allows us to monitor and control page-level and page-specific behaviors, as well as reconfigure them accordingly.

PagePage PathDirectoryContent Group
Home/Home
Contact/pages/contact/pagesPages/Contact
Search/searchPages/Search
Blog/blogsBlogs
Blog Category/blogs/category/blogsBlogs/Category
Collections/collections/collectionsCollections
Singular Collection/collections/collection/collectionsCollections/Collection
Products/products/collectionsCollections
Singular Product/product/productsCollections/Collection/Product
Singular Product with Variant/product/productsCollections/Collection/Product/Variant

We can generate reports and analyses by grouping the pages displayed in GA4 reports under specific categories, providing insights and context based on page and content types. The Shopify Content Grouping snippet uses these details to pass content to GA4 according to a specific directory structure. The content group information passed is as specified in the Content Group column.

<script>
  dataLayer.push({
    'content_group': '{{- contentGroupInfo -}}'
  });
</script>

The page group information is passed as the contentGroupInfo value to the content_group field and becomes accessible via the dataLayer.

The following code snippet can be added into the theme.liquid file, or alternatively included as a snippet for better code organization and invocation.