Add Google Analytics to WordPress Website [ With & Without Plugin ]

By: Sunil Kumar |  In: WordPress  |  Last Updated: 2018/11/18

Add Google Analytics to WordPress Website [ With & Without Plugin ]

You have launched a new site and Now you need to know how people are using it, How many people are actually visiting your site, How much time they are spending on your site, which is the main source of traffic on your site and much more.

Google analytics is the one point answers to all the above question

Google Analytics is now the most widely used web analytics service on the web. Google Analytics also provides an SDK that allows gathering usage data from iOS and Android Apps, known as Google Analytics for Mobile Apps.

Creating a Google Analytics Account

To create google analytics account visit google analytics official site fill out all the mandatory information.

create-account-analytics

after filling all the information click “Get Tracking ID” button and you will be asked to accept terms and conditions. After that, you will be redirected to the below screen.

google-analytics-tracking-code

Here in the red box is your google analytics code which will be used to track the traffic information.

#1 Add Google analytics code [with a plugin]

This is the easiest and risk-free way to add google analytics to your WordPress site. Most of the blogger recommending you some paid plugin like monsterinsights But we don’t need to spend money on such a simple task. Free plugins like GA Google Analytics are there to help you to add google analytics code to your website.

Install and activate GA Google analytics plugin to your site.

Now go to the GA Google analytics plugin setting and click plugin setting

GA-Google -Analytics-code

In this plugin, you need to provide the google tracking ID, not the entire Script code. It will generate the script automatically.

Now save the setting and flush cache if you are using any and you are done.

#2 Add Google analytics code without any plugin

This method is for advanced user only As it is a little bit of risky. A little mistake and your site can stop working. So be extra attentive while adding code manually.

Add code to the header.php file

login to your Cpanel account and go to your theme folder. Look for header.php file add the analytics code just before closing the head tag(<head></head>) like this-

<head>

      <!-- EXISTING HEAD CODE -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-128888326-1"></script>
    <script>
       window.dataLayer = window.dataLayer || [];
       function gtag(){dataLayer.push(arguments);}
       gtag('js', new Date());
       gtag('config', 'UA-128888326-1');
    </script>
</head>

Here paste your google analytics code at the end of the head tag(just before</head>).

Now save the file and you are done.

Add via functions.php File

You can also add Google Analytics tracking code to WordPress functions file. It will then automatically add code to every page on your WordPress site.

You will need to add this code to your theme’s functions.php file.

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

Checking Google analytics working Perfectly

After adding the google analytics code you can confirm by visiting your site. When you visit your site or someone else does, you will see the report in your Google analytics account.

 

Comments


Leave a Comment

Your email address will not be published.

*


Sunil Kumar


I am the owner of acmeextension. I am a passionate writter and reader. I like writting technical stuff and simplifying complex stuff.
Know More

Join more than 10,000 others Web Developers