How to Add Google Analytics to WordPress Without a Plugin

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

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

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

Why is Google Analytics Important for Your WordPress Website?

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

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.

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 google analytics view

Click on Admin in the left taskbar.

click admin

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

get google analytics tracking-code

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

download tracking 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.

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.

That’s it!

Anjali Punjab

Anjali Punjab is a freelance writer, blogger, and ghostwriter who develops high-quality content for businesses. She is also a HubSpot Inbound Marketing Certified and Google Analytics Qualified Professional.