Tracking Authors in WordPress with Google Analytics Event Tracking
Here is a script for tracking authors in WordPress using Google Analytics Event Tracking. I threw this together in response to a blog post by Douglas Karr on tracking authors in WordPress. Doug presents a way to do this using spoofed pageviews and a separate profile. I could see a use case for that method also.
If you aren’t familiar with Doug’s blog, I highly recommend it. A great resource for digital marketers, with frequent posts on SEO, analytics, social media and a variety of other subjects.
16 Comments to Tracking Authors in WordPress with Google Analytics Event Tracking
I’m trying to use this script on our Indiana Insider blog, but the wordpress plugin I use only allows me to insert my GA account number, not a full tracking script. Is there some specific plugin I should use or somewhere specific that I should insert this GA script into my blog?
February 10, 2010
Jeremy,
You’ll probably need to abandon the plugin and put the raw Google Analytics code in your theme footer, with the modification for author tracking. An alternative would be editing the plugin.
- Adam
Awesome, thanks for sharing that Adam. Where in GA would I be able to find this new data?
Also, would I be able to run your method at the same time as Doug’s? (i.e. to compare the data in the separate profile and this one using event tracking)
March 7, 2010
Gyutae,
Thanks for the feedback. You could run both methods simultaneously, but I can’t think of a scenario where you would really benefit from it, other than for comparison’s sake.
- Adam
March 21, 2010
Thank you for posting this, I am trying out your method. This sort of tracking is high in demand for WordPress, but there are no solutions I’ve found yet. I’ve just added your code, so I’ll have to wait until tomorrow for Google Analytics to show the “Events” data to confirm that it works.
Question: Does this code also track when an author’s post appears on the front page of a blog. For example, lets say Author A has 6 posts on the front page, and the front page has 1,000 page views that day. Will Author A register 6,000 pageviews? 1,000 page views? Or even 0 page views for the front page?
If so, is there a way to exclude front page (ie, index.html) page views for the Google Analytics code using php?
March 22, 2010
Hi, it worked, but with the problem of counting stories appearing on the front page multiple times, as stated. Do you know of php code that will basically say, if it’s the front page of the blog, don’t run this event?
March 22, 2010
Another problem I notice is that the Google Analytics Events is recording authors names twice in succession, like this: BenBieberBenBieber, JamesFordJamesFord. Any clue?
March 22, 2010
Toward the solution of PHP ignoring counting author pageviews that appear on the front page, what do you think of this:
pageTracker._trackEvent(‘Authors’,'viewed’,”);
March 22, 2010
Whoops, won’t let me paste the PHP. Nevermind.
March 22, 2010
Alex, I’d just write a conditional using is_home to display the code only on the pages that aren’t the home page. As for the doubling up of the names, you identified a “mistake” in the script. It doesn’t need the “echo” when using the_author. I’ve removed it from the script on this site. Thanks for finding that!
March 23, 2010
It’s working, although I’m not sure I understand the Google Analytics results. Analytics records two sets of statistics for each author: Total Events and Unique Events. Unique Events seems to match closers to my overall traffic.
Another problem with this method is people surfing into the website to view a Category, which again skews the author’s statistics. Is there a WordPress qualifier for only single-page articles? I used the is_home conditional, but this is starting to get complicated.
Okay, what about just putting this code into Single.php instead of the footer? It seems logical, but too good to be true at the same time.
Also, do other enterprise level analytics platforms offer a solution to this? I know there is a demand out there for this and it’s more of a hack for GA right now.
April 5, 2010
Dan,
It is entirely possible to limit this code to a single template, using PHP. I’m not sure you’d want to put it in that file, but rather put the conditionals in place and leave the tracking script in the main footer.
You can definitely implement the same type of tracking with an enterprise solution using custom parameters/variables.
- Adam
May 15, 2010
Alex, use is_single to only include it on single posts and pages: http://codex.wordpress.org/Conditional_Tags
July 25, 2010
This is not an accurate way to measure pageviews unfortunately. Event Tracking only records one unique event during a website visitor's session. This means that 11 pageviews is only recorded as 1 unique event. And even though 11 pageviews can be recorded as 11 TOTAL events, 11 page refreshes of the same page by the same visitor can also be recorded as 11 pageviews, thus skewing the numbers and leaving pageview counting open to manipulation.
Google Event Tracking is meant to record website visitors actions such as clicking a link or downloading a file, it's not meant to measure pageviews accurately, and the tools to do so are not built in.
Alex,
Are you saying that Google will only record one event per author (i.e. unique Catagory/Action/Label combination) during a visit? Or one per page?
- Adam

February 10, 2010