In the past I’ve written in depth about how to create content groupings and why they’re necessary to get the most information out of your website. There are three ways to create content groupings: tracking code, extraction, and rule defining. This article will be using the tracking code method via Google Tag Manager.
- Decide on how you want to group your pages together and what names you want to give the groups
- Create a new content group within Google Analytics by going to Admin> Content Grouping>+New Content Grouping
- Give your content grouping a name and select “Enable Tracking Code”
- Take a note of the index number and save your content grouping
- Go to Google Tag Manager, and in Tags, select your Google Analytics tracking tag
- In your Google Analytics tag under “more settings” select “Content Groups”
- Click “Add new content group”, add the index number that you took note of and the variable that will determine the group name
- Save your tag, deploy the container version and annotate your Google Analytics to reflect the changes made
These are the basics of setting up the content group, but “add the variable” is a little vague. You need a variable that extracts the name of content group from the page itself. This may be data stored within the data layer or data stored within the page DOM itself.
How to create a Data Layer or DOM Element Variable in Google Tag Manager for content groupings
One example that I’m going to use is how we put Branded3’s blog into categories by article type (e.g. Analytics, SEO, PR).
This data is already stored on page. For example What we know about gtag.js, the new Google Analytics Global Tracking tag is an “Analytics” blog post, which you can see here:
Since every blog post is tagged up in this way, we can extract the blog post category straight off the page. After inspecting the element, we can see that it lives within a span called “meta-category”.
To import this into Google Tag Manager as a variable, create a new variable with the following specification:
Variable Type: DOM Element
Selection Method: CSS Selector
Element Selector: Meta-category (this will change depending on what you’re trying to extract)
Be aware: Although this method is developer-light, if your website changes, the DOM Element may change or cease to exist. As well as this, the DOM Element may be different on the user-end (e.g. if they use a plugin or if they translate the page). This could bring in unexpected results.
One way to reduce this sort of anomaly is to utilise the Data Layer to extract the category. I’ve previously shown the value of the data layer in using custom dimensions to make an author report.
If you use the data layer, the code does not sit within the page itself so cannot be extracted using a DOM element variable. To see what Data Layer variables exist on a page, I use James. Clicking the “Data Layer” tab of this plugin allows you to see the names and values of data layer variables.
Make a note of the data layer variable name (for example the above it “author”) when creating your new variable. This needs to be in the form.
Variable Type: Data Layer
Data Layer Variable Name: author (this depends on what you want to extract)
Data Layer Version: Version 2
Once these variables have been created, you can attach them to your tag as we showed above.
If you have any questions about creating content groupings for Google Analytics (either using Google Tag Manager or without it) feel free to get in touch.