Skip links
Add google analytics to wordpress website

Add Google Analytics To WordPress ( Manual vs Plugin )

Table of Contents

Many WordPress users struggle to connect Google Analytics to their WordPress sites, and as a result, they miss out on valuable user data.

Fortunately, there are a range of choices for combining Google Analytics with WordPress. These techniques are fairly simple once you know what you're doing and can be useful in a variety of situations.

In this article, I'll explain what Google Analytics is and why it's important for your website. Then we'll show you four different ways to connect it to WordPress so you can start tracking activity.

What is Google Analytics and why its important?

It's best to understand what Google Analytics is and how it functions before linking it to your WordPress account. In a nutshell, this platform tracks the activity on your website and provides you with valuable information to help you develop it:

Google Analytics collects a wide range of data by inserting a code snippet into the header of each of your site's pages, which can be divided into five categories:

Realtime: Shows what's going on on your web at the time you're looking at the article.
Audience: Information about who is visiting your site, including demographics, is included in the audience section.
Acquisition: Explains how the website gets clients.
Behavior: Shows what your visitors do on your web, such as button clicks and the most popular sites.
Conversions: An advanced report that works with Google Analytics Goals to monitor activity including email list subscriptions and e-commerce sales.

The following are some examples of unique data you may find in your Google Analytics reports:

  • At any given time, the number of active users on your site.
  • Over time, how many people visit your site?
  • The ages, races, and locations of your guests.
  • From where do your guests come? (e.g., organic search, social media, etc.).
  • What sites do tourists look at and how long do they linger on them?
  • Bounce, click-through, and conversion rates are all relevant metrics to track.

In your Google Analytics dashboard, there's a lot to see and understand. This will assist you in a number of ways while you work to improve your website.

Importance of Google Analytics

Analytics can be helpful to many facets of your website if you know how to use them effectively. The following are four main areas that are important to every form of site:

A marketing strategy focused on content. You can find out what your visitors like best by looking at your most popular blogs, sites, items, or other content. Growing page views and traffic is as easy as generating more of the type of content that your audience responds to (here's how to get started with keyword research and how to optimise your WordPress site for SEO).

Inbound marketing is a term used to describe marketing that attracts customers Knowing where your traffic comes from will help you find out which marketing tactics are working and which aren't. You can then commit the rest of your time and money to the strategies that achieve the best results.

Segmentation of the audience. To effectively connect with your audience and facilitate conversions, you must first understand them. You can create subgroups for targeted marketing using analytics.

Auditing of the user experience (UX). Problems with your navigation or site design may be exposed by user activity flows. Identifying underperforming content and pages with high bounce rates will help you fix issues.

ALSO READ  Now Post From Facebook To WordPress Without Plugins Officially

The Conversions report is also useful for monitoring sales and revenue if you have an ecommerce platform.

As you can see, the numbers themselves aren't always the most important aspect. The importance is in how you apply the information you obtain from Google Analytics. Increases in traffic, conversions, and revenue can be accomplished by solving problem areas and employing the right marketing strategies for your platform.

Adding manually or with a plugin?

You might assume that using less plugins on your site is better, but this isn't always the case.

It's true that poorly designed plugins will bloat your site and slow it down.

However, a well-designed, lightweight plugin can save you a lot of time and effort while causing no harm.

In reality, the number of plugins on your WordPress site has very little to do with the pace and efficiency of your site. It all comes down to the consistency of the plugins you use.

Then how to add a google analytics tracking code to ?

On the other hand, its also true that using a simple javascript code like the code of Google Analytics directly coded into your theme or design manually decreases the complexity of your WordPress installation as not every plugin is well coded and maintained.

Many other similar posts like these show you complex way of putting the analytics code in wordpress, but here I have tried and tested an easy way too of your website design.

Let's see the manual way of inputting the code before diving into plugins.

Add Google Analytics code without plugin

If you don't want to use a plugin, you can also apply the Google Analytics monitoring code to your WordPress directly either by editing functions.php file or directly putting the code into your website footer which is visible everywhere on your website.

Before you start, make sure you have your WordPress backed-up so that if anything goes wrong, you can revert back easily.

Since you'll be editing the code that creates your site directly, even a slight error like a misplaced comma might bring your entire site down. Make a backup in case something goes wrong.

Step 1. Get the Google Analytics code.

google analytics tracking code

Log into your account, click the Admin section usually at the left bottom. In the property column, click the Data Streams and select your website. This should open up Web stream details page where you need to click the Global site tag tab to get the code.

The Google Analytics code looks something like this:

<!-- Global site tag (gtag.js) - Google Analytics --> 
<script async src="">
window.dataLayer = window.dataLayer || [];   
function gtag(){dataLayer.push(arguments);}   
gtag('js', new Date());   

gtag('config', 'G-'); 

If you need a more detailed guide to adding a , you can check the post here: Adding A New Website To Google Analytics

Step 2: Add tracking code to functions.php

Now, its the time to get your hands into the core files of your theme. You can also add code to header.php but its not a good way of coding external javascript in the header of your WordPress theme.

You can check out this StackOverflow question for more detailed answers on that:

Current recommendations are to place the javascript at the bottom not because it “looks like it loads faster”, but because by placing them there, javascript parsing and execution doesn't stop the browser from doing other things (like loading the rest of the page).

ALSO READ  Adding A New Website To Google Analytics

The one con I can think of is that if you define any objects and functions in external JS and want to use them in the page, you must wait for page load/ready.

Go to your WordPress admin dashboard and Appearance » Theme Editor and select the functions.php file there from the right hand section.

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

add_action('wp_head', 'wpb_add_googleanalytics');
function wpb_add_googleanalytics() { ?>
// Paste your Google Analytics tracking code from Step 4 here

The other way which is much easier without getting your hands on the core theme files like in the above step is to put it directly into the design of your website footer.

If you are using any page designer like or WPBakery Page Builder, then just go to the footer part of it and add the HTML code widget to it. Inside the widget, you can add the Google Analytics code and save.

Since Elementor is more popular these days, plus its free and we use it on RockinWordPress too, I am going to show you the Elementor way.

Go to your page or theme design and select the Edit with Elementor option. Once on the Elementor page, search for HTML and drop down in the footer design.

html code in elementor

Now add the code from Google analytics in this element and UPDATE the page or design.

Although this is an easy way to add the code in your website, if your website has different footers for some pages, you have to add this same code from Google Analytics on each of those footers if you want to track those pages too.

Add Google Anlaytics Code With The Help Of A Plugin.

A Google Analytics WordPress plugin is the easiest way for most WordPress users to integrate Google Analytics to their pages. This approach removes the need to edit the website's file.

I have tried and tested a few plugins on my websites which have performed good. They are as follows:

Site Kit by Google

In just a few taps, this free plugin links Google Analytics to your WordPress account, but that's not all. This plugin pulls data from Google's other services, such as Google Search Console, Google AdSense, and PageSpeed Insights, in addition to analytics, allowing you to create a nice dashboard using Google as your data source.

Here's how to get going:

Install and activate the Site Kit by Google plugin and trigger it, then press the Start Setup button.

When you've successfully linked your Google account, you'll be able to see data from Google Analytics, as well as all of the other services you've enabled, right in your WordPress dashboard. This is how it appears:

Google site kit wordpress plugin

All of this information will still be available from the left-hand sidebar of WordPress.

You might use the next plugin if this plugin is too much for you and you want to keep things focused solely on Google Analytics.

GA Google Analytics

Jeff Starr's free GA Google Analytics plugin has over 400,000 active installations and a 5-star rating:

Here's how to get going:

All you have to do now is add your Google Analytics tracking ID to the Google Analytics WordPress plugin's settings after you've enabled and activated it.

You can also select if the tracking code should be put in the header or the footer, add custom tracking code, force SSL, disable tracking for admin users, and a few other useful options with this plugin.

Scroll down and press the Save Changes button once you've tweaked it to your taste. On your WordPress site, Google Analytics should now be available.

Bonus Tip: Host Google Analytics Locally for Better Performance.

Although this method is not officially supported by Google, I suggest you implement it on your website if you are concerned about the performance of your website.

There are many reasons why you would want to do so. For instance, syncing Google Analytics locally will help you minimise the amount of external HTTP requests you make. You'll also have total control over the file's caching, enabling you to use your own server's cache headers.

This is vital for bettering the website's results. If you use Google PageSpeed Insights, you might have found an alert for your Google Analytics script that says “Serve static assets with an effective cache policy.”

The issue is that, as you can see from the alert above, Google Analytics has a two-hour cache time by default. This is most likely that if Google decides to make a shift, it wants all users to be able to see it as soon as possible.

You can boost efficiency by changing the cache time by hosting the Google Analytics script on your own server.

Using the Complete Analytics Optimization Suite to sync Google Analytics locally

To get started, we suggest using Daan van den Bergh's Complete Analytics Optimization Suite (CAOS), a free plugin he created and developed. It has more than 20,000 active installations and a five-star rating:

You can get it from the WordPress repository or check for it in your WordPress dashboard under Plugins > Add New.

With the CAOS, you can host your Google Analytics JavaScript file (analytics.js) locally and use wp cron to keep it updated (). Other features include the ability to:

  • Anonymize the visitors' IP addresses.
  • Set a bounce rate that has been modified.
  • Change the Google Analytics script's location (header or footer).

Before you use it, make sure all analytics plugins you have enabled are switched off.

google analytics host local


Although Google Analytics is a valuable tool for website owners and managers, it isn't the only analytics tool available.

It's important to keep track of your site's user behaviour, referral sources, and other data if you want to broaden your audience and brand. You can use one of the methods above to link Google Analytics to your WordPress site.

I would suggest to go the manual way if you can. As it helps a lot to keep your WordPress install to minimal. Next I would suggest to go with CAOS and host the Google Analytics script locally. It also gives the option to put it in different part of your website.

Do you know of any other methods to add Google Analytics code to WordPress? I would love to hear them in comments below!

Share This Article:
Related Articles:
Google My Business Reviews WordPress Plugins
5 Best Google My Business Reviews WordPress Plugins Free

Trust. It’s possibly the most crucial aspect of the sales process. Unsolicited, honest feedback from other customers is one of the fastest ways to create customer trust. If there’s one thing Google excels at, it’s designing products and services that appear to smoothly blend into our lives and enterprises. When

Read More »
Subscribe to our newsletter
Chat With Our SEO community members On discord

Leave a comment

This site uses User Verification plugin to reduce spam. See how your comment data is processed.

This site uses Akismet to reduce spam. Learn how your comment data is processed.