how to add analytics to wordpress without a plugin

How to Add Google Analytics to WordPress Without a Plugin

Looking for a way to add Google Analytics to WordPress without a plugin?

Setting up Google Analytics on WordPress helps you track your website traffic and provides valuable insights about your visitors.

Let’s take a look at how to add Analytics tracking code to WordPress without a plugin.

Table of Contents

To help you out, we’ve divided this article into different sections. You can jump ahead to any section you’re interested in:

MonsterInsights is the best WordPress Analytics plugin. Get it for free!

Why is Google Analytics Important for Your WordPress Website?

Google Analytics

Once you’ve started a WordPress website, you should know how it’s performing. And to get this useful data, you need Google Analytics. It’s a powerful tool that helps you understand how people use your site.

Here are some benefits of using Analytics:

  • Identify Traffic Sources – You can find out where your visitors come from, which channel they use (search, social, paid, etc.), which country they belong to, and more.
  • Better Understand Your Audience – Once someone lands on your website, what do they do? With Google Analytics, you can track their every interaction and see what links they click or which files they download.
  • Create Content That People Like – Google Analytics helps you track your pages and posts, so you know which content drives a lot of traffic. This way, you can find similar topics to cover and boost your traffic.
  • Conversions and Sales – If you have an eCommerce store, then Google Analytics can help you track your conversions and see how much revenue your store is making.
  • Improve Your Site’s User Experience – Find out how people behave on your site, which pages they visit, which device or browser they use so you can improve the user experience of your website.

Let’s look at the pros and cons of different installation methods.

Drawbacks of Adding Google Analytics Without a Plugin

If you’re planning on adding Google Analytics without a plugin, then here’s why it may not be the best choice for your site.

1. It’s Not as Easy as It Seems

Adding Google Analytics to your site without a plugin is not as easy as with a plugin. That’s because you’ll have to enter the tracking code in the header of your website. This means editing code, which can be a challenge for beginners.

Any mistake you make while adding the tracking snippet can mess up your analytics or even bring down your entire website.

Plus, if you want to enable additional tracking reports such as downloads tracking or eCommerce tracking, again you’ll have to manually tweak your theme’s template. With a plugin, on the other hand, enabling such reports is a breeze.

2. You May Lose the Tracking Code

If you decide to switch your website themes or upgrade your existing one, you will have to add the Analytics tracking code again to your new theme.

More often than not, website owners forget to preserve the code while upgrading their theme.

This will leave gaps in the data and lead to inaccurate reporting. And you could be missing out on important user insights while the tracking code wasn’t present on your site.

3. You Miss Powerful Analytics Features

Adding Google Analytics without a plugin means you’ll miss powerful features like media tracking, custom dimensions, file download tracking, affiliate tracking, form conversions, and outbound link clicks.

And without a plugin, it’s very time-consuming to set up these features on your WordPress site.

Plus, if you have an online store or sell a product on your site, you’ll also miss out on eCommerce tracking, meaning you won’t get to track your revenue or which products customers buy the most.

ecommerce report conversion tracking monsterinsights

So, what’s the best way to add Google Analytics to your WordPress site?

The easiest method for adding Google Analytics to WordPress is through a plugin like MonsterInsights. It’s the best WordPress analytics plugin out there. It makes it very easy to set up tracking, and you don’t have to worry about all the drawbacks of implementing Analytics without using a plugin. MonsterInsights works with Universal Analytics, Google Analytics 4, or both with our Dual Tracking feature.

Plus, MonsterInsights lets you set up advanced tracking features with just a few clicks, such as:

To start, just follow these simple steps to add Analytics to your website.

Step 1: Sign Up for Google Analytics

First, you will need to sign up for Google Analytics. You can use an existing Google account to sign up for Analytics or create a new one.

sign up for analytics

Step 2: Connect Analytics to WordPress with MonsterInsights

Next, you can install and activate MonsterInsights on your WordPress website. Once the plugin is up and running, all you have to do is use its setup wizard to add Google Analytics to WordPress without editing code.

select ga property

You can read how to properly set up Google Analytics in WordPress with MonsterInsights.

After you’ve added Google Analytics, MonsterInsights will bring all your important data inside your WordPress admin area. You can then use its dashboard reports to see how your site performs and uncover insights about your visitors.

overview report monsterinsights

Now, if you’d rather set up Google Analytics without a plugin, follow the step-step guide below.

Add Google Analytics to WordPress Without a Plugin

Before we get started, make sure to backup your WordPress theme, so in case something goes wrong, you can easily revert it.

You’ll be directly editing the code that outputs your site, so a mistake as small as a misplaced comma could bring down your whole site. Be sure to make a backup just in case.

Video Tutorial

You can also take a look at the written steps to learn how to set up Google Analytics without a plugin in WordPress.

Step 1: Get Your Google Analytics Tracking Code

Log into your Google Analytics account and select the website for which you need the tracking code.

Select a Google Analytics Account

Click on Admin in the left taskbar.

In the property column, click Tracking Info and then Tracking Code.

get google analytics tracking-code

Or, if you’re using Google Analytics 4, click Data Streams in the middle column, then choose the one you need.

GA4 Data Stream

Now you can get the tracking code under the Website tracking section (in Universal Analytics). Just copy the Google Analytics script.

download tracking code

In Google Analytics 4, head to Tagging Instructions » Global Site Tag to copy your code.

GA4 gtag code

Step 2: Add the Tracking Code to the header.php File

Now, are you wondering where to place Google Analytics tracking code on your website?

Log in to your WordPress dashboard and navigate to Appearance » Theme Editor. Now click the Theme Header (header.php) file on the right-hand side below the Theme Files section.


Paste the tracking code you just copied from your Analytics profile before the closing </head> tag. 

Then click Update File.

That’s it!

You’ve just learned how to add Google Analytics to WordPress without a plugin.

But if you’re looking for a simpler method, then MonsterInsights is the best solution. It’s one of the most popular Google Analytics WordPress plugins and makes it super simple to connect your site with Analytics.

Get Started with MonsterInsights Today!

Bonus: More Google Analytics and WordPress Tips

If you’re thinking about adding Google Analytics to WordPress, there are probably another few things you’re wondering about. We’re going to add some links here that we think might help!

Beginners Guide to WordPress: WPBeginner

If you’re a WordPress beginner, we highly recommend the WPBeginner blog. You can find answers to just about anything having to do with WordPress!

7 Types of Google Analytics Reports

Wondering where to start with Google Analytics? Read about the top 7 types of reports you can use to grow your business.

How to See the Google Analytics Keywords for Your Website

Google Analytics doesn’t show you the keywords people use in Google to find your site by default. Read our guide to find out how to see them!

How to Get a Simple Weekly Google Analytics Report by Email

Want a hands-off solution for reporting? You don’t have to run reports yourself. Just follow our guide to set up automatic ones!

That’s it!

If you’re still wondering whether it’s a good idea to install Google Analytics without a plugin, you should check out our post on is MonsterInsights worth it.

After installing Google Analytics, you might also want to stop Google Analytics from tracking logged-in WordPress users. And if you want, you can also check out our amazing guide on How to See the Google Analytics Keywords for Your Website.

For more tutorials like this, follow us on Twitter, Facebook and YouTube .

Want to Try MonsterInsights for Free?

Enter the URL of Your WordPress website to install MonsterInsights Lite.


    1. Sunil,
      You just need to follow the tutorial. It will add the Analytics tracking code to the entire site.

  1. This is completely true. Monster Insights will not slow down your site at all. We have done extensive testing and every-time this plug in comes out on top with no speed loss.
    We even testing no cache on a site with Google page speed installed on the Apache server and only used Yoast and Monster insights. Still no speed loss at all.
    So it is 100% true what Monster Insights tells you here, it’s the coding of the plugin that matters most. Quit using junk plugins.

    1. Can I also follow the traffic though Google Analytics when I install your plugin or can I only track in through your plug in?

      1. Hi Scott, you can track your traffic through Google Analytics 🙂

        MonsterInsights brings important stats inside your dashboard, so you can view your site’s performance at a glance.

  2. I don’t have a header.php section in my theme. It is a child theme so maybe that is why. I have no idea, but really have no idea where to put this code.

    1. Hey Stacy! Thanks for stopping by the blog. Yes, if you’re using a child theme that doesn’t have a header.php, that means it’s using the header.php from the parent theme.

    1. I think tracking code option that you have shown on your article has been changed…. google anylatic now dont have tracking code…instead of tracking code they have property id….. Kindly update the latest process.

      1. Hi Vikash,

        Thanks for reaching out!

        We’re really excited to launch support for Google Analytics 4 soon. At this time, we’re waiting for Google to release some APIs for the public to use.

        For now, we currently support Universal Analytics properties which we recommend users stay with until we’re ready to launch. When this happens, we’ll be reaching out to users with a simple, seamless upgrade.

        For your Google Analytics property to work with MonsterInsights, please enable the option “Create a Universal Property only”, found under the advanced options when creating a new property. Here’s our step by step guide on how to do this:

        I hope that helps! Let me know if I can answer any other questions 🙂

        Thank you!

  3. If I have synced my google analytics with the MonsterInsights plugin, does this mean my iOS google analytics app will get the same data?

    or will I still need to insert the global tag in my header.php to get the google analytics app to display the correct info?

  4. Hey MonsterInsights – I need some advice.

    I have developed a new website, an upgrade from an existing website which has very strong SEO and Google Analytics History (and is a 55 page website).

    I will be making the new website go live on the existing Domain Name by just switching the A record for it some time very soon.

    If I implement MonsterInsights on the new site with the existing GA tracking code, will it push that tracking code across the whole new website/pages and at the same time, will the GA history be kept on GA?

    1. Hey Sami, thanks for reaching out!

      Yes, if you use the same tracking code from the same Google Analytics property, you’ll keep your data.

      A quick tip when launching a new site: Especially if your page URLs are changing, it can be really helpful to create a new View in Google Analytics on go-live day. That way, you can easily see your new website data apart from the old stuff. Of course, data will still populate in the old views too 🙂 Just can be helpful to be able to see the new data on its own. Here’s a guide on creating a new view:

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our privacy policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.