Share this post

How to add Google Analytics Code to a Website Without Using a Plugin

How to add Google Analytics code in website without using a plugin

If you have a website and want to study your audience in details, Google provides an amazing (and free) platform called Google Analytics. It is a web based platform that you can use to understand your website visitors a bit more – their age, gender, locations, the devices they use to visit your website, the pages they visit, the average time spent engaging with your website, their user journey as they navigate from one page to another and a lot more.

If you haven’t yet integrated GA (as it is fondly called) in your website, this post will help you immensely. Although there are different ways to integrate Google analytics, we’ll be focusing on how to add Google analytics code in your website without using a plugin. Why add another plugin to clutter your WordPress website if you can do without one, right?

Before we implement the process, let’s see how your website will look without the tags. You can make use of a Chrome extension called Tag Assistant Legacy (by Google), and once added to your browser, it shows the number of tags fired on a particular page. Since we haven’t yet associated our Google Analytics account with our website, it’ll look blank as shown below:

Tag Assistant - No tags found

We’ll come back to this extension a bit later when we set up Google analytics on your website. So let’s get to it.

How to add Google Analytics code in your website without a plugin

We assume that you already have a Google analytics account created. If you have still to create one and want to know the steps involved, this blog post will be guide you with screenshots: How to create a Google Analytics Account.

1) Login to your Google analytics account by visiting:

2) Once you’ve logged in, you will require the Global Site Tag (gtag.js) to add it to the header of the website. If you’re using Google Analytics 4, you will find the global site tag on your Web Stream Details page as shown:

Global site tag in Google Analytics 4

3) Copy the gtag.js code in your notepad locally.

Global site tag snippet in Google Analytics 4

4) If you’re using Google Universal Analytics, you will find the Global Site Tag on the tracking code page, as shown below. Copy the code as we’ll need it soon.

Global site tag snippet in Universal Analytics

5) Next, login to your WordPress site. At WP Adventure, we almost exclusively use the Astra theme to build WordPress websites. Go to Appearance and click on Theme Editor.

Theme Editor in WordPress Astra theme

6) Select the theme from the dropdown that you want to edit. Search for a file called header.php and click to open.

Strong Recommendation:

It is our very strong recommendation that you create a child theme to make any edits to the theme files - so that the changes remain even after you update your theme later on. Once you've created a child theme, you can copy the header.php file to it and proceed with the remainder of this post. We have a blog post that guides you how to copy header.php from parent theme to the child theme

Find header.php in Astra theme

7) Paste your Global Site Tag code (gtag.js) just above the closing </head> tag as shown below. This is the same code that you copied from your Google analytics account in step 2 – 4 above.

Adding global site tag in header.php file in WordPress

8) Click Update file to save it.

9) Technically, we’re done at this point however it is always a good practice to verify if it has been implemented correctly. Let’s revisit the Chrome extension to check if the tag is firing correctly. And if you’ve followed the steps outlined above correctly, the tag does fire as shown below:

Tag Assistant - After adding global site tag in WordPress

That’s it. Job done. You’ve added your global site tag in your website to connect your Google analytics account without using a plugin. It was very easy and straightforward, wasn’t it? You can now sit back and watch the data flow in your Google analytics account as your visitors navigate the various pages of your website.

If you just want to stick with the default features provided by Google Analytics, using the gtag.js will be sufficient. However, it has limitations such as its ability to work with only other Google tools or difficulty in implementing more advanced tracking such as link clicks or button clicks etc.

Our recommendation? Use Google tag manager instead. We’ve written a post that will help you add Google analytics code in your website using Google tag manager. It’s a much versatile solution and we always take that route over the one above. Go, give that a read and decide!

We're all on an adventure!

2nd Floor, Building No. 150, Zakaria Masjid Street, Mumbai - 400 009, India.

Web design

Web development

WordPress development

SEO services

Ecommerce SEO services

Local SEO services

Social media marketing

Digital marketing

Internet marketing

Pay per click (PPC)

Content writing

Mobile app development

Website SEO Audit


About Us


Refer and Earn

Privacy Policy

Scroll to Top