Google Analytics for WordPress: Two Methods

There are two ways to install Google Analytics for WordPress:  manually in your theme or by using a plugin.  While most of this post will cover the manual installation of the tracking code, I will also briefly discuss some of the WordPress Google Analytics plugins I have used over the years.

Note:  This post isn’t going to cover creating an account at Google, since most people have at least one already through Gmail, Google+, YouTube, Picasa, etc.  However, if you do need help setting up a Google Analytics account, there is a great video provided by Google as part of their Conversion University series:  Creating a Google Analytics account

Finding your Google Analytics Account Number

Once you have your Google Analytics account set up, you’ve conquered probably 75% of your installation.  Hard to believe, right?  All you need now is your account number/profile from Google Analytics to plug in to the tracking code.

To find the proper code, sign in to Google Analytics and look for the following on the account home tab:

google-analytics-account-number

I’ve obscured my number with red X’s so that no one accidentally starts writing data to my account!  But if you see a code that starts with UA-, that’s your account and profile number.

Installing the default Google Analytics tracking code

With account number in hand, we’re ready to install the tracking code in our WordPress header file, right before the wp_head(); line (and definitely before the closing tag.)  Note: if you are using the Twenty Eleven theme, there are some comments about how removing the wp_head line will break WordPress plugins…this is the correct location.

Once you hit save to your header.php file, you’re done. If all is well, you’ll see the basic Google Analytics data starting to populate in your account in about 24 hours!

Of course, you can always use the Google Analytics for WordPress plugin…

If it turns out this is too complicated (though, I hope not!), or your needs are more complicated than the ‘standard’ Google Analytics installation, there are myriad WordPress plugins that you can install.  In the past, I’ve used many different plugins for my Google Analytics tracking needs, but the one I feel is the best is provided by Joost de Valk.  His plugin, not surprisingly named “Google Analytics for WordPress”, will allow you to do some link tracking, custom variables, e-commerce tracking, and much more.  Of course, the downside to this is that you lose the flexibility of coding exactly what you what, how you want…but it’s a good trade-off for those looking for simplicity.

I’ve also used Google Analyticator in the past, and it too seemed to work pretty well.  I’ve never really done an A/B comparison of the two, but the feature set is pretty much the same, and both gentleman seem to be excellent WordPress web developers, so I doubt either plugin will cause any performance hit.

No matter which way you choose to get your Google Analytics fix on your WordPress blog, happy tracking!  If you’re not measuring, you’re not improving 🙂


Removing Comment Bubble From Twenty Eleven Theme

If you’re like me, one of the things that seems odd about the WordPress Twenty Eleven theme is the comment bubble in the upper right of each post on the front page of the blog.  If you don’t know what I’m talking about, here’s a picture:

wordpress-twenty-eleven-comment-bubble

In the upper right, the comment bubble (highlighted blue) clutters up the front page

Before we can remove the comment bubble, we first need to figure what this element is called within WordPress.  Luckily, this is quite easy using a tool that is included in all modern browsers.

Finding the comment bubble’s name is as easy as “Point, Right-click, and Inspect Element”

To find out what any HTML element is called on a page, all you need to do is to point to the element, then Right-Click on it and choose “Inspect Element”.  I’m using a Mac with the Firefox browser, so it looks like the following on my computer:

firefox-5-inspect-element

'Inspect Element' is one of the most useful tools in web development

Once you click “Inspect Element”, you’ll see that the comment bubble is located inside the comment-link section of our WordPress template code:

comment-link

We need to look for "comment-link" in our WordPress template

Adding content.php to our WordPress child theme

Now that we’ve found what the comment bubble element is called, we need to find it in our WordPress child theme.  If you’ve been following along with the posts on this blog, we’ve already developed a custom CSS file and a custom header file.  To save you the agony, the WordPress file we need to modify is called content.php. Copy the content.php file from the base Twenty Eleven theme into your child theme directory.

Once you’ve copied this file to your directory, open it up in your favorite text editor.  What we’re looking for is “comment-link”…using Command-F, we can see that it is contained in this file twice.  We want to modify the first one, as it controls the element at the top right of the post; the second “comment-link” refers to the link at the bottom of each post.

When in doubt, comment it out!

Any time you are making changes in code, it’s good practice to first ‘comment out’ the code you are modifying, so that you can ‘uncomment-out’ the code if the change isn’t what you intended.  If you delete the code outright, before knowing what it does, you’ll be scrambling when you delete the wrong line!

Using the HTML comment tag of “Left arrow, exclamation point, two dashes”, we can start commenting out at the first line of the code snippet (to the left of the <? symbol).  Use the “Two dashes, Right arrow” HTML comment tag to the right of the “php endif” statement.  When you are done, your code will look like the following:

Hit save and you’re done!  No more comment bubble on your theme.  Of course, once you verify that the code is working correctly on your theme, you can delete these lines of code.  It’s really up to you and your needs…if you think you might want to re-instate the comment bubble at a later date, leave the code.  If you’re like me and don’t like the comment bubble, then delete!


WordPress Stats or Google Analytics? Yes!

To understand the success of your blog content and site design, you need actionable data on your visitors and how they are interacting with your site.  Whether to use WordPress Stats or Google Analytics (or both) to obtain this data depends on your goals.

WordPress Stats plugin

wordpress-stats-dashboard

WordPress Stats dashboard

If your goals are relatively basic in terms of understanding your blog’s success, then there’s no better place to get started than installing the WordPress Stats plugin. This plugin is part of the default “Jetpack” plugins installed with every version of WordPress…to activate it, go to the left-navigation menu under “Jetpack” and follow the instructions for activation.  You’ll need an API key from WordPress.com, but they are free and easy to obtain.

Once installed, this plugin will let you know how many page views your content has generated on a daily/weekly/monthly basis.  It will also allow you to view which blog posts specifically are the most popular, which is great for understanding what your readers are interested in reading.

This plugin will also tell you what search terms readers are using to find your site in search engines, and any other blogs or websites that are linking to your site (known as “referrers”).  Like page views, knowing these search terms and referring sites will let you know the type of content visitors to your site are most interested in reading, because either a visitor was interested in learning more about a topic (search terms) or read an article on your site and wanted to share it with others (referring link).

As a casual blogger, you can do much worse than just monitoring these simple data points.  But if you want to really analyze what’s happening when visitors come to your site, you’re going to need a bit more data collection.

Google Analytics

Have you ever thought, “I wonder where my readers are located geographically” or “Is my blog design compatible with different browsers, including mobile devices”?  If so, then stepping up to Google Analytics might be worth your while.  While the amount of data provided by Google Analytics can be overwhelming in the beginning, once you start using the reporting interface for a few weeks, you’ll gain a ton of insights.

google-analytics-dashboard

Google Analytics dashboard from The Fuqua Experience

For example, in a prior post I posted the geographical distribution of visitors to this blog after only 3 days.  By tagging my blog post link with Google campaign tracking, then posting that link to Twitter, I got amazing insight into how geographically diverse the contributors to the #measure hashtag are.  There were visitors from 17 countries that read my first blog post, something that would not have been possible to know without the extra horsepower that Google Analytics provides.  Sure, there’s not a whole lot of intent I can ascertain from the geographic distribution after 3 days, but the geographical distribution is something I can monitor over time to see what trends might be present.

WordPress Stats or Google Analytics?  Yes!

Up to this point, I haven’t been very precise about what constitutes a “simple” metric such as page views, or how to know when you need the extra “horsepower” that installing Google Analytics provides.  The reason for my imprecision is that the decision to install either tracking code shouldn’t be an “either/or” decision, but rather an “and”.  If you’re running a self-hosted WordPress blog, in my opinion you should be running both WordPress Stats and Google Analytics!

Yes, the data provided by Google Analytics is a superset of the information provided by WordPress Stats; thus, you don’t gain any additional insight from having WordPress Stats installed.  What you do gain by having both installed is convenience, and as far as I can tell there is no performance degrade to a site having both running at the same time.

So when you need a quick snapshot of what your blog has done in the past several weeks, or you want to get an idea of your most popular content while in your WordPress admin panel, the WordPress Stats plugin will do just that.  When you want to get a deeper insight of how several factors are interacting to create your successful blog, sign in to Google Analytics.

But above all else, remember:  the data doesn’t do anything because it’s being recorded.  You need to study it to unlock the value!


  • RSiteCatalyst Version 1.4.12 (and 1.4.11) Release Notes
  • Self-Service Adobe Analytics Data Feeds!
  • RSiteCatalyst Version 1.4.10 Release Notes
  • WordPress to Jekyll: A 30x Speedup
  • Bulk Downloading Adobe Analytics Data
  • Adobe Analytics Clickstream Data Feed: Calculations and Outlier Analysis
  • Adobe: Give Credit. You DID NOT Write RSiteCatalyst.
  • RSiteCatalyst Version 1.4.8 Release Notes
  • Adobe Analytics Clickstream Data Feed: Loading To Relational Database
  • Calling RSiteCatalyst From Python
  • RSiteCatalyst Version 1.4.7 (and 1.4.6.) Release Notes
  • RSiteCatalyst Version 1.4.5 Release Notes
  • Getting Started: Adobe Analytics Clickstream Data Feed
  • RSiteCatalyst Version 1.4.4 Release Notes
  • RSiteCatalyst Version 1.4.3 Release Notes
  • RSiteCatalyst Version 1.4.2 Release Notes
  • Destroy Your Data Using Excel With This One Weird Trick!
  • RSiteCatalyst Version 1.4.1 Release Notes
  • Visualizing Website Pathing With Sankey Charts
  • Visualizing Website Structure With Network Graphs
  • RSiteCatalyst Version 1.4 Release Notes
  • Maybe I Don't Really Know R After All
  • Building JSON in R: Three Methods
  • Real-time Reporting with the Adobe Analytics API
  • RSiteCatalyst Version 1.3 Release Notes
  • Adobe Analytics Implementation Documentation in 60 Seconds
  • RSiteCatalyst Version 1.2 Release Notes
  • Clustering Search Keywords Using K-Means Clustering
  • RSiteCatalyst Version 1.1 Release Notes
  • Anomaly Detection Using The Adobe Analytics API
  • (not provided): Using R and the Google Analytics API
  • My Top 20 Least Useful Omniture Reports
  • For Maximum User Understanding, Customize the SiteCatalyst Menu
  • Effect Of Modified Bounce Rate In Google Analytics
  • Adobe Discover 3: First Impressions
  • Using Omniture SiteCatalyst Target Report To Calculate YOY growth
  • Google Analytics Individual Qualification (IQ) - Passed!
  • Google Analytics SEO reports: Not Ready For Primetime?
  • An Afternoon With Edward Tufte
  • Google Analytics Custom Variables: A Page-Level Example
  • Xchange 2011: Think Tank and Harbor Cruise
  • Google Analytics for WordPress: Two Methods
  • WordPress Stats or Google Analytics? Yes!
  • Building a Data Science Workstation (2017)
  • JuliaCon 2015: Everyday Analytics and Visualization (video)
  • Vega.jl, Rebooted
  • Sessionizing Log Data Using data.table [Follow-up #2]
  • Sessionizing Log Data Using dplyr [Follow-up]
  • Sessionizing Log Data Using SQL
  • Review: Data Science at the Command Line
  • Introducing Twitter.jl
  • Code Refactoring Using Metaprogramming
  • Evaluating BreakoutDetection
  • Creating A Stacked Bar Chart in Seaborn
  • Visualizing Analytics Languages With VennEuler.jl
  • String Interpolation for Fun and Profit
  • Using Julia As A "Glue" Language
  • Five Hard-Won Lessons Using Hive
  • Using SQL Workbench with Apache Hive
  • Getting Started With Hadoop, Final: Analysis Using Hive & Pig
  • Quickly Create Dummy Variables in a Data Frame
  • Using Amazon EC2 with IPython Notebook
  • Adding Line Numbers in IPython/Jupyter Notebooks
  • Fun With Just-In-Time Compiling: Julia, Python, R and pqR
  • Getting Started Using Hadoop, Part 4: Creating Tables With Hive
  • Tabular Data I/O in Julia
  • Hadoop Streaming with Amazon Elastic MapReduce, Python and mrjob
  • A Beginner's Look at Julia
  • Getting Started Using Hadoop, Part 3: Loading Data
  • Innovation Will Never Be At The Push Of A Button
  • Getting Started Using Hadoop, Part 2: Building a Cluster
  • Getting Started Using Hadoop, Part 1: Intro
  • Instructions for Installing & Using R on Amazon EC2
  • Video: SQL Queries in R using sqldf
  • Video: Overlay Histogram in R (Normal, Density, Another Series)
  • Video: R, RStudio, Rcmdr & rattle
  • Getting Started Using R, Part 2: Rcmdr
  • Getting Started Using R, Part 1: RStudio
  • Learning R Has Really Made Me Appreciate SAS