How To Track Your WordPress Post Metrics by Author and Publish Date in Google Analytics

Author's avatar Analytics UPDATED Aug 23, 2021 PUBLISHED Mar 15, 2018 14 minutes read

Table of contents

    Peter Caputa

    To see what Databox can do for you, including how it helps you track and visualize your performance data in real-time, check out our home page. Click here.

    If you use Google Analytics to measure your content marketing, you have probably noticed that it does not offer two valuable dimensions for analyzing your data.

    First, Google Analytics does not let you review the top-performing authors on your blog.

    Even if you use a system like HubSpot, you can only measure sessions, conversions and conversion rate. You do not get any other quality metrics like bounce rate or time on page.

    Second, Google Analytics does not show the publish dates of each page. So, if you want to see how your most recent blog posts are performing, you need to search for each one by title or URL. You can’t even do it in a custom report!

    So, I wanted to find an automatic way to track the author and publish date of every post, so that you can use those dimensions alongside all metrics within Google Analytics- pageviews, time on page, bounce rate etc.

    ga_content_analysis_dashboard_template_databox

    As long as you have Google Tag Manager set up on your domain, you can actually do this pretty easily. I will show you how to create custom variables in Google Tag Manager that can be loaded up into Google Analytics as custom dimensions.

    At the end, you will be able to run any report in Google Analytics (or Databox) with author and publish date dimensions.

    Image Credit- Branded3

    What is Google Tag Manager?

    Google Tag Manager (GTM) is a single code that allows you to quickly update all the third party HTML tags that you add to your website. Since it is an online interface (tagmanager.google.com), any team member can use it to update HTML codes, instead of waiting on a developer. If you plan to use other technologies within your site, like Hotjar or Drift, you should definitely set it up to make it easier to manage tags.

    As an example, let’s say that you want to add Drift, a chatbot for marketers and salespeople, to your site. Without GTM, you would need to manually update each Google Analytics tracking code in order to track data on user interaction.

    This tutorial is going to cover both WordPress and HubSpot users, so here are two quick guides to installing GTM, if you have not already.

    Use the GTM for WordPress plugin to add GTM to your WordPress site and manage it from the WordPress interface.

    If you use HubSpot, check out their guide to adding GTM to HubSpot.

    Create An “Author” Custom Dimension

    We need to do five things in order to get the name of the author into Google Analytics.

    1. Create a custom dimension in Google Analytics so that we can add the data
    2. Find where the page author data is stored on the blog post page or JavaScript
    3. Create a user-defined variable in Google Tag Manager that will store the author from each page
    4. Connect the user-defined variable to the custom dimension
    5. Publish changes

    Yes, those are slightly out of order compared to the diagram above, but that is the easiest way to create the path from beginning to end.

    Creating a Custom Dimension in Google Analytics

    You must be an account “administrator” to create custom dimensions in your account. From the main Google Analytics interface, click the “Admin” button. Select the appropriate Property, and click the Custom Definitions menu item. Then, click Custom Dimensions.

    Create a new Custom Dimension named “Author” with a scope of “hit” and the Active checkmark box completed.

    This should be your first custom dimension, so the index will be 1. You can confirm by looking at the JavaScript code snippet.

    This is the endpoint where you can eventually access the data in Google Analytics.

    Creating a User-Defined Variable in GTM (WordPress)

    If you use HubSpot, skip ahead to the next section. If you use WordPress, check out the “Settings” page for your GTM for WordPress plugin. Make sure the “Post Author name” checkbox is checked.

    That means that the author name will be available as part of the dataLayer object. You can make sure it is working by opening up the inspector in your browser, clicking into the “Console” tab, and typing “dataLayer”. You should see an array of objects with data like this:

    In this case, the author data has a label of “pagePostAuthor”. Now, you need to sync that information with Google Tag Manager. Log into Google Tag Manager, and click the “Variables” section on the left.

    Create a new “User-Defined Variable” at the bottom of the page, and make it a “Data-Layer Variable”. Give it a name of Author”. The data layer variable name must be the exact same as the label above, so in this case, that means that it is “pagePostAuthor”.

    Skip down to “Connecting a User-Defined Variable to a Custom Dimension” to finish the process.

    Creating a User-Defined Variable in GTM (HubSpot)

    In HubSpot, the author data is usually stored as a meta tag, so there is no need to add a plugin or integration. Click into any blog on your domain, and open up the inspector. Look within the “head” section of the HTML, and you should find a meta tag with the name of “author”.

    This is the data you will import into Google Tag Manager.

    Log into Google Tag Manager, and click the “Variables” section on the left.

    Create a new “User-Defined Variable” at the bottom of the page, and make it a “JavaScript Variable”. Give it a name of Author”. The JavaScript variable name must access the meta tag above, which can be done with the following bit of JavaScript:

    Connecting a User-Defined Variable to a Custom Dimension

    Here is the last part. We need to connect the data in this user-defined variable to the correct custom dimension in Google Analytics. Click on the “Tags” menu on the left, and find the tag with your Google Analytics tracking code that fires on every page. It should have a “Type” of “Universal Analytics”.

    From there, find the “More Settings” dropdown, then the “Custom Dimensions” dropdown under that.

    Add an Index of 1 to match the index you previously set up in Google Analytics. Then, select the block on the far right, and select the User-Defined Variable you set up previously.

    Publish Changes

    To begin adding the author data to Google Analytics, click “Submit” in the top right.

    After that, Google Analytics will track the author on every page view, and allow you to track your top authors on an ongoing basis.

    Create a “Publish Date” Custom Dimension

    We must create a number to represent each date so that we can easily categorize our posts by publish date. In other words, we don’t want to use words like “March 15, 2018”, but instead, we should use “20180315”. This will make it easier to sort the posts using regular expressions.

    As you can see from the dataLayer object below, each of those numerical dates is available as a separate property. So, just like above, we are going to import each one into Tag Manager, and combine them into one custom dimension.

    Creating a Custom Dimension in Google Analytics

    You will want to create a new custom dimension called “PublishDate” in the second dimension slot (this will happen by default).

    Create a User-Defined Variable for Each Date Property

    Before we create a date by combining the three properties, we need to create a user-defined variable for each one to get them into Tag Manager. Each one is a Data Layer Variable.

    PublishYear stores the year.

    PublishMonth stores the month.

    PublishDay stores the day.

    Connecting All 3 Date Variables To One Custom Dimension

    Here is the last part. We need to connect the data in this user-defined variable to the correct custom dimension in Google Analytics. Click on the “Tags” menu on the left, and find the tag with your Google Analytics tracking code that fires on every page. It should have a “Type” of “Universal Analytics”.

    From there, find the “More Settings” dropdown, then the “Custom Dimensions” dropdown under that.

    As you can see above, we add all three variables into one string using double brackets. There should not be any spaces between the variables. This will create one complete date.

    Create A “Page Title” Custom Dimension

    Since the title tag is a universal HTML tag, we can pull it into the Google Analytics in the same way across all CMS systems. The steps are very similar to the ones above.

    1. Create a custom dimension in Google Analytics so that we can add the data
    2. Create a user-defined variable in Google Tag Manager that will store the author from each page
    3. Connect the user-defined variable to the custom dimension
    4. Publish changes

    You can find your page title by opening the inspector on any blog post, then looking for the head section within the HTML. You can find the title within the head section.

    Creating a Custom Dimension in Google Analytics

    Create a new custom dimension with the same process as you used above. Except this time, call the dimension “PostTitle”, and attach it to the third custom dimension

    Create A User-Defined Variable for Post Title

    Follow the same steps as above to create a user-defined variable within Google Tag Manager. Call this one PostTitle as well, and attach it to document.title as a JavaScript variable to pull in the page title.

    Connecting a User-Defined Variable to a Custom Dimension

    Here is the last part. We need to connect the data in this user-defined variable to the correct custom dimension in Google Analytics. Click on the “Tags” menu on the left, and find the tag with your Google Analytics tracking code that fires on every page. It should have a “Type” of “Universal Analytics”.

    From there, find the “More Settings” dropdown, then the “Custom Dimensions” dropdown under that.

    Add an Index of 3 to match the index you previously set up in Google Analytics. Then, select the block on the far right, and select the User-Defined Variable you set up previously for the page title.

    Publish Changes

    To begin adding the page title data to Google Analytics, click “Submit” in the top right.

    After that, Google Analytics will track the page title on every page view, and allow you to track your top posts labeled by title on an ongoing basis.

    Measure Your Blog Post Metrics in Databox

    The dashboard pulls custom dimensions 1, 2 and 3 from your Google Analytics account, so if you used those three slots for author, publish date and page title, the data will immediately populate.

    It shows your top blog authors based on all posts published in their name, so your team can get competitive over the data for the month or year.

    It also looks at pageviews and bounce rate for all your latest posts, so you can see which recent posts are the highest quality, and which ones are helping you hit the month’s traffic goals.

    If there are any other custom dimensions that you would like to track, let me know in the comments. I am curious to learn about the other ways that content marketers analyze their content.

    ga_content_analysis_dashboard_template_databox
    Author's avatar
    Article by
    Tamara Omerovic

    Tamara Omerovic is a marketing consultant with 8 years of experience in content marketing and SEO. She specializes in leading high-performing teams and developing effective marketing processes for B2B SaaS brands.

    More from this author

    Get practical strategies that drive consistent growth

    Read some