Most guides on this topic skip the honest part: adding Google Analytics to WordPress without a plugin is possible, but it comes with real trade-offs that beginners don’t always find out until something goes wrong.
We’ve seen it firsthand — a theme update wipes the tracking code, or a small code mistake in header.php takes down the whole site. If you’re going the manual route, it helps to know exactly what you’re signing up for before you start.
In this guide, we’ll walk you through why you might want to skip a plugin, what the real drawbacks are, and how to do it correctly if that’s the path you choose. We’ll also show you the faster, safer alternative if you’d rather spend that time on something else.
In This Article:
- Why Add Google Analytics Tracking Code to WordPress Without a Plugin?
- Drawbacks of Adding Google Analytics Without a Plugin
- Recommended Method for Adding Analytics to WordPress
- Add Google Analytics to WordPress Without a Plugin: Tutorial
- Video Tutorial: Adding Google Analytics to WordPress Without a Plugin
- FAQs About Adding Google Analytics to WordPress Without a Plugin
Why Add Google Analytics Tracking Code to WordPress Without a Plugin?
There are a few reasons why WordPress site owners think they want to add Google Analytics without using a plugin.
First, they might be concerned about using too many plugins. Using too many poorly optimized plugins can slow down your site — though properly built plugins shouldn’t slow it down.
Second, they might be worried about the cost. There are real benefits to a Pro license, but a free version is enough to get Google Analytics installed and running.
Third, they might already know how to paste in the tracking code and figure they don’t need help. Even if you do, though, a plugin still unlocks features you can’t easily set up on your own.
Drawbacks of Adding Google Analytics Without a Plugin
If you’re planning on adding Google Analytics without a plugin, 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 more involved than using a plugin. You’ll have to paste the tracking code into your site’s header, which means editing theme files — a real challenge if you’re not comfortable with code.
A single misplaced character can break your analytics or take down your entire site.
And if you want advanced reports — like file download tracking or eCommerce tracking — you’ll need to manually edit your theme’s template files too. With a plugin, enabling those reports takes a few clicks.
2. You May Lose the Tracking Code
If you switch themes or upgrade your existing one, you’ll have to add the tracking code all over again.
Site owners forget to do this more often than you’d expect. That creates gaps in your data and inaccurate reporting — and you could be missing critical user insights the entire time the code is gone.
3. You Miss Powerful Analytics Features
Going without a plugin means skipping features like media tracking, custom dimensions, file download tracking, affiliate link tracking, form conversions, outbound link clicks, and more — all of which take significant effort to set up manually.
If you have an online store, you’ll also miss out on eCommerce tracking unless you go through a complex Google Tag Manager setup. That means no revenue data, no product performance reports — nothing that actually tells you what’s selling.
So, what’s the best way to add Google Analytics to your WordPress site?
Before You Switch Methods
The manual method only gives you a basic tracking snippet. The features most site owners actually need — eCommerce tracking, file downloads, form conversions — require either a plugin or a complex Google Tag Manager setup. If those features matter to you, the plugin route will save you hours.
Recommended Method for Adding Analytics to WordPress
The easiest way to add Google Analytics to WordPress is through a plugin like MonsterInsights, a WordPress plugin that connects GA4 to your site without touching a single line of code. It’s the best WordPress analytics plugin out there.
With MonsterInsights, you don’t have to worry about any of the drawbacks above. Setup takes minutes, not hours, and you won’t lose your tracking code the next time you update your theme.
MonsterInsights also lets you set up advanced tracking features with just a few clicks, such as:
- eCommerce and User Journey tracking for your WooCommerce, Easy Digital Downloads, GiveWP, MemberPress, LifterLMS, Restrict Content Pro, and MemberMouse stores
- File download tracking to see how many times each file is downloaded
- A popular post/product widget so you can show your most popular posts or products to your audience
- Media tracking to see what videos are getting watched on your site
- Form conversion tracking across your website
- And much more!
I’d recommend starting with the setup guide below to get everything connected properly.
Step 1: Sign Up for Google Analytics
First, sign up for Google Analytics. You can use an existing Google account or create a new one.
If you’re not sure whether you need an account yet, our guide on whether your site needs Google Analytics is worth a quick read first.
Step 2: Connect Analytics to WordPress with MonsterInsights
Next, install and activate MonsterInsights on your WordPress site.
Get started at the best license level for your site, or start with the free version of MonsterInsights.
Once the plugin is active, the setup wizard walks you through connecting Google Analytics to WordPress — no code editing required.
You can read the full walkthrough on how to set up Google Analytics in WordPress with MonsterInsights.
After you’ve connected Analytics, MonsterInsights brings all your important data right inside your WordPress dashboard. From there, you can use its dashboard reports to see how your site performs and uncover insights about your visitors.
If you’d rather set up Google Analytics without a plugin, the step-by-step guide below covers exactly that.
Add Google Analytics to WordPress Without a Plugin: Tutorial
I recommend making a full backup of your WordPress site before starting. You’ll be directly editing the code that outputs your site, so a mistake as small as a misplaced comma could bring it down. Take that backup first — it makes the whole process much less stressful.
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.
Click on the Admin Cog in the left taskbar.
Click Data Streams, then choose the one you need.
Once inside your data stream, scroll down and click View tag instructions. On the next screen, switch to the Install manually tab to copy your Google Analytics script.
Not sure which data stream to pick? Our guide to GA4 Measurement IDs explains how they’re structured and which one belongs to your site.
Step 2: Where to Add Google Analytics Tracking Code in WordPress
There are two options for where to add Google Analytics code in WordPress: header.php and functions.php. Both work, but they come with different risks — it’s worth understanding where and how to add Google Analytics code in WordPress before choosing one.
Option 1 – header.php
The first place you can add your tracking code is in your theme’s header file.
Log in to your WordPress dashboard and navigate to Appearance » Theme Editor. Click the Theme Header (header.php) file on the right-hand side under the Theme Files section.
Paste the tracking code you just copied from your Analytics account before the closing </head> tag.
Then click Update File.
Option 2: functions.php
Your other option is to insert some code into your functions.php file:
<?php
add_action('wp_footer', 'add_googleanalytics');
function add_googleanalytics() { ?>
// Paste your Google Analytics code here
<?php }
?>
I’d recommend making these edits in a child theme rather than your main theme files, so your tracking code survives any theme updates. If you’d prefer to skip direct file editing altogether, WPCode is a lightweight code snippets plugin that handles this cleanly without putting your theme files at risk.
You’ve added Google Analytics to WordPress without a plugin.
If you’re looking for a simpler method, MonsterInsights is the best solution. It’s one of the most popular Google Analytics WordPress plugins and makes it easy to connect your site with Analytics.
The Easiest Way to Add Google Analytics to WordPress
MonsterInsights connects your WordPress site to Google Analytics in minutes — no code editing required. Get in-dashboard GA4 reports, eCommerce tracking, file download tracking, and more, all set up through a simple wizard.
Get Started with MonsterInsights Today!If you’re still on the fence about whether a plugin is worth it, check out our honest look at whether MonsterInsights is worth it.
Video Tutorial: Adding Google Analytics to WordPress Without a Plugin
FAQs About Adding Google Analytics to WordPress Without a Plugin
Can I add Google Analytics to WordPress without a plugin?
Yes, you can add Google Analytics to WordPress manually by pasting your GA4 tracking code into your theme’s header.php file or using a wp_footer hook in functions.php. It works, but you’ll miss out on advanced tracking features — like eCommerce tracking, file downloads, and form conversions — that plugins handle automatically.
How do I get my Google Analytics tracking code in GA4?
In GA4, go to Admin → Data Streams and click the stream for your website. Scroll down and click “View tag instructions,” then switch to the “Install manually” tab. You’ll find your full gtag.js script there, ready to copy.
What is the difference between adding Google Analytics via header.php vs. functions.php?
Both methods work, but they load the tracking code differently. header.php pastes the script directly into your site’s <head> section. The functions.php method uses a WordPress action hook to output the code in the footer. Either way, the code runs on every page — the main difference is where in the HTML it appears and how much control you have over it.
Will I lose my Google Analytics tracking code if I change my WordPress theme?
Yes — if you added the tracking code directly to header.php or functions.php, switching or updating your theme will overwrite those files and your tracking code will disappear. Using a child theme or a plugin like WPCode protects against this, since your customizations live outside the parent theme files.
Is it safe to edit header.php or functions.php directly in WordPress?
It can be done safely, but it carries real risk. A small syntax error in either file can break your entire site. I always recommend taking a full site backup first, and making edits inside a child theme rather than your main theme. That way, if something goes wrong, you can restore without losing your original theme files.
What is WPCode and can it help me add Google Analytics without a plugin?
WPCode is a popular WordPress plugin for managing custom code snippets. It lets you paste your GA4 tracking script into a dedicated interface and choose where it loads — without touching theme files directly. It’s a good middle-ground option if you want to avoid direct file editing but still prefer not to use a full analytics plugin.
Does adding Google Analytics manually affect WordPress site speed?
The GA4 tracking script does add a small amount of load to your pages, whether you add it manually or through a plugin. The difference between the two methods is negligible in practice. What matters more is that the script loads correctly and doesn’t block rendering — both the header.php and functions.php methods handle this fine when implemented correctly.
I hope this article helped you add Google Analytics to your WordPress site. If you want to get more from your analytics setup, check out these beginner-friendly guides:
- How to Add Google Analytics to WordPress
- MonsterInsights vs. Google Analytics – What’s the Real Difference?
- How to Set Up Google Analytics Click Tracking
- Google Analytics Reports: The Ultimate Guide (GA4)
- Google Analytics Tracking ID (Measurement ID): Complete Guide
Follow us on X, Facebook, and YouTube for more Google Analytics tips.
Not using MonsterInsights yet? Get started today!
Finally, stay connected with us on YouTube for the latest Google Analytics and WordPress tips and tutorials.
How to add Google Analytics code to multiple posts.
Sunil,
You just need to follow the tutorial. It will add the Analytics tracking code to the entire site.
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.
Thanks for sharing, Todd! Really happy to hear about your experience with MonsterInsights 🙂
Can I also follow the traffic though Google Analytics when I install your plugin or can I only track in through your plug in?
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.
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.
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.
Thanks a lot for this tutorial.
Thank you for a great post. I am glad to came across your site.
Best
Pablo
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.
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: https://www.monsterinsights.com/how-to-add-a-property-in-google-analytics/
I hope that helps! Let me know if I can answer any other questions 🙂
Thank you!
Thanks, This information helps me for setting up my google analytics.
Can I add in my sidebar, through custom html widget?
No. Doing so doesn’t install Google Analytics on your site. It’s necessary to add your website tracking code to the header, i.e.,
of every webpage you want to track. You can learn more about that in this article: https://www.monsterinsights.com/should-you-put-google-analytics-code-in-wordpress-header-or-footer/Thanks!
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?
Yes it will get the same data, no additional code required.
Great! Thanks
That’s really nice post. I appreciate your skills. Thanks for sharing.
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?
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: https://www.monsterinsights.com/docs/create-a-new-view-in-google-analytics/
Hi,
I have installed the free version of Monster Insight and grants some access of Anlaytics Account, now I delete the plugin. How I can stop the granted access of Analytics to Monster Insights?
Thanks.
Hey there,
Here’s the link to the apps that have access to your Google Account: https://myaccount.google.com/permissions – you’ll be able to remove it there.
Hi, If I install Analytics through a plugin like yours, this will be created in Google Console? What happens if I delete the plugin, will the code still be valid? like, i could go in my Google console and copy/paste the code? Thanks!
Hi Ian,
We’re guessing you mean Google Analytics, not Google Console? If you uninstall MonsterInsights down the road, you can still install your Google Analytics code manually. If we misunderstood your question or you have others, don’t hesitate to reach out! https://www.monsterinsights.com/contact/
Whenever I try to add the code to my header in the code editor, it shows up as a clickable URL on my website. How do I get it embedded? My wordpress looks different from the screenshots used here… I dont think they’re up to date
Hi Sarah – The screenshots look up to date from my end when I tested the file editor just now. If you’re not using MonsterInsights, I’m unable to help you troubleshoot. If you need help troubleshooting, I’d recommend joining a group like this one: https://www.facebook.com/groups/wpbeginner.