Analytics & Testing, WordPress

Tracking Multiple WordPress Authors with Google Analytics

Google Analytics

I wrote another post on how to track multiple authors in WordPress with Google Analytics once before, but got it wrong! Outside the WordPress Loop, you’re unable to capture the author names so the code did not work.

Sorry for the fail.

I’ve done some additional digging and found out how to do it smarter with multiple Google Analytics profiles. (Quite honestly – this is when you come to love professional analytics packages like Webtrends!)

Step 1: Add a Profile to an Existing Domain

The first step is to add an additional profile to your current domain. This is an option that most people aren’t familiar with but works perfectly for this type of scenario.
existing-profile.png

Step 2: Add an Include Filter to the New Author Profile

You’ll want to only measure page views tracked by authors in this profile, so add a filter for the subdirectory /author/. One note on this – I had to make “that contain” as the operator. Google’s instructions call for a ^ before the folder. In fact, you can’t write an ^ into the field!
Include-author.png

Step 3: Add an Exclude Filter to your Primary Profile

You won’t want to actually track all the extra pageviews by author in your original Profile, so add a filter to your original profile to exclude the subdirectory /by-author/.

Step 4: Add a Loop in the Footer Script

Within your existing Google Analytics tracking and below your current trackPageView line, add the following loop in your footer theme file:
<p class="code">
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
var authorTracker = _gat._getTracker("UA-xxxxxxxx-x");
authorTracker._trackPageview("/by-author/<? echo the_author(); ?>");
<?php endwhile; else: ?>
<?php endif; ?></p>

This will capture all of your tracking, by author, in a second profile for your domain. By excluding this tracking from your primary profile, you don’t add additional unnecessary pageviews. Keep in mind that if you have a home page with 6 posts, you’ll track 6 pageviews with this code – one for each post, tracked by author.

Here’s how the Author Tracking will look in that specific profile:
Screen shot 2010-02-09 at 10.23.32 AM.png

If you’ve accomplished this in a different way, I’m open to additional ways to track the author information! Since my Adsense revenue is associated with the profile, I can even see which authors are generating the most ad revenue :).

11 Comments

  1. 1

    Great post Doug! An alternative for tracking Authors at this level is with event tracking in GA. You can get a tally of how many times each of your authors’ posts were viewed, in the same profile as your regular data, without inflating pageviews. Also, you can use multiple dimensions in the Event reporting to see what sources were driving visitors to various authors (e.g. who is attracting the most readers via Twitter), where they are coming from, etc. I tried to post the script, but I was over the character limit. Here is the link: http://www.wheresitworking.com/2010/02/08/tracking-authors-in-wordpress-with-google-analytics-event-tracking/

  2. 2
  3. 3

    Awesome, thanks for sharing this Doug! I’m finding that the_author() needs to be replaced with get_the_author() in order to prevent the author name being duplicated and outputted twice.

    Also, how does your solution compare with Adam’s?

  4. 4
    • 5

      Hi Jeremy!

      The way I implemented it was actually utilizing two different accounts within Google Analytics (separate UA codes). I call one account “Author” and the other one I keep as the entire site. Make sense?

      Doug

  5. 7

    Thanks very much. I’m trying this out now. One thing though, I removed “echo” out of the loop because it seemed to be duplicating the author name. For instance /by-author/Author NameAuthor Name was appearing with the echo.

  6. 8

    Thanks for the tutorial. I need to track the pageviews each writer on a news blog accumulates in order to pay them by views.

    Including the homepage doesn’t really work, though.

    Can you just exclude code from the homepage? If that code was inserted only in the single-page layouts (an option on custom webpages), would that work? excluding homepage views from the count?

  7. 10

    How do you do step 1 please: “add an additional profile to your current domain”

    You show how to complete the step, but not how to get there in the first place.

Leave a Reply