Design & Development

How to Install Google Analytics on WordPress

Google Analytics is a freemium software service that helps websites monitor traffic and identify trends in site visitor behavior that could, ultimately, impact marketing, conversions, revenue, and profits.

WordPress is the single most popular content management system with between 48 percent and 62 percent of the CMS market, according to BuiltWith, Opensource CMS, and W3Techs. Others estimate that WordPress powers at least one-in-five of the top 10 million sites on the web.

Ecommerce is also embracing WordPress as an estimated 250,000 sites use WooCommerce, the popular WordPress plugin that transforms the WordPress CMS into a functional ecommerce platform. WP eCommerce, another WordPress plugin, has been downloaded more than 2 million times since its release in 2006, and may have tens or even of hundreds of thousands of live ecommerce sites running on it.

Given the utility and popularity of Google Analytics and WordPress, it makes sense to demonstrate how quickly and easily the two solutions could be used together. What follows are the easy steps to install Google Analytics on any site using WordPress 3.9.1 or similar.

Get Google Analytics Tracking Code

Google has been known to change the Analytics navigation and terminology relatively frequently, and the company doesn’t necessarily follow a versioning system. So it is possible that some users could have a slightly different interface than what is described here.

In general, open up Google Analytics. You will need to create an account, if you have not already done so. Once you have an account, navigate to the Admin page.

Navigate to the Admin page in Google Analytics.

Navigate to the Admin page in Google Analytics.

With the Admin page open look for the “Tracking Info” link in the “Property” column. Under “Tracking Info” click “Tracking Code.”

The Tracking Code link is in the Tracking Info section of the navigation.

The Tracking Code link is in the Tracking Info section of the navigation.

Clicking the “Tracking Code” link should open a new section and slide the Property column to the left. This new section includes a snippet JavaScript tracking code. Copy the code, and get ready to paste it into place on your WordPress site.

The Tracking Code should be copied and later pasted into place.

The Tracking Code should be copied and later pasted into place.

Add the Tracking Code to WordPress

Open your WordPress installation’s site administration. These instructions are for the form of WordPress (version 3.9.1) that you install on a server rather than the form of WordPress hosted at WordPress.com.

From the administration panel select “Appearance” and then “Editor” to open up the theme editor. This editor should allow you to make changes to your WordPress theme files. If for some reason, you have trouble saving changes, check your server to ensure that the theme files may be overwritten.

The WordPress Appearance Editor allows users to modify the current theme.

The WordPress Appearance Editor allows users to modify the current theme.

Google Analytics tracking code may be placed in either the WordPress header file (header.php) or footer file (footer.php). If you place the tracking code in the WordPress header, the Google Analytics script will be run as the page begins to load and should complete whether the rest of the page loads or not. In this way, you will be prioritizing Google Analytics, ensuring that each visit will be counted. Placing the tracking code in the WordPress footer means that almost the entire page will load before the Google Analytics tracking script is run, but many developers like to place JavaScript, in general, at the end of a page in the hope that the page will load a millisecond faster.

With the WordPress editor page open, find the header.php (for our example, the tracking code is going in the header) under the Templates column and select it so that it is the active file.

Locate the header.php file from the Templates column.

Locate the header.php file from the Templates column.

In the editor, locate the closing head tag, which has a forward slash (/) before the word “head” inside of HTML’s characteristic brackets.

Locate the closing head tag in the code.

Locate the closing head tag in the code.

Add a couple of new lines and paste the Google Analytics tracking code into the header.php file just about the closing head tag.

Paste the Google Analytics tracking code in place and save the changes.

Paste the Google Analytics tracking code in place and save the changes.

Save the changes and update the file. Google Analytics should be installed. Try clicking around on the site a bit and checking out the Real Time analytics from the Google Analytics interface to ensure that everything is working correctly.

Beyond the Basics

This rather basic installation of Google Analytics will provide some information, but many, if not most businesses, will want to use more advanced features like custom variables or ecommerce tracking.

All of these features can be set up manually. As an example, check out Tim Wilson’s article “Google Analytics: 5 Custom Ecommerce Events to Track,” which explains what online merchants should track with Google Analytics and the code necessary to add some of these custom variables.

Also see Wilson’s articles “Configuring Google Analytics, Part 1: Are You Taking Full Advantage?” and “Configuring Google Analytics, Part 2: Advanced Capabilities” to get the most out of Google Analytics.

There are also a couple of popular WordPress plugins that can help with Google Analytics.

The first is “Google Analytics for WordPress” from developers Joost de Valk and Barry Kooij. This plugin provides an interface for WordPress users to set up a few custom variables like tracking a post author from a plugin options page. For sites that are using content marketing to promote transactions, this plugin can be very helpful. Also, if you install this plugin, you do not need to add Google Analytics tracking code, but rather have verify your Google Analytics account with the plugin and allow it to add the appropriate tracking code for you.

Businesses using WooCommerce may also want to consider using the “WooCommerce Google Analytics Integration” WordPress plugin, which can help track sales all the way back to the last click referrer.

Armando Roggio
Armando Roggio
Bio   •   RSS Feed


x