Google Analytics is a famous and popular reporting and metrics tool for Website owners/Webmaters.That helps websites monitor traffic and identify trends in site visitor behavior that could ultimately impact marketing, conversions, revenue, and profits.So,today Iam here to show how to install Google Analytics code on WordPress blogs and websites. WordPress and Google Analytics are the best companion.WordPress is the most popular website content management system used by thousands of web developers to build new websites each day. Google Analytics is the most advanced web traffic monitoring tool and best of all it is 100% free.

How To Add Google Analytics Code in a WordPress Website

 How to Add Google Analytics Code to WordPress? 

The installation of Google Analytics requires minimum steps so, why waiting lets start.

Step-1 : You need a Gmail account in order to log on Google Analytics . If you have existed google account then  create a Google Analytics account. To do this, visit Google Analytics Signup Page.

Step-2 : Once you sign-in with your Gmail account, you will be prompted to a screen like the one below. Here you can signup for Google analytics with your Gmail account.

Step-3 On the next window you will get options to choose between website or mobile app. Make sure website is selected.and select the tracking method as Universal Analytics now which is in beta mode and comes with extra features of classic analytics account.you will be upgraded to new features once they come out of beta version.

Step4: On the next step choose your account name,website name,website url,industry category,time zone…etc. Once you have fill the above information then click on the Get Tracking ID button. Now you will get a pop up window stating that You will be presented with Google Analytics terms and service which you must agree to, so click on I Agree button.

Step-5 : Now you will be presented with Google Analytics tracking code. Copy this tracking code so that you will need to enter it in your WordPress site.

How To Add the Tracking Code to WordPress :

There are 3 ways to install Google analytics in WordPress.

  1. Direct paste
  2. functions.php and
  3. plugins.

1. Direct paste Method :

In the direct paste method you need to login in your wordpress website,From the dashboard select “Appearance” and then “Editor” to open up the theme editor. This editor should allow you to make changes to your WordPress theme files.

Google Analytics tracking code can 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 (In our example, the tracking code is going to place in the header.php) under the Templates column and select it so that it is the active file.In the editor, locate the closing head tag, which has a forward slash (/) before the word “head” inside of HTML’s characteristic brackets “<>” .

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

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.

2. Function.php Method :

Note: only use this if you know what you are doing.Because if you did anything wrong then your website may get unexpected errors.

Add the following code in your theme’s functions.php file and don’t forget to paste your Google Analytics code.

Once you have installed Google Analytics on your site, Now  you can click Save.You can now click on the Reporting tab to see your site’s analytics overview. It takes Google up to 12 – 24 hours to start providing you with the awesome site stats that you need.

3.Plugin Method :

You can download a Google analytics code injector plugin for WordPress. This is very easy, as such plugin requires only Google Analytics ID other than the full tracking code. From your WordPress dashboard, go to Plugins >> Add New, search for ‘google analytics’, you will get a lot of free Google analytics plugins for WordPress. One disadvantage of this method is that, this will add an extra plugin to WordPress. It might affect your site speed to some extent. We all want faster Website, don’t we? So, I will recommend you to follow the first method i.e( direct paste)from the three methods to add Google Analytics code to WordPress without any extra plugin or installation.

As always your opinions and feedback is important for us because you are the one who makes our post more valuable and worth reading. Drop your comments to express your thought on this tutorial.