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):

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:

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

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.

Get the E-book (52 Pages)

Get the E-Book (37 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:

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

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

Step-7: Select the index number for your new content grouping from the ‘Select Index’ drop-down 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:

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:

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.

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

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

   

EXCLUSIVE FREE TRAINING REVEALS....

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


(even if you are completely new to analytics)


Here’s what we’re going to cover…

#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 Beyond
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.

Himanshu Sharma

Digital Marketing Consultant and Founder of Optimizesmart.com

Himanshu helps business owners and marketing professionals in generating more sales and ROI by fixing their website tracking issues, helping them understand their true customers' purchase journey and helping them determine the most effective marketing channels for investment.

He has over 12 years of experience in digital analytics and digital marketing.

He was nominated for the Digital Analytics Association's Awards for Excellence. The Digital Analytics Association is a world-renowned not-for-profit association that helps organisations overcome the challenges of data acquisition and application.

He is the author of four best-selling books on analytics and conversion optimization:

error: Alert: Content is protected !!