How To Easily Add Google Analytics Code In Your WordPress Blog

Add Google Analytics in WordPress

Google Analytics lets you track almost every activity on your website. So, if you’ve created your Google Analytics account and generated the tracking code, being a beginner you might feel difficulty in adding it to your WordPress blog to start tracking visitors.

You would know that you’re required to add the Google Analytics code to the <HEAD> of every web page of your blog. It simply means, you need to add the tracking code to the header area of your WordPress blog.

There’re are many methods of adding Google Analytics code in your WordPress blog. You can either do it using a plugin or by editing theme files (header.php and functions.php).

Add Google Analytics Code Using a WordPress Plugin

This is the best and easiest way to add Google Analytics tracing code to your WordPress blog. There’re many WordPress blogs available to insert Google Analytics code to your WordPress blog, but one of the best and flexible plugin I recommend is Insert Headers & Footers plugin.

So, very first you need to install and activate this plugin in your WordPress. To do so, go to Plugins › Add New and search for Insert Headers & Footers or you can directly download the plugin from WordPress Plugins Repository and install it. Once installed, activate the plugin.

After activating the plugin, go to Settings › Insert Headers & Footers from your WordPress dashboard and paste the Google Analytics code in the Header script area, as shown in the following picture.

Insert Headers and Footers Settings

As soon as you’ll click the Save button, the Google Analytics code will be added to your WordPress site and you can start tracking visitors to your blog in Google Analytics.

It’s the most easiest way to insert Google Analytics code in WordPress site. However, for any reason if you’re not willing to install any additional plugin to your WordPress, you may directly add the code via header.php or functions.php file. Let me guide you for both.

READ ALSO: The Most Affordable Managed WordPress Hosting

Add Google Analytics Code in Theme’s Header File

If you don’t want to use any plugin, you can add Google Analytics code to your header.php file very easily. All you need to go to Appearance › Editor › header.php to open the header.php file of your WordPress theme.

Now, look for </head> in the header.php file. You can paste your Google Analytics code just before this </head> tag. Adding the code after opening <body> tag will also work.

Don’t forget to click Update File button to save changes to the server. That’s all about adding Google Analytics code in your WordPress header.php file.

Add Google Analytics Code in Your Functions File

You can also use your theme’s functions.php file to insert Google Analytics tracking code into every page of your WordPress blog. Just go to Appearance › Editor › functions.php and copy and paste the following function in your functions.php file.

<?php add_action('wp_head', 'add_google_analytics');
function add_google_analytics() { ?>
// Paste your Google Analytics code here
<?php } ?>

Now, all you need to paste your Google Analytics code in the above function at the marked spot. And it will automatically add the Analytics tracking code to every web page of your website.

Add Google Analytics Code in Genesis Framework

If your blog is running with Genesis Framework, it becomes even much easier to add Google Analytics code. Neither you need to install any plugin for that nor you have to insert it through editing any of your theme files. This is because Genesis Framework lets you directly add Google Analytics add via its Theme Settings area.

Just navigate to Genesis › Theme Settings and scroll down to Header & Footer Scripts area. And paste your Google Analytics code to Header Scripts box and save changes. It’s all.

Genesis Framework Theme Settings - Header Scripts

So, that’s all about adding Google Analytics code into your WordPress to start monitoring your blog’s visitors. One of the best and hurdle-free method to add Google Analytics code is by using a plugin.

Most bloggers suggest keeping less plugins for optimum performance and this is true also but if you’re installing a light-weight plugin like Insert Headers & Footers, it won’t affect the performance of your blog.

There’re many benefits of using a plugin instead of editing your theme files for inserting Google Analytics code such as at any point of time if you update, customize or just change your theme, it won’t affect tracking if you’ve inserted Analytics code using a plugin.

Otherwise, if you’ll inserted Google Analytics code through theme files like headers.php or functions.php, you’ll be required to add the code again after updating or changing your theme.

Leave a Reply