Practical Ecommerce

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

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


Sign up for our email newsletter

  1. Mary Ann Aschenbrenner June 19, 2014 Reply

    This article is a big help, clear and easy to follow. Thank you!

  2. Vaibhav Singh June 19, 2014 Reply

    Great post, I have added Google analytics to my blog by using a plugin.

    Going to change.
    Thanks Armando

  3. Guy Cook June 20, 2014 Reply

    Well written, easy to follow instructions that address using Universal Analytics (I found not all analytics plugins support that new universal tracking code) This post is the solution, and I”ve reshared it in the social channels, good job.

  4. Manas Das June 20, 2014 Reply

    Thanks for this! IT worth a lot for a beginner like me :)

  5. Claudia June 20, 2014 Reply

    Thanks for posting this! It really helps :)

  6. Max June 22, 2014 Reply

    Nice and easy it seems. Shame i cant find EDITOR under appearance. using genesis theme. Anyone with any idea as to why this is so?
    please help me out.

    • Armando Roggio June 23, 2014 Reply

      Max, who is hosting your WordPress site?

    • Ron June 24, 2014 Reply

      Look under Genesis / Theme Settings, enter code into script area at bottom. “Enter scripts or code you would like output to wp_footer()”

  7. Byron June 24, 2014 Reply

    Good article Armondo. Using a quality theme allows easy input without editor too.

    • Armando Roggio June 25, 2014 Reply

      You’re right, many themes will include GA as a setup option or similar.

  8. Bridget Koan August 5, 2014 Reply

    Thank you form this information. It worked! I can’t believe I did it!

  9. Maggie Megenbir January 27, 2015 Reply

    This was very helpful!! I searched numerous other articles like this until I found yours. Yours was the only one that made sense from start to finish.
    Thank you!

  10. shovo April 12, 2015 Reply

    Thanks for a good post.

  11. Vicky May 24, 2015 Reply

    Hello, I am using Online WordPress theme.. Is there any way to install GA in that?

  12. Stefan May 27, 2015 Reply

    Hey, thanks for the post!
    I’d like to suggest also our new plugin Tracking Code manager that give you a complete solution for all your tracking codes.

    Here the link:

  13. Cari S June 25, 2015 Reply

    Thanks for these fairly easy instructions to follow. I am a total tech-tard. I sincerely hope I did it right, BUT how do I know if the analytics are installed and working properly?? Thank you!

  14. Ivan October 22, 2015 Reply

    I prefer footer.php instead of header.php

    Any significant difference ?? Here I have described how I do it.

    BTW good article

  15. Vikram Pawar December 5, 2015 Reply

    You have correctly pointed out the steps to add google analytics code to theme, but if theme is upgraded user have to do it again so its better to add by creating a simple plugin. You can refer for steps on how to add google analytics code using a simple plugin.

  16. Kyle Andrew April 1, 2016 Reply

    Outstanding job Armando. Thanks.

  17. charis August 19, 2016 Reply

    Here is a good tutorial that uses a plugin for that :

  18. Betty September 9, 2016 Reply

    Great article.Google Analytics Counter Tracker plugin on wordpress is just too good. It analyse the visitors hits on your homepage and display it graphically.