Tracking Your Most Popular Blog Post Tags in Google Analytics with Jekyll

Published: August 7, 2017

Tagging is a feature built into most blogging platforms. Typically tags differ from categories in that there are many more of them on your site and a larger number of them are applied to a specific post. Here’s how WordPress describes the difference…

Tags are similar to categories, but they are generally used to describe your post in more detail.

Regardless of the exact meaning, understanding which tags on your site are most popular can help you make decisions about what type of content to publish. This post outlines a strategy for identifying your most popular tags in Google Analytics

Recording Arbitrary Data in Google Analytics

Google Analytics provides several mean for storing arbitrary data. The options available to us are as follows…

A critical concern for our implementation is that a single post can have many tags. This immediately disqualifies Content Groups as an option…

If you call the same index number multiple times on the same page, then only the last call for that index number is sent to Analytics.

Create/edit Content Groups - Google Analytics Help

Next up is Custom Dimensions. The only way to send multiple values is by using a Product-level scoped custom dimension. Doing this requires the site to be using enhanced ecommerce, and would require thinking of each tag as a product. This feels a bit dirty. This Stack Overflow post suggests URL encoding the tags as a value, but we want them each stored uniquely, so this isn’t really a workable solution.

This leaves us with Events, which is what we’ll use

Updating the analytics.js Tracker

Sending the data to Google Analytics is really easy. Below is the snippet I’m using on this site.

(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),

ga('create', '{{ ga }}', 'auto');

ga('send', 'pageview');

{% if page.tags.size > 0 %}
{% for tag in page.tags %}
  ga('send', 'event', 'taggedPost', 'view', '{{ tag }}', { nonInteraction: true  });
{% endfor %}
{% endif %}

The Result

You’ll now be able to see which tags users are viewing under Behavior > Events > Overview.

A demonstration of tracking tags in Google Analytics from this blog

As you can see, Magento and Security are the most popular tags on this site.

Max Chadwick Hi, I'm Max!

I'm a software developer who mainly works in PHP, but loves dabbling in other languages like Go and Ruby. Technical topics that interest me are monitoring, security and performance. I'm also a stickler for good documentation and clear technical writing.

During the day I lead a team of developers and solve challenging technical problems at Something Digital where I mainly work with the Magento platform. I've also spoken at a number of events.

In my spare time I blog about tech, work on open source and participate in bug bounty programs.

If you'd like to get in contact, you can find me on Twitter and LinkedIn.