How to Add Google Analytics to WordPress (4 Easy Ways)

Add Google Analytics to WordPress

After completing your blog set up with WordPress, it’s time to add Google Analytics to WordPress. In this post, you will get to know how to add Google Analytics to WordPress.

First, I will give you a brief introduction to Google Analytics. I will explain what is Google Analytics and why do you need it.

Next, I will show you how to sign up for a Google Analytics account in a step by step method.

Finally, you will be able to add google analytics to your WordPress blog, choosing any one of the methods I have covered in this tutorial.

Here’s is the table of content for this tutorial –

Table of Contents

  • Introduction to Google Analytics
  • Why Do You Need Google Analytics?
  • How to Sign Up for Google Analytics Account? (Step by Step)
  • How to Add Google Analytics to WordPress
  • Easiest Way to Add Google Analytics to WordPress
  • Add Google Analytics Tracking Code With a Plugin
  • How to Add Google Analytics to WordPress Without a Plugin?
  • Host Google Analytics Locally (Improve Page Speed)
  • The Basics of Google Analytics
  • Final Thoughts
  • FAQs

Introduction to Google Analytics

Most of the beginners have no idea of Google analytics. Basically, to track your website traffic, you need to add the tracking code of Google Analytics to your website.

Google Analytics gives you valuable information about what pages or posts are working well, what is not working, from which country you get the maximum page views, etc. Having all these information, by analyzing them, you can come up with the next best idea to skyrocket your blog’s traffic.

Why Do You Need Google Analytics?

As I have mentioned that Google Analytics gives you the traffic report for your website, you can see –

Who is your audience?

This is where you get the geographical location of the visitor of your blog. Not only the location but also you get the technical insights of your visitor. You get to know what device is being used mostly to visit your blog, what kind of specifications available for the device, etc.

If you know, that most of the visitors use a 720p HD screen resolution, then you need to design your blog compatible with that resolution.

What do your visitors do on your website?

When people came to your website from several sources, what actually they do? You can track the pages they view, the time they spend on your blog, and the bounce rate of your blog.

By looking at all those insights, you can improve your UI of your website and work on improving your content quality to minimize the bounce rate.

The page views of your blog give you the most popular pages, looking at which you can understand what your audience is looking for. And you can create more amazing content related to the most viewed pages.

For the pages with low page views, you can either improve their quality or you can 301 redirect to the relevant updated content of your blog.

What is the source of your traffic?

Here you get to know the sources of your traffic, from where the visitors are coming i.e. organic search, social, referral, or direct.

Organic search means the visitor is coming from a search engine like Google, Bing, Yandex, etc. The pages that are visited from search engines are the pages ranking on search engines.

If you have more traffic from Social Engines, like Facebook, try to optimize your content only for Facebook will give you more traffic.

When do your visitors coming by?

Google Analytics also shows you when the visitors come to your website by the hour, day, or week.

When you know the most active hours of your site, you can schedule your posts to publish at that time to get more traction.

How do your visitors interact with your content?

Google analytics shows how your audience interacts with your blog’s content. It shows you the percentage of the visitors that clicked on the links on your site. If you define some goals, you can also track them.

If you are using e-Commerce functionality, then the Conversion report of Google Analytics is helpful for sales, conversions, and revenue tracking.

How to Sign Up for Google Analytics Account? (Step by Step)

Before adding google analytics to WordPress, let’s see how to sign up for a Google Analytics account.

Step 1: Visit Google Analytics

Click here to visit Google Analytics. You have to sign in with your existing google account. If you do not have any, which very rare! go ahead, and create an account with google.

Step 2: Starting of Sign Up process.

After signing in with your Google account, you will be redirected to the Analytics page (image below). Click on the blue button to start.

Then you will see the create account page, enter an account name there and click on Next.

Step 3: Choose the option on which you’re going to use Google Analytics.

In the next screen, you need to select the option that suits your need. The options are to measure your website, to measure your application (android or iOS), and to measure both website and app. In this case, select Web.

On the next page, enter the website name, website’s URL, country, and time zone. Then click on the ‘create’ button.

Step 4: Agree to Google Analytics terms and conditions.

After that you will see the Google Analytics terms and service page, click on the ‘I Agree’ button.

That’s it, now you have a Google Analytics account for your website. The next page you see contains the tracking code for your website.

How to Add Google Analytics to WordPress

In this section, you’ll get to know how to connect Google Analytics with your WordPress blog.

To track the user activities on your website, the tracking code of Google Analytics must present on every page of your site.

There are a few methods to add Google Analytics code to your WordPress blog. To integrate Google Analytics to your WordPress site, you can use one of the following ways that best suits your need.

Let’s get started …

Easiest Way to Add Google Analytics to WordPress

The easiest way to connect Google Analytics to your blog is by using a plugin. The plugins, that are specific for Google Analytics only, save you from digging deep into the more technical side of WordPress.

This method is suitable for a non-techy. By just installing the plugin and then filling up some details will result in the tracking of user activity of your blog.

There are several plugins out there to add Google Analytics to WordPress. Let’s see the official plugin by Google for WordPress.

Site Kit by Google

This is the official WordPress plugin from Google. A simple but powerful plugin for WordPress users to use everything that Google offers to make them successful on the web.

With just a few clicks you can easily integrate Google Analytics to your blog with Site Kit. Not only Google Analytics insights but also Google Search Console, Google AdSense, and PageSpeed Insights can be integrated and viewed within your WordPress dashboard.

Let’s see how to get stared with Site Kit.

Search for Site Kit plugin and then install and activate it.

Then click on Start setup button.

Now you have to sign with the google account that used to sign up for Google Analytics account. Then you have to go through a verification process and give permission to google site kit to access your Google Analytics account.

On successful completion of the setup process, you can see the data from Google Analytics directly in your WordPress dashboard.

That’s how you can add Google Analytics to WordPress using Site Kit by Google.

After that, if you wish to use the other three services on Site Kit, go through the similar verification process that you are the owner of your site, and give the permissions required.

Some other popular plugins to add Google Analytics to WordPress are Google Analytics Dashboard Plugin for WordPress by MonsterInsights, Google Analytics Dashboard Plugin for WordPress by Analytify, etc.

Add Google Analytics Tracking Code With a Plugin

Remember the tracking code, when you signed up for Google Analytics account? You can add that code to the function.php file using a plugin.

If you don’t use a child theme and insert optional codes using a plugin, then this method is for you.

Now to do that, I use the plugin, Code Snippets and in my opinion, a great plugin to insert codes into the functions.php file.

Let’s see how to use the Code Snippets plugin to add Google Analytics to WordPress.

Code Snippets Plugin

Using Code Snippets plugin is an easy, and simple way to run PHP code snippets on your site. It removes the need to use a child theme for your site.

Just search for the plugin and install it.

Then go to Snippets and click on Add New.

Now, copy the tracking code from your Google Analytics account, and paste it as shown below –

add_action( 'wp_head', function () { ?>

// Paste your Google Analytics tracking code

<?php } );

Replace Your tracking code with your GA tracking script. Then click on the radio button for Only run on site front-end. Then click on Save Changes and Activate.

Done! Now you can see the user activities on the Google Analytics dashboard.

How to Add Google Analytics to WordPress Without a Plugin?

To start tracking your visitors, the Google Analytics code needs to be present on the entire site of your website except the admin area. Usually, each and every pages and posts of your website.

Here’s how you can add Google analytics to WordPress manually.

Option 1. Insert the tracking code into functions.php

You can achieve any functionality using the functions.php file of your theme. It is better to edit the functions.php file when you’re using a child theme. Otherwise, each change you make to your theme will be erased when you update the main theme.

To add Google Analytics tracking code, simply edit the functions.php file. Then add the following code –

<?php

add_action('wp_head', 'googleanalytics_code');

function googleanalytics_code() { ?>

// Paste your Google Analytics tracking code

<?php } ?>

Option 2. Insert the tracking code into header.php

Another way to add Google Analytics to WordPress without using a plugin is to add the tracking code to the header code of your theme. The header will load on every page of your website, so this way you can have Google Analytics installed on your website.

Again, if you’re editing any file of your WordPress theme, make sure to use a child theme.

To add the tracking code into the header.php, paste the tracking code before the</head>tag of the file.

<?php

/**

* The template for displaying the header

*/

?>

<!DOCTYPE html>

<html <?php language_attributes(); ?>>

<head>

//Some theme codes

//Paste the tracking code here

</head>

Now, save the file and that’s it.

Use the custom functionality of some themes

Some themes offer custom codes to add to the main theme itself. For example, I am using GeneratePress’s Elements to add the Google Analytics code.

You can use your theme’s native functionality as well to add Google Analytics code also.

However, you can not use this method, if you’re using a free theme on your website.

Host Google Analytics Locally (Improve Page Speed)

If you want to get rid of the performance overhead caused by the Google Analytics script, then this method is for you. You can host the tracking script locally on your own server.

Note: Hosting the JavaScript file locally is not recommended by Google.

So, why do you want to do it?

There are a couple of reasons to host the tracking code on your server. First, you can control the cache policy of the code, which is set to 2 hours by Google. Next, the number of HTTP requests can be reduced by using this method.

These are some factors that affect the performance of your website. When you use the PageSpeed Insights, you may see the Serve static assets with an efficient cache policy warning for Google Analytics script.

To reduce the overhead by the script, we will use a free plugin to host the Google Analytics code locally.

Complete Analytics Optimization Suite (CAOS)

CAOS is a free plugin that allows you to host the JavaScript file (analytics.js) locally. Also, this plugin updates the scripts automatically using WordPress’ built-in Cron-schedule.

To get started with CAOS, install, and activate this plugin. Then, enter the tracking code. After that, the plugin adds the Tracking Code for Google Analytics to the header (or footer) of your theme.

The plugin downloads and saves the javascript file to your website’s server and keeps it updated using a scheduled script in wp_cron().

Also, CAOS is fully compatible with Google Analytics Dashboard Plugin for WP by MonsterInsights, WooCommerce Google Analytics Integration, Google Analytics Dashboard Plugin for WP by Analytify, and Google Analytics Dashboard for WP by ExactMetrics.

The Basics of Google Analytics

Since you’ve successfully added Google Analytics to WordPress, now let’s have a look at the Google Analytics dashboard. So, you get a quick understanding of the information you can find.

When you go to the Google Analytics home page, the left sidebar has the different sections of data to look at. The five key areas that are relevant to any type of site include the following –

  • Realtime: This shows you the visitors of your website at that very time, you open this report. How many visitors you have, their geographical locations, which pages they are viewing, etc.
  • Audience: This report helps you to learn more about your website visitors. The information like, how many visitors you had over a period of time, the system they use, their language and locations, etc.
  • Acquisition: It shows you the traffic sources and other relevant information regarding those sources.
  • Behavior: In this report, you will find the page views, bounce rate, unique pageviews, etc. Also, you can see the average page speed of your website and many more.
  • Conversion: When you set up goals, then you can track the conversions using Google Analytics and this report shows you, how well the conversions are going on.

Final Thoughts

Google Analytics is a free tool to track the site’s user activity, referral sources, and other data. This will help you understand and grow your audience and let you improve more by showing the downside of your site.

To add Google Analytics to your WordPress site you can use one for the following ways –

  1. Add Google Analytics to WordPress with a plugin (Easiest Method)
  2. Add Google Analytics tracking code to your site using a plugin
  3. Add Google Analytics to WordPress without a plugin
  4. Host Google Analytics code locally to improve performance score

So, There you have it.

Now, you know how to add Google Analytics to WordPress. Do you have any other methods to install Google Analytics? Let me know in the comment section below.

Which one of the above methods you’re going to use?

And if you like this article, feel free to share it.

FAQs

How do I add Google Analytics to my WordPress site?

To add Google Analytics to your WordPress site you can use one for the following ways –

  1. Add Google Analytics to WordPress with a plugin (Easiest Method)
  2. Add Google Analytics tracking code to your site using a plugin
  3. Add Google Analytics to WordPress without a plugin
  4. Host Google Analytics code locally to improve performance score

Is Google Analytics free for WordPress?

Most of the plugins for Google Analytics are free but there may be some up-sell model. The Site Kit by Google is a free plugin that can set up Google Analytics in a few clicks.

How do I install Google Analytics without WordPress Plugin?

Here’s how you can add Google analytics to WordPress manually:
Option 1: Insert the tracking code into functions.php
Option 2: Insert the tracking code into header.php
Option 3: Use the custom functionality of some themes

«
»