Google Tag Manager: Configuring Content Grouping

I feel like we waited forever for Content Grouping to come to Google Tag Manager, but now that it’s here, it feels great. In this post, I’d like to run through how you are going to configure your Content Groups within Google Analytics and Google Tag Manager, and how you can test to make sure it’s implemented properly.

Before we get started, you’re going to want to identify how you’d group your content into groups that make sense for your site or business. If you’re interested in hearing what Google has to say, they have some lovely documentation at their analytics help portal. For this example, I’ll be creating a Content Group for SwellPath’s blog post categories SEO, Analytics, PPC & Media, Social Media, and News & Events. That way the Analytics team can prove once and for all that they have the most popular blog posts on the site.

Creating the Content Group within Google Analytics

Go ahead and open your Google Analytics account, and head to the Admin section. Click the Content Grouping option for the View you’d like to apply the Content Grouping to.



Once you’ve clicked Content Grouping, you’ll be directed to a page where you can create a new content group. Let’s create a content group by clicking the Create New Content Grouping button.


*As you can tell by the screenshot, there is a limit of 5 groups per view. Not to worry, you can have a large amount of groups within those groups, so you’ll be alright.

Now that we are in our Content Group Settings, let’s name our Content Group, Blog Category.

There are three options for implementing Content Grouping:

  1. Group by tracking code (which is what we will be using)
  2. Group by extraction
  3. Group by rule definitions

You can read-up on the different methods in the Google Help doc I mentioned above, but for this post I’m only going to focus on Group by tracking code.

Go ahead and click Enable Tracking code, and once you do, you’ll see that the code has been enabled.

Note: By default, and because this is our first content group, our index will be 1, but as you add more content groups this will be the place where you can select the index.


If we were going to implement content grouping using Classic Analytics or Universal Analytics, we’d simply copy the respective code, and swap out 'My Group Name' for 'Analytics' (if we were on an analytics blog post page), and we would be done. However that is too much work, and we’ve already implemented Google Tag Manager, so let’s use that.

Go ahead and click Save on the Content Grouping Settings, and head over to your Google Tag Manager container.

Adding the Content Group to Google Tag Manager

Alright, so now we are in our cozy Google Tag Manager container. Let’s go and create a Universal Analytics (beta) tag.

*If you are double-tagging your site using Google Tag Manager, which is recommended, you’d create another Classic Analytics tag too, but for this example I’ll just be using the Universal Analytics (beta) tag.

The reason I’m creating a new tag instead of using an existing tag is because I need the tag to fire only when it meets certain criteria (more in just a sec).

Your new tag should look something like this:


Input our index, which is 1. For our Content Group filed, we’ll be using the macro {{blog category}}. This is actually a Custom Javascript Macro that finds an element on the blog page and returns the text. In our case, this is the blog category.

That little code snippet looks like this (in case you’re curious):

function() {
var el = document.getElementsByClassName('blog-category');
var text = (el[0].innerText || el[0].textContent); //added .textContent for Firefox.
var category = text.toLowerCase().replace(/ /g,'');
return category;

The rule, as you can see in the upper-righthand corner says blog only, and it looks like this:



The rule says, look at the path of the URL i.e. anything after, and if it matches this format /YYYY/MM/blog-post, then fire this tag. A lot of wordpress sites are setup like this.

That’s it for that tag. However, it’s very important to note that we must also add a blocking tag to both our Google Analytics and Universal Analytics pageview tags, otherwise we will end up with double pageviews when visitors are on our blog pages!



Go ahead and create a version, name it. Always name it something. This is the point of version control. Trust me, you’ll thank me when your client is asking when/who pushed a tag when their site broke.

Do the quick Preview & Debug, to make sure it looks alright:



Then go ahead and publish.

Always go and test what you just pushed. Even though Preview & Debug say that you’re good, it’s good to double-check.

One way to check is to use Google Analytics Debugger (a chrome extension), and look at the request getting sent to GA. Does it have our Content Group?


Why yes, yes it does! Now crack-open that beer.


I love Google Tag Manager and Content Grouping. This pairing will provide analysts with a greater understanding of how content is affecting visitor flow – or determining which service has most popular blog category.

Feel free to reach out with questions. Happy to help.

Nicholas Blexrud

Nicholas Blexrud - Sr. Technical Analyst

Nicholas is the Sr. Technical Analyst at SwellPath in Portland, Oregon. He spends tons of time in both Google Analytics and Google Tag Manager, and enjoys helping out folks with technical problems.

6 Responses to “Google Tag Manager: Configuring Content Grouping”

  1. Seth

    Thanks for the tutorial. I tried it, but I cannot get it to work. I get this at the end of the Google Analytics Debugger:

    Running command: ga(create, UA-xxxxxx-x, [object Object]) analytics_debug.js:9
    Creating new tracker: gtm1400360454420 analytics_debug.js:9
    Running command: ga(gtm1400360454420.set, anonymizeIp, ) analytics_debug.js:9
    Running command: ga(gtm1400360454420.set, contentGroup1, ) analytics_debug.js:9
    Running command: ga(gtm1400360454420.set, hitCallback, function (){if(w(a[“”]))a[“”]();else{var c=a[“13″],d=c&&
    c.hitCallback;w(d)&&d()}b()}) analytics_debug.js:9
    Running command: ga(gtm1400360454420.send, pageview) analytics_debug.js:9
    Initializing Google Analytics. analytics_debug.js:9
    Tracking script already loaded. Abandoning initialization.

    I am not using the Blog Only rule, because my Permalink structure doesn’t use dates. Instead, I used a rule to run this on all pages, but only after the page was fully loaded:

    {{url}} matches RegEx .*
    {{event}} equals gtm.dom

    Here’s a sample blogpost:

    Any suggestions?

    Thank you! -Seth

  2. Seth

    Could you please remove my Google Analytics ID number and replace it with UA-###### in the code snippet I submitted?

    Thank you.

  3. Agustín Suárez

    Hi Nicholas,

    Great post! I arrived here after hardly fighting against my content grouping tag. Everything worked fine, but the reports in GA were empty once a “Category” was clicked.

    SO I tried with your piece of Javascript and… tadam!! Everything works. “I just need to get rid of the prefix of my category div and keep the spaces between words” I said to me. So, I modified a little your code. The result: empty reports again, although Group Names are correctly populated :(

    I write down here my code, so you can see that is not hard modified:

    function() {
    var el = document.getElementsByClassName(‘blog-categories’);
    var texto = (el[0].innerText || el[0].textContent); //added .textContent for Firefox.
    var categoria = texto.toLowerCase().substring(3);
    return categoria;

    So, the point can be:

    1.- Google doesn’t like variable names in spanish
    2.- You choosed a variable combination that magically make everything works
    3.- It’s something wrong with the .substring part
    4.- GA have problems to show a pageviews report of a Group name if it was previously “faulty”

    So, for 4, I will wait until tomorrow to see what happens with a “fresh” group name. If I still get the same error, I will seriously think, that 3 is the problem (because I wannot to think that the first 2 possibilities are correct :))

    Any clue?


  4. Agustín Suárez

    Hi Nicholas,

    I can say yet that points 3 and 4 aren’t the reason for this weird behaviour. With a brand new group category, I still got the problem, and it was also present if I remove the substring() part.

    So I resigned myself to use exactly your code, but I said: “at leas, lets put – between the words to make it easier to read”. And how big was my surprise as I started to se some group names with the structure “google-tag-manager-“. I realized, that GTM was sending group names with blank spaces at the end, and maybe GA have problems with that.

    So I ended adding .replace(/^\s+|\s+$/g,”) to my variable and… voilà. Everything looks fine right now.


    • Nicholas Blexrud

      Hey Agustín, glad to hear that everything is working now!

  5. Libera la bestia analítica con Google Tag Manager • Agustín Suárez

    […] Google Tag Manager: Configuring Content Grouping. Nicholas Blexrud. Si para ti es importante realizar una segmentación de tus usuarios por el contenido o categorías que consumen, no puedes perderte esta guía de Nicholas para sacarle todo el partido que la agrupación de contenido de Google Analytics te brinda. […]


Leave a Reply

Loading Facebook Comments ...

Get Our Newsletter

To keep up with the latest news from SwellPath on digital advertising, analytics, and SEO, sign up for our newsletter.