Track Best Performing Authors: Custom Dimensions You Should Consider Implementing for More Precise Tracking via Google Analytics. Part 2

“You cannot improve what you cannot measure”. There’s some truth to it. At least, when it comes to digital marketing. It’s all about measurement and improvement. Today, we’ll try to make use of our blog authors, and turn them into metrics.

Track Best Performing Authors

You wanna know who’s article on your blog people read the most? I bet you do. It’s probably one of the most tricky to implement because not every signature is the same. We’ll get to that. For now, we’ll stick with my example.

So, we have an author at the end of the blog post. The text and a link are wrapped around a SPAN tag with a CLASS. Just like this.

We can use ‘document.querySelector’ to extract the content of the SPAN element. But, then we will be left with a string of code, so we have to extract just the text, and cut out the name of the blogger. The actual script goes like this:

This is how it looks in the console.

Now let me explain some parts of it:

  1. We have extracted the content of a CLASS element.
  2. Then we have stripped the code to plain text, which left us with a sentence.
  3. Now we need to split that text into parts, basically, forming an array of words, then splice (literally) the text and extract just the author’s name.
  4. And thus we have an array of 2 words: first and last name of the author. But, we can’t use it in our Tag Manager variable just yet.
  5. We need to join the array into a string of text.

So, basically, we have split the inner text into separate words and joined them together because a split function returns an array we cannot use. You will have to adjust the code to your exact situation or just ask a developer to wrap the name of the author in a tag with specific CLASS.

Authorship. Implementation

  1. Go to https://tagmanager.google.com/

2. Go to Variables > User-Defined Variables Section > Click [NEW] button

3. Choose ‘Custom JavaScript’

4. Paste the code you have prepared based on the text above. Mine looks like:

function () {
var y = document.querySelector(‘.blog-details — author’);
var text = y.innerText;
var text2 = text.split(“ “).splice(-2);
var text3 = text2.join(“ “);
return text3;
}

5. Name the variable ‘Author’

6. Go to Tags > Click [NEW] button

7. Name the tag ‘Author Assign’

  • Choose tag type: “Universal Analytics”
  • Track type: Event
  • Category: Author
  • Action: {{Author}} — that’s your variable
  • Label: {{Page URL}} — that’s a built-in variable to track the url of a page when the event occurs
  • Set the Analytics ID

8. Go to your main Analytics tag, expand ‘More Settings’ > ‘Custom Dimensions’, and add the variable as a custom dimension:

  • Index: just a number — can be 1 if that is your first Custom Dimension
  • Dimension Value: {{Author}}

* This way you will be able to see the Author as a dimension in Google Analytics reports, and not be limited by the events.

9. Go to your google analytics admin section (Property column) > Custom Definitions > Custom Dimensions.

5. Hit the [+NEW CUSTOM DIMENSION] button.

6. Name it ‘Author’ (or whatever you like), the Scope is ‘Session’, tick the ‘active’ checkbox, and Save.