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:
- Group by tracking code (which is what we will be using)
- Group by extraction
- 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:
That little code snippet looks like this (in case you’re curious):
var el = document.getElementsByClassName('blog-category');
var text = (el.innerText || el.textContent); //added .textContent for Firefox.
var category = text.toLowerCase().replace(/ /g,'');
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 swellpath.com, 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.