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.


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?
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)
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
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?
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?
Another problem I notice is that the Google Analytics Events is recording authors names twice in succession, like this: BenBieberBenBieber, JamesFordJamesFord. Any clue?
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’,”);
Whoops, won’t let me paste the PHP. Nevermind.
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!
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.
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
Alex, use is_single to only include it on single posts and pages: http://codex.wordpress.org/Conditional_Tags
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
It's complicated, so I'll repost what I wrote at an official WordPress forum:
This may be a bit advanced for some, but just a warning: the problem with Google Analytics Event Tracking is that it is not a completely accurate way for tracking unique pageviews, as it wasn't built for that (it was built to record visitor's actions such as hitting play on a video or downloading a file). So the code above, while semi-helpful, is not an entirely accurate way of recording unique pageviews and probably should not be 100% used to determine pay for bloggers.
The reason Event Tracking is not accurate for tracking pageviews using the code above is that if a visitor views multiple unique webpages in WordPress's "Single Page" view (single.php), Event Tracking will only count those views as 1 unique event (or 1 pageview). For example, say a visitor reads one article, then reads 10 more on your site, Google Event Tracking will record all those views as 1 unique event, and also record it as 11 total events. (You'll have to read up on Google Event Tracking to know the difference between Total and Unique Events.)
Why does it do that? Because "Single Page" (single.php) is the trigger, not individual post titles. So even though a user is browsing multiple articles on the site, Google Analytics Events Tracking only counts it as one unique event of accessing the single.php on your site during the visitor's session. Think of it the same way regular ol' Google Analytics counts unique pageviews, except instead of a tracking a specific URL, single.php is the webpage, and the posts are just the dynamic content loading inside of it.
So to reiterate, no matter if a user reads 1 article or 11 different articles in "Single Page" view, it will only be counted as 1 unique event during a user's session on your site,
So Total Events seems more accurate right? Wrong. Because if that same user views the same article 11 times (in other words, hits refresh 11 times), it will count as 11 total events, also ruining your pageview counting.
So unique events does not equal unique pageviews. And that's too bad, because unique pageviews would be one accurate way to measure individual author success on a multi-author blog.
Maybe there is a way to do use Google Analytics Event Tracking more accurately than the above code example, I'm still looking for it though.
That all makes sense. Is that why there is the page level scope option for custom variables in Google Analytics. It seems like using custom variables instead of events is the solution here.
Can you give a code example of what you mean?
All,
I've actually abandoned using my own script in favor of Yoast's plugin: http://yoast.com/wordpress/google-analytics/
Since recent updates were made earlier this year, I find it is far superior to my JavaScripting capabilities, and I highly recommend it.
- Adam