Analyze Your Posts by Word Count: Part 1

analyze posts by word count in google analytics

Many SEO discussions focus around word count and how many words is optimal for search engines to pick up a piece of content more easily.

The deeper question from an analyst’s end is, how does word count affect user’s actions on site? Do people spend more time with content if they have more to read? Less to read? What are the engagement effects of users on content length?

Well we are going to explore just that, with a way to incorporate tracking of your content’s length right within Google Analytics. I will preface this with saying the setup I am going to walk through with you is in direct relation to using a site set up in WordPress. If you don’t have a WordPress site, the same concept still applies, but the implementation may be slightly different.

Collecting the Data

First, you’ll need to implement a small piece of code on your WordPress site in order to pull in the number of total words used in a post of page. For this action we will be using a great snippet that I found from Thomas Hardy at, along with Google Tag Manager to further implement our tracking.

First, login to the backend of your site in WordPress and access your editor, under Appearance -> Editor. From there locate your Header file along the right-hand side and open that up in your window.

Just under the opening tag, you will want to create a dataLayer. If you already have your dataLayer created for Google Tag Manager, that is great. If not the code you insert should look just like I have here below.

    dataLayer = [{
    'wordCount': '<?php echo word_count();?>'

Basically this is creating a dataLayer variable that we will later access in Google Tag Manager. It is labeling the variable as wordCount and then accessing some built in functionality in WordPress to obtain the number of words within your post or page.

From there we have one more code modification to perform within the WordPress admin area. Still in your editor section, you will want to find the file on the right-hand column labeled Theme Functions. Open that up and scroll to the bottom of the document. There place the following code.

function word_count() {
    $content = get_post_field( 'post_content', $post->ID );
    $word_count = str_word_count( strip_tags( $content ) );
    return $word_count;

Once you save that, we are done with the WordPress implementation and on to the fun stuff in Google Analytics and Google Tag Manager.

Google Anlaytics Word Count Custom Dimension

In order to track our posts by word count as a new dimension in Google Analytics, we will have to create a custom dimension. The setup here is very easy, as you can simply go into your admin panel in Google Analytics, select the Custom Definitions option under your Web Property and then select Custom Dimensions.

custom dimension setup google analytics

From there, create a new dimension, call it Word Count Actual, and set it to Hit level for the scope. Later we will also come back and create another dimension for Word Count Buckets, but we’ll save that for a later time at the moment.

custom dimension setup google analytics

Remember the index for your custom dimension, we will need this in the next step. If you have never created one before, the index will be 1.

Google Tag Manager Setup

Heading over to your Google Tag Manager implementation, you will want to locate your standard Google Analytics tag, which provides the basic pageview metrics to send to Google Analytics.

Under configure tag, select Custom Dimensions and click to add. In the index box remember back to the index of your dimension (it may be 1) and place that there. In the value area, start by typing two open brakcets {{ and then scroll to the bottom of the list and select “New Variable”.

This will launch a new section to create a variable. Each time a page is loaded on our site it will have a different value populated for the word count. If you want an accurate measurement of each word count you can use a new variable inside of Google Tag Manager to extract it from the variable you created in step one on your wordpress site. For this variable, you can name it simply wordCount.

gtm variable for word count

Select DataLayer Variable (DLV) for your variable type. Name the variable wordCount and then within that dialogue box, simply type wordCount again into the DataLayer Variable Name box. Save that and it will populate back into the Google Analytics tag you are working within.

This ensures that the custom dimension will now look for the variable you set on your wordpress site (wordCount) and populate that number to the custom dimension.

Back to Google Analytics for Reporting

Heading back over to Google Analytics, we can see if the custom dimension is populating as required. Since you are using a custom dimension to pull in our post’s word count, you will want to create a custom report.

custom report creation google analytics

Within the custom report select pageviews, bounce rate, and time on site for your metrics (or whichever metrics you would like to choose). Then in the dimensions area, search for Word Count Actual and select that newly created dimension.

Once you save, you new custom report will look like the following:

word count custom report analytics

One thing you should instantly notice is that each post is going to have a different word count, so how can we really analyze anything if every post is different?

Make sure to stop back next week as we continue this training and explore how to group your word counts into buckets for further analysis. This will include a new custom dimension and the data import feature in Google Analytics.

Go to part 2: Grouping Word Count by Buckets

Chris Kujawski

Founder and instructor at Digital Metrics Guru.

A passionate and driven digital marketer, specializing in Google Analytics, Tag Manager and Data Studio. A qualified expert in Google Analytics and Adwords, with more than 10 years experience delivering sound solutions to clients worldwide.

View all posts

1 comment