How to add Google Analytics to WordPress In Less Than 2 Minutes

Today, I am going to show how to add Google Analytics to WordPress blog in less than 5 minutes. But before sharing the tutorial, let me tell you in Brief about Google Analytics and why Google Analytics for wordpress is important.

Well, Google Analytics is a free online tool that can be used by webmasters/bloggers for better understanding how people are using their website or blog. In other words, with the help of Google Analytics, you can easily track how much traffic you are generating and from where your traffic is coming i.e. search engines, direct traffic, social networks or referring sites. You can also track what keywords were used by visitors in the search engines to get into your website and on which pages they are landing on your website, where they live, their age, the browser they are using and so on. So if you want to expand and grow your business on internet, then adding google analytics to wordpress  is highly recommended.

How to Add Google Analytics to WordPress?

1. Sign Up For Google Analytics Account

First of all you will have to signup for Google Analytics account. To do this, simply visit Google Analytics signup page and log in with your Google account login details. After clicking on Sign in button,you will be redirected to Google Analytics main sign up page.

Google Analytics sign up page will look something like this:

google analytics login
After clicking on Sign In or Create an account,you will be redirected to the page given below
google analytics sign in
Click On Sign Up

2. Adding Website In Google Analytics

Now you will be given two options (Website Or Mobile APP) to track, make sure you select “Website“. After clicking on Website , enter account name, website name,website URL,industry category and reporting time zone. Don’t worry about any discrepancy, you may change all these information later.

adding google analytics to wordpress

After filling the information click on “Get Tracking ID ” at the bottom of the page and accept Google Analytics Terms of service agreement. Now you will see Your Tracking ID(some thing like UA-12121212-1) and will be given some JavaScript code which you have to put on your WordPress website.

adding google analytics to wordpress

4. Add Google Analytics Tracking Code To WordPress blog

There are various ways in which you can install Google Analytics for WordPress.

  • Adding  Tracking Code in Header.php and footer.php  file
  • Adding Google Analytics Using Functions.php
  • Adding Tracking Code Using Third Party Plugins

Adding  tracking code in header.php and footer.php file

Copy GA tracking code and go to WordPress Dashboard-> Appearance-> Editor. Open either your theme header.php file or footer.php file. If you want to add the tracking code in header.php (recommended by Google),  then add it  before </head>Tag and if you want to add it in your footer.php file (for improving peformance) ,then add it before </body> tag. Save the changes and update the file. Google Analytics should be installed.

Adding Google Analytics Using Functions.php

Copy the PHP code given below and paste it at the end of your functions.php file. Now replace “UA-XXXXX-X with your property ID” in line 5 with your GA Tracking ID. If you want to follow this method,then make you are good in PHP as a small error in functions.php file can breake your complete website.

// Include the Google Analytics Tracking Code-Affiliate (ga.js)
// @
function google_analytics_tracking_code(){

$propertyID = 'UA-XXXXX-X'; // GA Property ID

if ($options['ga_enable']) { ?>

<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', '<?php echo $propertyID; ?>']);

(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);

<?php }

// include GA tracking code before the closing head tag
add_action('wp_head', 'google_analytics_tracking_code');

// OR include GA tracking code before the closing body tag
// add_action('wp_footer', 'google_analytics_tracking_code');

Adding tracking code using WordPress Plugin:

If you are finding difficult to add tracking code in WordPress theme files, then you can install Google Analytics for WordPress. It is user friendly and is developed by “Joost de Valk” the guy behind WordPress SEO plugin. The only disadvantage of this plugin is that you will have to deal with one extra plugin and it might affect your page speed to some extent.

best google analytics wordpress plugin

Also Check: How To Increase WordPress Speed Using Best W3 Total Cache Settings

Adding Google Analytics in Gensis Framework: 

Nowadays many WordPress themes are providing inbuilt Google Analytics functionality. For example, if you are using Genesis framework,then you can add Google analytics directly in your Theme options. Go to WordPress Dashboard->Genesis->Theme Settings->Header and Footer script and paste the tracking code. Click “Save settings” and you’re done.

Adding Google Analytics in Gensis Theme

How to Check if Google Analytics Is working?

If you want to confirm that Google Analytics is installed on every page(Posts,pages,archives) of your WordPress website, then right click on any page and select view source code.You will see your ga.js code right above the closing header tag on every page.

You can also check it directly from Google Analytics account. Go to your Google Analytics Account and click on “Admin” at the at the top of the page and under “Property” choose your site and then click “Tracking Info”. If the Google Analytics code is installed properly, this section will displays the words “Receiving Data“.

If you find this tutorial useful,then do share it with your friends on Facebook and Twitter & if you have any questions or need help regarding installing Google Analytics In WordPress,then do leave your comments in the comment box given below.

  • Nice blog! Described very clearly that how to add google analytics to the website… The blog is very useful. Thanks for sharing.

  • Joyita Paul Chowdhury says:

    Hi Deepak,

    Great post, very well described with proper screens shots.

    I would just like to add that ‘Google Analytics Dashboard for WP’ is also a good plugin for setup

    Google Analytics for WordPress sites, where you can access your site statistics from WP backend

    without login to your respective Google Analytical account.


    • Nice article. Could you please explain the benefits of integrating GA to my WP site, rather than just using the GA interface alone?

  • >