4 Unique Google Analytics Segments to Use on WordPress
What good are your Analytics if you can’t make sense of the data and suit it to better your needs? Sometimes, you can get more meningful information out of the reports by customising the data to suit your needs. For instance, have you ever wondered what the value of comments are on your pages? How about determining the longevity of posts? Or seeing which author rocks up the higher number of pageviews per month?
4 Segments to help answer those questions…
Here are some great segments you can get out of WordPress. In the following order:
- Author name
- Number of comments
- Post date
- Logged in or not
// 1. This will show the Author's name in your Analytics _gaq.push(['_setCustomVar',2,'Author','<?php the_author(); ?>',3]); // 2. This will show your comments number for each post in Analytics _gaq.push(['_setCustomVar',3,'Comments-Number','<?php echo get_comments_number(); ?>',3]); // 3. This will display the date a page was posted in Analytics (you may need some regex to get the value out of this one) _gaq.push(['_setCustomVar',4,'Post-Date','<?php echo get_the_date(); ?>',3]); // 4. Finally, this set's the user's session as a logged in user or a logged out user _gaq.push(['_setCustomVar',5,'Logged-In','<?php if ( is_user_logged_in() ) { echo 'Yes'; } else { echo 'No'; }; ?>',2]);
Implementing these custom variables
I suggest reading up on Google’s Custom Variables documentation and the WordPress Codex for more detailed instructions about these sorts of custom variables (both of these sites are fantastic resources for developers). From my experience though, you will need to consider a couple of things:
- Some of the PHP functions I presented above can only be called from certain parts of the page
- You may need to consider where your Google Analytics script runs
- You MUST set the custom variable before _trackPageview, but after _setAccount - otherwise it will not track
Of course, you don’t want to go crazy and implement any custom variable just for the hell of it either. Think first about what you need out of your reports and what you’re going to act on before wasting slots you may need in the future.
Let me know if there are any more great segments you like to use as a blogger, in the comments.
You could filter the author and see which post did best, so you can advise him to post in a certain category he’s good at. So you’ll get a more structured approach on who’s posting what and keep content fresh in each category.
Totally… if you ran a blog with multiple authors, this would be a hell of a variable to track.
By the way Dries, I’ve found that all of this can be achieved through Joost de Valk’s Google Analytics plugin for WordPress which is exceptionally good (not too sure how resource intensive it is, but it got me to switch).
Not all sites run WordPress
Indeed… I eat my own words.
No doubt others could apply these in Drupal, Joomla or another blogging platform.
(+ title changed - thanks Dries)
Is it possible to show top 10 authors based on google analytcis? Thanks for the article.