In an earlier blog post I covered how to measure user behavior and segmenting content for publishers on Accelerated Mobile Pages. Ever since the post, we were asked many times on how to track articles that are associated with multiple tags and categories in Google Analytics.

Unfortunately, the solutions that I see circulating in the Internet suggest that if an article or a content page is associated with multiple categories, a single custom dimension should be fired with the content pageview. And all categories that are associated with the page will be concatenated and separated with a delimited (for example: holidays-mothers_day-craft-gifts) and then get sent as a one string.

mothers_day

If we look at the sample report above, you will see an obvious readability and usability issues about this solution:

  1. This report shows us how pages with multiple tags perform, but it is very hard to analyze the performance of each category by itself.
  2. For category analysis, you will need to export the data outside GA (ex. Excel sheet), clean all entries, and then look at categories and their corresponding pages.

Since i’m a big fan of constructing solutions that provide reporting and ease of analysis within the GA interface, where possible, and since the purpose of this exercise is to analyze page categories, we need a solution that is category-centric where page categories can be tracked independently from the pages that they are associated with but also associate with their corresponding pages as needed in reporting.

(For a multi-tag analysis in BigQuery, see Big Data for Publishers by Hazem Mahsoub.)

Suggested Solution:

Create a custom dimension to track each page category by itself and a create custom metric to track how often each individual category is viewed. we will need to loop through each item in the categories array and fire an event for each item along with the “category” custom dimension and “Category Views” custom metric.

This will empower analysts to look at categories at the aggregate level as well as in a granular level.

Step 1: Configure Google Analytics

Set up a Custom Dimension:

  1. Click on New Custom Dimension
  2. Name the Custom Dimension as “Category”
  3. Set the “Scope” as “Hit”.
  4. Save the Custom Dimension by clicking “Create”.
Custom dimension
Creating a custom dimension

Set up a Custom Metric:

  1. Name the new Custom Metric “Category Views”.
  2. Leave the “Scope” dropdown as “Hit”.
  3. Set “Formatting Type” as “Integer”.
  4. Save the Custom Metric by clicking “Create”.
Creating a custom metric
Creating a custom metric

Step 2: Configure the Google Analytics code to read the article categories and send them with an event hit that is sent when users browse the content page.

Note: Since multiple tags are associated with our articles, The “Category” custom dimension and the “Category views” custom metric will be fired with an event for every category in the page (loop through each item in the tags array).

Sample code for tracking categories

  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

	ga('create', 'UA-12345678-1', 'auto');
		
	var pageURL = '/holidays/mothers-day/crafts/planning-mothers-day/';
	var pageTitle = 'Planning Mother\'s Day';
	var categoryValue = ['Holidays', 'Mother\'s Day', 'Crafts', 'Gifts'];
	
	ga('set', {page: pageURL, title: pageTitle});
	ga('send', 'pageview');
	
	for (var i = 0; i < categoryValue.length; i++) {
		setTimeout(myFunction(i), 3000);
		function myFunction(i) {
		  ga('send', 'event', 'Custom Dimension Event', 'Blog Post Categories', 'Blog Post Categories', {nonInteraction: true, 'dimension1': categoryValue[i], 'metric1': 1});
		}
	}

Note #1: Modifying page URLs

Many publishers and content websites use Single Page Applications to deliver much faster-loading content without requiring a full-page load.

In these cases usually the page URL you want to send to GA and associated with all Event hits is different from the URL that appears in the browser’s address bar. We want to make sure every Custom Dimension, Custom Metric and Event hit get sent with the correct page URL. In the above sample code, we updated the page field on the tracker instead of passing it in the send command. Setting it on the tracker will ensure the page URL is used for all subsequent hits.

Note #2: Non-Interaction Events

In GA a bounce is defined as a session with a single interaction hit. Event hits are by default considered an interaction hit, which means that it is included in bounce rate calculations.

In our code, we set the value of the final boolean parameter “nonInteraction” to true to make the sent events non interaction hits in order not to impact the bounce rate calculations. Now our sessions that contain a single page view with non-interaction events fired for category tracking will be treated as bounce sessions as normal.

Note #3: Google Tag Manager

If you’re using Google Tag Manager for Google Analytics deployment, follow the following instructions:

  1. Add the following snippet of code to the head of your content page or elsewhere above your container snippet (update the data layer variables with the correct metadata information):
       dataLayer = [{
         'pageURL': '/holidays/mothers-day/crafts/planning-mothers-day/',
         'pageTitle': 'Planning Mother\'s Day',
    	 'categoryValue': ['Holidays', 'Mother\'s Day', 'Crafts', 'Gifts']
       }];
    
    
    
    ...
    
    
  2. Configure the GTM tags to receive the data layer values and fire the proper hits to GA.
Tag #1: Pageview Tag
Tag #1: Pageview Tag

 

Tag #2: Event Tag
Tag #2: Event Tag

 

Tag #3: Custom HTML Tag
Tag #3: Custom HTML Tag

Step 3: View Stats in Google Analytics

Now that we have everything sent to GA, it’s time to view our data and see how our articles’ categories are performing.

Since custom dimensions don’t appear in standard reports as a primary dimension, create a simple custom report with the “Category” dimension and the “Category Views” metric.

Custom report showing Category as the primary dimension

 

Page URL applied as a secondary dimension

Finally: Measure and optimize

In our example that we used in this post, Better Homes and Gardens website offers extensive information on decorating, building and remodeling, crafts, entertaining, cooking, and gardening.

If crafts pages, for example, are generating high time on page and more user engagement (ex. social shares, comments, paid subscriptions, purchases…), business owners may consider investing more writing resources towards additional crafts ideas. And if cooking articles are leading to high bounce rate, high exit rate, and low average time on page, resources may get shifted to write on other more engaging topics.

It is important for analysts to keep in mind and before taking any drastic actions to drill into individual pages within the category to determine which specific articles are well performing or underperforming for the topic in question. Looking at aggregate numbers of the categories performance is just one step of many that we should take before we make any site optimization actions.

Happy Analyzing!

Message Sent

Thank you for registering.

Cardinal Path hosted a live session to connect with you and answer all your questions on Google Analytics.
Get all the expertise and none of the consultancy fees in this not-to-be-missed, rapid-fire virtual event.

Thank you for submitting the form.

Thank you for submitting the form.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Click here to download access the tool.

Message Sent

Thank you for registering.

Message Sent

Thank you.

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Thank you

Message Sent

Thank you.

Message Sent

Success!
Your message was received.

Thank you.

Thank you for registering.

Cardinal Path is continuing with its series of free training. Next we are conducting training on Google Data Studio. Check it out here.

Message Sent

Thank you for registering.

Thank you for your submission.

Your request has been submitted and a rep will reach out to you shortly.

Message Sent

Thank you for your interest.

Thank you for registering.

You should receive a confirmation email from GoToWebinar with your unique webinar login information. If you do not receive this email or have trouble logging in to the event, please email asmaa.mourad@cardinalpath.com.

Thank you for subscribing!

You're now looped into the world's largest GMP resource hub!

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for your submission.

Thank you for your submission.

Message Sent

Thank you for registering.

Thank you for registering.​

Paid media spend by Government websites increased a whopping 139% YoY in 2020.

2020 Online Behavior Live Dashboard

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

2020 Online Behavior Live Dashboard

Thank you for your submission.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Thank you for registering.

Message Sent

Success! Thank you
for reaching out.