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 Nova.com (ga.js)
// @ https://developers.google.com/analytics/devguides/collection/gajs/
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; ?>']);
_gaq.push(['_trackPageview']);

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

<?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.

16
Leave a Reply

avatar
14 Comment threads
2 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
15 Comment authors
Joyita Paul ChowdhuryChetaruMatt Selby PhotographyAreesha NoorRiya Rai Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Shreya
Guest
Shreya

Great post !! Adding codes to themes header is the great option but we need to remember this thing when we changing theme. Faced this situation already and lost 1 day analytic data. i prefer to use plugin for analytic codes

sam
Guest

nice post bro you explained clearly how to add analytics to our wordpress blog

jossef
Guest

WOW thanks for the information but I don’t see a need to add Google analytic to your blog how it can be of any benifit ?

Amanda Rinai
Guest

Nice Share, I used to be only using google webmaster and bing only, i never use google analytics , but i will try it, thanks for the information…

satishw.r
Guest
satishw.r

Adding codes to themes header is the great option but we need to remember this thing when we changing theme.thanks for the information
Thanks for blog

Amir Hamjah
Guest

Great Post. This is such a very helpful content. Thanks.

Sunny
Guest

Great Deepak, Actually i am a New in Online Industry ,i have my own word press website and google analytics account. Thanks for giving information for google analytics to word press especially for google analytics by yoast plugin.

Keep Sharing Deepak

sanghamitra chowdhury
Guest

Hi,I have already attached google analytics code via plugin but I am not able to see the sources of referral traffic or anything..like from what different sources the traffic is coming?

Rintu Biswas
Guest

Hey Deepak, very nice article you have written.

I have a question:

What is the best SEO plugin between Yoast WordPress SEO and All in One SEO?

Riya Rai
Guest

I simply took a google analytic plugin and wrote the unique code given by google analytic and It started working

Areesha Noor
Guest
Areesha Noor

Hi Deepak,

Great post indeed!
Google Analytic is really great tools to track visitor, and searches data etc. Actually I am using plugin for this purpose but I think coding system is also good.

Any way thanks Deepak for sharing such great information with us.
Regards:
Areesha Noor!

Matt Selby Photography
Guest

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

Chetaru
Guest

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
Guest

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.

Thanks
Joyita

Pin It on Pinterest

Share This