How to Create a Google Analytics Custom Dimension for Blog Visitors via Google Tag Manager

Marketers spend a lot of time and energy working on our blogs and convincing the rest of the team of our blog’s importance in one way or another. Whether that’s related to recency of content to encourage more consistent Googlebot crawls, or tied to a more concrete metric like eCommerce revenue driven by the blog, having a bit more information about how our site visitors are interacting with the site after visiting the blog can be a valuable tool. A Custom Dimension in Google Analytics to track blog visitors is a great place to start collecting that data.

A Custom Dimension for blog viewers can be easily created in Google Tag Manager. We’ll create a cookie that will be deployed via Google Tag Manager and applied as a small file to the browsers of users who visit any page within the /blog/ section of our site. We’ll then create a User-level Custom Dimension within Google Analytics that will allow us to segment out blog visitors and track their actions across the rest of our Google Analytics data. 

First things first, sending cookies to your users is something that needs to be discussed in your Privacy Policy and might have GDPR and CCPA concerns, so sites should make sure they’re set up to deliver cookies in the right way before starting to do this.

1. Define what area of your site you want to track and what you’d like to do with the data.

In this case, we’ll be tracking users accessing /blog/ pages on the UpBuild site. I think that it would be interesting for our Client Discovery team to understand how our blog posts factor into users submitting a form on our website.

2. Create a Google Analytics custom dimension.

In Property Settings, set up a Custom Dimension called something like “Users Who Viewed the Blog”.

I’m a big believer in taking out ambiguity where you can. I want this data to be super simple for anyone within an organization to understand and apply without needing to reference some type of ‘master sheet’. If we kept it as just ‘Blog’, while I might know what it means, it leaves a lot of room for interpretation and added steps to track back. So the more literal I can make my Custom Dimension name, the better.

We want to capture individual users, so we’ll set the Scope to User. We’ll also make note of what number the dimension is – in this case, it’s dimension 8.

3. Create a GTM custom HTML tag.

Hop into Google Tag Manager and set up a new Custom HTML tag.

Here’s the script we created to set the cookie:

See the Pen Blog View Custom HTML Tag by UpBuild (@upbuild) on CodePen.

Use the above script and modify the page path to match your blog’s URL structure. Set the Tag’s Trigger to fire on All Pages. Here’s what that will look like:

4. Create a custom variable for our cookie.

We’ll then need to set up a 1st Party Cookie Variable called ‘blog’ that matches up with our Custom HTML cookie name. Here’s an example of what that might look like:

5. Connect our custom dimension to our Universal Analytics implementation tag.

Since UpBuild uses Google Tag Manager for our Google Analytics implementation, we don’t need to create a new tag to capture our new Custom Dimension data. We’ll just make a simple edit by adding in the new Custom Dimension Variable we just created to the existing Universal Analytics tag.

This is also where we’ll reference the Index number (8) that we saved from creating our Google Analytics Custom Dimension.

6. Preview & test

Now it’s time to make sure that GTM can properly detect the post publish date and capture it as a variable. Since we’re viewing a Blog page, we see the correct ‘yes’ designation.

7. Publish this GTM workspace.

Once everything looks good, go ahead and Publish your Google Tag Manager Workspace, and the data will roll into Google Analytics for you to view and use.

This Custom Dimension creation method can be applied to other areas of your site as well to identify and segment different user types — for example, tracking users who view the login page, or users who enter the site via a product page. The sky’s the limit when it comes to segmenting out user behavior of your site visitors, and GTM is definitely your friend here.

Related Posts

Leave a Reply

Your email address will not be published.