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.

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 Google Analytics code 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.

Add Google Analytics To WordPress ( Manual vs Plugin ) 6

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:


If you need a more detailed guide to adding a new website to google analytics, 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).

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 Elementor 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.

Add Google Analytics To WordPress ( Manual vs Plugin ) 7

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:

Add Google Analytics To WordPress ( Manual vs Plugin ) 8

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.”

Add Google Analytics To WordPress ( Manual vs Plugin ) 9

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.

Add Google Analytics To WordPress ( Manual vs Plugin ) 10


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:
image size reduce online
Free Image Size Reduction Trick

Without Any Plugin Did you know that a normal website gets most of its weight from the images used in it? It is true. The majority of website size is mostly because of the images used in its pages. Optimizing images without losing quality is a difficult task for average

Read More »
free wordpress hosting
Host Your WordPress Website For Free Forever

Hosting a WordPress website can be an expensive thing if not done properly. It can go from just a few dollars to thousands of dollars a month. Finding WordPress hosting can be a difficult task. If you own a small blog or website that you do not update often then

Read More »
free high quality backlinks
Get Free High Quality Backlinks The Creative Way

A backlink in the SEO world is a link from a post or a page on one website to another. If a website is linking to your content, it means you got a backlink. These backlinks are also called “inbound links”. Sometimes they are also called “incoming links”. Carrying a

Read More »
seo trends 2022
Search Engine Optimization (SEO)
The 10 SEO Trends That SEOs Will Dominate In 2022

To exist is to change, to change is to mature, to mature is to go on creating oneself endlessly. Henri Bergson If you feel like you’re constantly recreating yourself and the way you do SEO, you definitely aren’t alone. It felt as though things couldn’t get any more tumultuous after

Read More »
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
Discord SEO Community Chat
  • Just-iko avatar Just-iko Thank you very much for answering ☑️ ✨
  • ddev66 avatar ddev66 Put your content in the right HTML tags and Google will show it this way.

    In the picture that you show, the first content is put in a list with bold headings.
    The second content is a FAQ on that page.

    Put in the right HTML tags and Google will pick it up nicely.
  • Just-iko avatar Just-iko Hello, I'm a newbie in this field, any guidance would be appreciated :) some questions please, is there any idea on how to make our website could appears like that in Google search? The one that I marked..
  • ddev66 avatar ddev66 Semrush or Ahrefs will help you for spying competitors.

    I think Semrush has a trial period as well.
  • Aadhi avatar Aadhi Buy semrush, you can buy it at cheap rate by using Group buy method
  • SG.CK avatar SG.CK Any free tool for spy traffic and ranking ?
  • ddev66 avatar ddev66 Search on google “htaccess redirect rules”
    Put them in your website’s htaccess file if you are using Apache
  • BrunoAfonso avatar BrunoAfonso how should I go to solve this issue
  • BrunoAfonso avatar BrunoAfonso Can you explain a little bit more? My website is not wordpress, I use amazon web services
  • ddev66 avatar ddev66 You can make a 301 redirect to the correct page on your website.
    If you are using Wordpress then SEO plugins like rank math have this feature.
    If you don’t want to use SEO plugins then there are many good redirect plugins in the Wordpress repository.
    And if you are not using Wordpress then .htaccess file is your friend.
  • BrunoAfonso avatar BrunoAfonso For example, is this image, the second link "THU Main Event" goes to a different page that it's supposed to. How do I fix this.
  • BrunoAfonso avatar BrunoAfonso So I have a website and when you search for it, one of the hyperlinks that google provides goes to the wrong page, is there a specific way for me to change that?
  • ddev66 avatar ddev66 Need more explanation
  • BrunoAfonso avatar BrunoAfonso Hello people, does anyone know how to fix a hyperlink within a google search?
  • ddev66 avatar ddev66 Semrush shows you all the links that it considers as toxic in its domain overview dashboard. You can then use these website list to disavow in GSC.
  • rrakesharmaa avatar rrakesharmaa I want to remove high spam backlinks via Disavow tool. So i need these links.
  • ddev66 avatar ddev66 extract high spam score backlinks.
    This is little confusing for me to understand

    Do you want to remove high spam backlinks to your website or do you want to receive backlinks from websites that have a high spam score?
  • yaswanth avatar yaswanth Now I use the Search console live URL inspector. It shows the page source and screenshot with an error(If any).
    Result: The page is not mobile friendly in the screenshot. All the element's styles are broken.

    Now, I feel like, " What the hell is happening in rich result tester? The google bot shows everything is ok, and in the search console, this is happening."

    # Problem Digging Stage final stage - Solving the problem
    The easiest way to solve the problem is to compare the thing and find the difference.
    Is rich results tester a google bot? Yes!
    Is it owned by google? Yes!
    Is it have any link with the official search console crawler? No!

    Now, What is the difference between 2 crawlers?
    Their IPs are different. They work differently.

    Summary: Google bot (Offical bot) is not able to crawl all elements in the webpage. It is not able to read all styling files. All other bots(services that use crawl as Google Bot) can view/crawl the page.

    List of official google bot IPs:

    Solution: Rather than digging into all files, we changed the hosting server located in the exact location.

    Thank you for reading this article. It takes a few mins to read this article, but It took hours to find the correct problem with a solution. If you find this article valuable, give it a like and if you have any questions, feel free to ask them.
  • yaswanth avatar yaswanth Solving Critical Indexing Problem (CASE STUDY)

    Last week I received a message from a friend he is requesting me to help him index a page of his website. I said, " Wait, sometime google will index automatically" Then he said he was getting problem with his homepage. So, I started digging. First, I want to find the problem. Then all other things were easy.

    # Problem Digging Stage 1 - Analyze the top layers
    Checking the basic things
    1) No Index tags
    2) Canonical tags
    3) Website page Age

    Result: Nothing Found

    # Problem Digging Stage 2 - Getting Deeper
    1) Checking status codes (If there is any redirects, 404 error, or soft 404 errors)
    2) Using an SEO browser to check the web page accessibility
    3) Trying with different user agents

    Result: Nothing Found

    # Problem Digging Stage 3 - Analyzing and
    comparing past and current stages of webpage
    1) Checking the Wayback machine for any spam content history
    2) Checking the search console for errors
    3) Other page's indexability

    Result: I got some clue. Search console shows "Page is not mobile friendly."

    # Problem Digging Stage 4 -Finding the reason for the search console error.
    When I checked the web page with SEO Browser, the page was mobile friendly, and I also tried "crawl as Googlebot." Everything looks good. Then where is the problem?

    One thing was confirmed google is not able to view the webpage clearly. And all other bots are not getting any problems.

    So, I decided to use only google properties in the further process (Because only the google bot gets stuck).
    I selected three tools to process further.
    1) Google page speed insights
    2) Google rich results tester
    3) Search console Live URL inspector

    First, I used page speed insights to check If the google bot can crawl/view the page or not(If there are any issues in crawling, then the tool returns a lighthouse error)
    Result: everything is ok

    Second I used Google rich results tester. It provides the page source and screenshot of the webpage.
    Result: everything is ok
  • achann avatar achann Backlink actually link that provided outside web, so if you use instagram and insert your web link that still counted as backlink.
  • achann avatar achann If you want to be free, why not using mailchimp for email blast. Or maybe you can use whatsender for whatsapp blast, there is nulled version I think.
  • achann avatar achann Um.. Maybe you can use whatsapp blast and give link? Or maybe you can use email marketing and give link to your web?
  • rrakesharmaa avatar rrakesharmaa How can I extract high spam score backlinks for my website? Is there any free tool that provides all high spam score sites HELP ME PLEASE 🙂
  • nkap avatar nkap <@211319858258771968> hey, would you be able to share the website that you want guest posts on? I’m in touch with a few fintech businesses and can ask them whether they’d be interested in putting a post on your site.
  • ddev66 avatar ddev66 <@211319858258771968> it sure will work. Make sure to write that it’s free to post as guests. A lot of websites do not mention this and writers usually think it’s paid opportunity only.

    Keep us updated of how well this goes for your website.
  • soutaraku avatar soutaraku Thank you so much for the detailed guide. I'll see if I can put up the Guest Post page to start with! I hope my email gets bombarded in a good way haha
  • ddev66 avatar ddev66 You should start putting up a page called Guest Posting on your other website where you put articles, etc.. and put all the requirements there which you are looking for in the guest posts. Make sure to leave your email as well for easier contacts.

    Build up some links to this page. Because most of the writers are looking to write for high metrics website that have good DA, TF, etc...

    Once you have a page setup it will help you get attention from people who are searching on Google.

    Next you can start sending the URL of this page to people whom you think might be interested to write for your service on social networks like twitter, linkedin, etc.

    Also list this page URL on websites that have posts like free guest posts list in SaaS, free guest posts list in "your niche", etc. Something like this:

    These will get you enough traction to attract guest posts from various contributors over the time. Your email will be bombarded with emails following the above tips.
  • soutaraku avatar soutaraku I can translate guest post to Japanese and put it on our website to share stories from overseas. I thought it would be interesting for our readers and a good way for link building.
  • soutaraku avatar soutaraku It's not titled as contribute/guest posts page, but there's a website we put interview articles and such. We surely can put guest posts on that website.
  • ddev66 avatar ddev66 <@211319858258771968> does your website have contribute/guest posts page?
  • soutaraku avatar soutaraku Hi guys! I'm a Japanese SEO specialist/ content editor working for a fintech company, and looking for someone to put guest posts on our website (preferably about fintech or SaaS market). Are there any good place to look for people willing to guest post?

    In Japan, not many people write guest posts, so I'm kinda lost. Twitter trick is only guiding light to me, <@838326478924021760>. Thanks for sharing.
  • Deleted User avatar Deleted User trying it out right now
  • nkap avatar nkap Great idea! Will definitely try it out. Thanks mate.
  • ddev66 avatar ddev66 A good trick to get guest posts for your website. <@456226577798135808> <@755307075625549854>
  • Büşra avatar Büşra Thank you very much. I'll try 😊
  • nkap avatar nkap Yeah me too!!
  • naaz avatar naaz <@755307075625549854> Thank you for the detailed answer. Hope <@341197404302737408> finds the right solution for this.
  • nkap avatar nkap <@341197404302737408> Just these:

    You can try 3 things: (I suggest you try the 3rd option first)

    1. If there are any links in your coverage report that’s actually not from your domain/property, I’d recommend you use the Search Console’s removal tool to remove these from your property.

    2. If you’re using any page builders like elementor etc make sure you turn off search engine indexing for things like templates. You can find this in Yoast SEO settings. With this setting your templates and unnecessary pages won’t be indexed. Are you using elementor by any chance?

    3. It’s also possible that your site has been hacked. If random URLs are appearing in analytics and search console the first thing that you should do is check your .htaccess file to see if someone has put any rewrite rules.
  • ddev66 avatar ddev66 <@755307075625549854> got any views on this?
  • ddev66 avatar ddev66 did you change your permalinks sometime back in last few months?
  • naaz avatar naaz <@838326478924021760> bringing to your attention on this.
  • Büşra avatar Büşra hello guys! I need to help about SEO optimation. I'm using wordpress Yoast. I saw dummy link like as `````` I haven't these in page. Btw ı'm using google search console. Why may be this? Is anyone has idea about that?
  • ankit662003 avatar ankit662003 does anyone know how to create seo silos?
  • ankit662003 avatar ankit662003 hi
  • ddev66 avatar ddev66 Just know that we are all here to help each other
  • ddev66 avatar ddev66 No worries mate.
  • Alex25 avatar Alex25 The thing is idk what to ask .
    I'm just stuck
  • ddev66 avatar ddev66 Drop your queries here

Leave a Reply

Your email address will not be published.

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