How to Insert Google Analytics Code For WordPress

Google Analytics is the best and precise way to analyze the traffic you are getting onto your website. Google analytics will tell you the exact quantity of visitors per day onto your website. The stats can be calculated according to the country, language, organic searches, social signals, etc. This complete information ultimately helps you to collect all of the traffic data from one platform and save it for your audit.

Well, as you have known about the benefit of Google Analytics, there is one problem that many of the bloggers and website managers face about Google Analytics. That problem is how to insert Google Analytics code into the header file of your web page. It is necessary to place the tracking code of Google Analytics into the header code of the web page for which you want to analyze the traffic status. There are several methods to insert the Google Analytics code into the header file of the page and I am going to describe 3 useful methods for it. Let’s talk now.

Google Analytics Code

Methods to Use Google Analytics Code

Method No. 1

The easiest and the most reliable method is to insert the Google Analytics tracking code into the header file manually. Also, it is the quickest way and easiest way to do that. First, copy the tracking code that Google Analytics will provide you with. Now, go to the WordPress dashboard and click on Appearance. In Appearance you will see Editor, click on it and search the header.php file and insert your tracking code after the <body> tag or before the </head> tag.

This way you can just insert the code within a minute. The only thing that can be a disadvantage is that when you change the theme of WordPress, you have to re-insert the code into the header file.

Method 2

The 2nd way to do so is to insert the Google Analytic tracking code into the file named “function.php”. This one is also a simple and manual way to do, but you need to insert a code into the function file. The code will be


<?php add_action(‘wp_head’, ‘add_google_analytics’);

function add_google_analytics() { ?>

// Paste your Google Analytics code here

<?php } ?>

The benefit of doing it is that your header file will be lighter as it was before placing the code. The load will be at the function file, not the header file. On the other hand, for the security reason, function file may be restricted to edit, so before doing anything, you need to make sure that everything is like I am telling you otherwise go to the next method.

Method 3

Method 3 is the automatic way to insert the Google Analytic tracking code into the header file of the WordPress. This way you just need to install a plugin and follow the instructions of the plugin and you will be done. There are a lot of plugins for this purpose. The benefit of using it that code will be there every time even after you update the theme or change the theme or even customize it. The only disadvantage is that you need to be careful selecting the proper plugin for you because they can change the style of your website or can be a cause of total blank page. Sometimes every plugin does not work.

Written by Thomas Tucker

 1,903 total views,  2 views today

How many stars?

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
No comment yet, be the first!

What's your idea?