Add Google Analytics to WordPress WITHOUT a Plugin (2022)

Looking for a way to add Google Analytics tracking code 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 your Analytics tracking code to WordPress without a plugin.

Table of Contents

Why Add Google Analytics Tracking Code to WordPress Without a Plugin?

Google Analytics

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

There are a few reasons why WordPress website owners might think they want to add Google Analytics to WordPress without using a plugin.

First of all, they might be concerned that they’re using too many plugins. Too many plugins that aren’t optimized well can slow down your WordPress site (although properly optimized plugins shouldn’t slow it down).

Second, they might also be concerned about the price of using a Google Analytics plugin. Although there are definitely benefits of paying for a Pro version, a free version can help you get Google Analytics installed and running well, too.

Third, they might know how to install the Google Analytics code, so they feel like they don’t need a plugin to get set up. Even if you know how to install Google Analytics, though, that doesn’t mean you can’t benefit from any extra features of Google Analytics plugins.

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 paste 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: Tutorial

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: Where to Add the Tracking Code in WordPress

There are two options for where to add Google Analytics code in WordPress: header.php and functions.php.

Option 1 – header.php

The first place you can add your tracking code to your website is in your header file.

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.

how-to-add-google-analytics-to-wordpress

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

Then click Update File.

Option 2: functions.php

Your other option for adding Google Analytics to your site without a plugin is by inserting some code in your functions.php file:


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

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!

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 learn How to Track Link Clicks in Google Analytics 4 and WordPress. 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 .