Creating Content Group in Google Analytics via tracking code using gtag.js

This article is in conjunction with the article Introduction to Content Grouping in Google Analytics where I introduced the concept of ‘Content Grouping’ and ‘Content Groups’.

In this article, I will show you, how to group web pages on your website to create content groups by using the ‘Group by Tracking Code’ method.

What is ‘Group by Tracking Code’

You can add a line of code to your Google Analytics Tracking Code to identify web pages and make them a part of the content group.

This method is called ‘Group by Tracking Code’ in Google Analytics.

You can see this method while creating/editing ‘Content grouping’ (Admin >’ View’ column > Content Grouping):

content grouping 1

group by tracking code

Use the ‘Group by Tracking code’ method for creating content groups:

#1 If you are comfortable making code changes on your website and you understand the Google Analytics development environment and/or if you know/hire someone who does.

#2 You want to create very robust content groups that can withstand any change made to the URLs and/or title tags of the web pages which are part of the content groups.

#3 If you have got web pages whose titles or URLs are too hard or impossible to capture via regular expression (‘group using extraction’ method) or rule sets (‘group using rule definitions’ methods).

#4 If you want to make sure that the same web page is not included in multiple content groups.

The ‘Group by Tracking Code’ is my favourite method for creating content groups in Google Analytics because it is very robust.

Introduction to ‘Index number’

In the context of ‘Content Grouping’, an index number can be any number from 1 to 5.

Google Analytics internally identifies a ‘content grouping’ through its index number and not by its name.

Since in GA, you can create only five ‘content groupings’ per reporting view, the value of an index number can only be one of the numbers from 1 to 5.

  • An index number of ‘1’ corresponds to the first ‘content grouping’ which is denoted by ‘content_group1’.
  • An index number of ‘2’ corresponds to the second ‘content grouping’ which is denoted by ‘content_group2’.
  • Similarly, an index number of ‘5’ corresponds to the fifth ‘content grouping’ which is denoted by ‘content_group5’.

Ideally a ‘content grouping’ like first ‘content grouping’ should be denoted by ‘content_grouping1as ‘content grouping’ and ‘content group’ are not one and the same thing.

But this is not the case. Google is confusing you here. So beware.

In order to see the index number of a content grouping, navigate to the ‘Admin’ section of that GA view for which you created ‘content groupings’ and then click on ‘Content Grouping’ link:

content grouping link 1

You can now see the index number assigned to each ‘content grouping’:

content grouping index number

Now, if you want to create a new ‘content grouping’ then do not use the index number which is already in use. Otherwise, your web pages may be assigned to the new content grouping.

These index numbers act as slots and you can put only one content grouping at a time to these slots.

attribution modelling

Get the E-Book (52 Pages)

62 point checklist

Get the E-Book (50 Pages)

Making a call to an index number

If you want to refer to a ‘content grouping’ within your code then you would need to make a call to its index number.

For example, if the name of your content grouping is ‘Men Clothing’ then first identify its index number and then make a call to this index number, from within your code.

You can make a call to an index number by using the Google Analytics command called ‘set’ before sending a pageview hit.

This command is also used to create new content groups.

Following is the syntax of the ‘set’ command for creating a new content group within the content grouping (specified by its index number):

gtag(‘set’, {‘content_group<Index Number>‘: ‘<Group Name>‘});

This line of code is added to the Google Analytics tracking code, of all those web pages, which will be part of the new content group:

<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-1123456-78″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-1123456-78’, {‘content_group<Index Number>’: ‘<Group Name>’});
</script>

For example, let us suppose, you want to group all the web pages on your website, which sell men’s shirts into the content group named ‘Men Shirts’

Let us also suppose, that the index number of your content group is 1.

Now in order to create this content group, you would need to make following similar changes, to the Google Analytics tracking code, of all those web pages, which will be part of the new content group named ‘Men Shirts’:

<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-1123456-78″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-1123456-78’, {‘content_group1’: ‘Men Shirts‘});
</script>

Note: Do not call the same index number multiple times on the same web page, like the one below:

<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-1123456-78″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-1123456-78’, {‘content_group1’: ‘Men Shirts‘, ‘content_group1’: ‘Men Trousers‘});
</script>

If you call the same index number multiple times on the same web page then only the last call for the index number will be sent to GA, along with the pageview.

In our case the last call would be:

gtag(‘set’, {‘content_group1’: ‘Men Trousers‘});

So the web page where you put this code will belong to the ‘Men Trousers’ content group and not to ‘Men Shirts’ content group. 

Remember when you use the ‘Group by Tracking Code’ method, you can assign only one ‘content group’ at a time to a web page.

Note:

<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-1123456-78″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());

gtag(‘set’, {‘content_group1’: ‘Men Trousers’});
gtag(‘config’, ‘UA-1123456-78’);
</script>

is same as:

<!– Global site tag (gtag.js) – Google Analytics –>
<script async src=”https://www.googletagmanager.com/gtag/js?id=UA-1123456-78″></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag(‘js’, new Date());
gtag(‘config’, ‘UA-1123456-78’, {‘content_group1’: ‘Men Trousers‘});
</script>

You can use either ‘set’ command or ‘config’ command to set up content group in GA.

Steps to create content groups in GA via the ‘Group by Tracking Code’ method

Follow the steps below to create content grouping and corresponding content groups in GA via the ‘Group by Tracking Code’ method:

Step-1: Decide the names and number of content/product categories which you will use as ‘content grouping’ in your GA reporting view.

Step-2: Decide the names and number of content/product sub-categories which you will use as ‘content groups’ in GA for each ‘content grouping’.

Step-3: Identify all of the web pages which will be part of each ‘content group’.

Step-4: Navigate to the ‘Admin’ section of your GA view and then click on ‘Content Grouping’ link:

content grouping link 1

Step-5: Click on ‘New Content Grouping’ button:

new content grouping button

Step-6: Name your content grouping and then click on the ‘Enable Tracking Code’ link as shown below:

enable tracking code

Step-7: Select the index number for your new content grouping from the ‘Select Index’ drop-down menu:

index menu

Note: Do not use the index number which is already in use.

Step-8: Modify your Google Analytics tracking code according to the snippet you see and the way I explained earlier:

enable tracking code 1

Step-9: Click on the ‘Done’ button. At this point you can choose to use other methods (‘Group using Extraction’ and ‘Group using rule definitions’) to create more content groups, or you can simply click on the ‘save’ button:

save button

Using different methods for creating content groups for a particular content grouping

You can use any or all of the following three methods at the same time to create different content groups within a content grouping:

  1. ‘Group by Tracking Code’
  2. ‘Group using Extraction’
  3. ‘Group using rule definitions’

However, when you use more than one method at a time, to create content groups, GA executes different methods, in the following order:

#1 ‘Group by Tracking Code’ method is executed first for creating a content group.

#2 ‘Group using Extraction’ method is executed second.

#3 ‘Group using rule definitions’ method is executed last.

order of

Within ‘Group using rule definitions’ method, GA executes various rules from top to bottom:

group using rule definitions 1

You can drag the rules up and down to change the order in which they should be executed by GA.

Related Article: Google Tag Manager Content Grouping Setup Guide

Other articles on specialized tracking in Google Analytics

  1. Google Analytics Ecommerce Tracking Tutorial
  2. Google Tag Manager Event Tracking Tutorial
  3. Google Analytics Event Tracking Tutorial
  4. Google Analytics Store Visits Tracking Tutorial
  5. Offline Conversion Tracking in Google Analytics – Tutorial
  6. Ecommerce Tracking Google Tag Manager (GTM) – Tutorial
  7. Tracking Virtual Pageviews in Google Tag Manager – Tutorial
  8. Google Tag Manager YouTube Video Tracking
  9. How to unlock not provided keywords in Google Analytics?
  10. Google Analytics Virtual Pageviews Tutorial
  11. Google Analytics and YouTube Integration Tutorial
  12. Google Analytics for Facebook Tutorial
  13. Cross Domain Tracking in Google Analytics – Complete Guide
  14. How to use two Google Analytics codes on one page
  15. The one thing that you don’t know about PayPal.com and the referral exclusion list
  16. Google Analytics Calculated Metrics – Tutorial
  17. Creating your own Google Analytics Tag Auditing System
  18. Google Tag Manager Search Tracking without Query Parameter
  19. Tracking Google Analytics Paypal Referral and other payment gateways
  20. How to Track Phone Calls in Google Analytics – Call Tracking Tutorial
  21. How to track leads in Google Analytics via CRM
  22. Postbacks in Google Analytics Explained
  23. Subscription & Recurring Revenue Analytics in Google Analytics
  24. Track the Impact of Google Analytics Cookie Consent on Website Traffic
  25. Tracking Offline Conversions in Google Ads
  26. Implementing Scroll Tracking via Google Tag Manager
  27. Scroll Depth Tracking in Google Tag Manager – Tutorial
  28. Site Search Tracking In Google Analytics Without Query Parameters
  29. Google Tag Manager Youtube Video Tracking via YouTube Video Trigger
  30. How to Correctly Measure Conversion Date & Time in Google Analytics
  31. Google Analytics Social Tracking – Twitter, Facebook, Google Plus and LinkedIn
  32. Cross Domain Tracking in Google Analytics – Complete Guide
  33. Google Analytics Linkedin & Twitter Tracking
  34. Google Analytics Site Search Tracking via Query Parameters
  35. Google Analytics Site Search Tracking Tutorial
  36. Creating and Using Site Search Funnel in Google Analytics
  37. Learn to Setup Facebook Pixel Tracking via Google Tag Manager
  38. AMP Google Analytics Tracking – Learn to track AMP pages
  39. Setting up Sales Funnel across websites in Google Analytics
  40. Regex Google Analytics & Google Tag Manager – Tutorial

Register for the FREE TRAINING...

"How to use Digital Analytics to generate floods of new Sales and Customers without spending years figuring everything out on your own."



Here’s what we’re going to cover in this training…

#1 Why digital analytics is the key to online business success.

​#2 The number 1 reason why most marketers are not able to scale their advertising and maximize sales.

#3 Why Google and Facebook ads don’t work for most businesses & how to make them work.

#4 ​Why you won’t get any competitive advantage in the marketplace just by knowing Google Analytics.

#5 The number 1 reason why conversion optimization is not working for your business.

#6 How to advertise on any marketing platform for FREE with an unlimited budget.

​#7 How to learn and master digital analytics and conversion optimization in record time.



   

My best selling books on Digital Analytics and Conversion Optimization

Maths and Stats for Web Analytics and Conversion Optimization
This expert guide will teach you how to leverage the knowledge of maths and statistics in order to accurately interpret data and take actions, which can quickly improve the bottom-line of your online business.

Master the Essentials of Email Marketing Analytics
This book focuses solely on the ‘analytics’ that power your email marketing optimization program and will help you dramatically reduce your cost per acquisition and increase marketing ROI by tracking the performance of the various KPIs and metrics used for email marketing.

Attribution Modelling in Google Analytics and BeyondSECOND EDITION OUT NOW!
Attribution modelling is the process of determining the most effective marketing channels for investment. This book has been written to help you implement attribution modelling. It will teach you how to leverage the knowledge of attribution modelling in order to allocate marketing budget and understand buying behaviour.

Attribution Modelling in Google Ads and Facebook
This book has been written to help you implement attribution modelling in Google Ads (Google AdWords) and Facebook. It will teach you, how to leverage the knowledge of attribution modelling in order to understand the customer purchasing journey and determine the most effective marketing channels for investment.

About the Author

Himanshu Sharma

  • Founder, OptimizeSmart.com
  • Over 15 years of experience in digital analytics and marketing
  • Author of four best-selling books on digital analytics and conversion optimization
  • Nominated for Digital Analytics Association Awards for Excellence
  • Runs one of the most popular blogs in the world on digital analytics
  • Consultant to countless small and big businesses over the decade
error: Alert: Content is protected !!