Google analytics helps to track website or blog traffic.

Analytics can show where readers/visitors landed on your site, what they read, how long they stayed, what they searched, the browser they used, where they live, their age and even their interests.

Analytics is the visitors tracking tool for website. With its help, we can track how many visitor come on your blog or website and in which location they visit your website, how long visitors stayed, what kind of browser there used, what kind of operating system they used, what kind of screen Resolution they used, and what they searched.

In your WordPress theme, if you don’t want to add more than plugin then you can manually insert code into your wordpress theme without using plugin.

Here is the easy way to place analytics code into wordpress blog or website.

Add Google Analytics Code into WordPress Theme

Method 1  – Paste Analytics Code Before </head> in Header.php File

Login with Google Analytics Account:-

After Login with Analytic Account , add your website then copy your website tracking code. and, in new tab login into wordpress website/blog.

Login into wordpress website/blog.

In your WordPress Website Admin Dashboard, go to Appearance > Editor. Open Header.php File and Paste Google Analytics Code into Header.php File before </head> close and update it.

Paste Google Analytics Code before Head Section Close

Now your google analytics code is working.

Else you can use Method 2.

Method 2 – Create Function in Function.php File

Go to your WordPress Admin Dashboard and Click on Appearance > Editor.

Wordpress appearance editor

Open function.php file.

Wordpress Theme editor


In function.php, create a Function with any name (example: function googleanalytics() )  in the bottom of function.php file. and paste google analytics code script after echo.


function googleanalytics() {

echo "<script>


(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),



ga('create', 'UA-********-*', 'auto');

ga('send', 'pageview'); </script> \n \n";


add_action( 'wp_head', 'googleanalytics' );

where googleanalytics is function name. You can take some another name on there. and \n for break line from the bottom.

Note: Before using this method, copy the function.php code and save it on notepad file.

Else you can use Method 3.

Method 3 – Use WordPress Plugin Google Analytics by Yoast

Wordpress Google Analytics Plugin by Yoast

If you don’t want to use any of the both method, you can use method 3.

In this we want to suggest you to use wordpress plugin, name is Google Analytics by Yoast. Download this plugin and install in your wordpress blog or website