How to add Google A...
 
Notifications
Clear all

How to add Google Analytics Code to Wordpress

1 Posts
1 Users
0 Reactions
42 Views
(@allseobasics)
Posts: 40
Member Admin
Topic starter
 

When it comes to adding Google Analytics to WordPress, it can be quite tricky when you don't have much coding experience.

We have made an easy step-by-step tutorial with images on How to add Google Analytics Code to WordPress.

There are different ways a website master or a blogger can connect your Google Analytics account with a WordPress website or a blog, it can all be done in a few simple steps.

How do you add Google Analytics to your WordPress Website?

You can do this by adding a manual code in the header of your selected theme. Let's have a look at the easy-to-follow step-by-step tutorial guide below;

 

Step 1

Locate your file manager using your cPanel login.

file manager

 

Step 2

Locate your main "public_html" location and then select the "wp-content" folder followed by "themes". You should see something similar to what I have below;

Select Your Themes Folder in WordPress

 

Step 3

Select your current "active theme", this will be named something else, in my case, it's named "Newspaper".

Select your active theme

 

Step 4

Locate your "header.php" to insert your Google Analytics code.

 

Locate your header.php to insert your google analytics code

 

Step 5

Whilst the header is selected (highlighted in light blue colour) click on the EDIT tool at the top. As shown below;

edit

 

Step 6

This will open up loads of codes, you may feel like a genius at this point, but stay calm and breathe. Please do not panic, at this point, what you want to do is look at everything only between the codes of <head> till </head> highlighted in red/blue for you.

This is where you will be posting scripts to run on the whole of your website, likes Google Ads, analytics, cookie GDPR compliance, and any other 3rd party scripts, these script will usually be in JavaScript format. 

Now, you might see less code or more code between this <head> till </head> section, if you do, then simply please don't worry. Means your theme is using less or more external JavaScript from 3rd parties, or from local server.

We will be looking at everything only between the codes of <head> till </head> code only!

Step 7

You will need to copy and paste your Google Analytics code, your Google Analytics code should look something like this below;

<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-000000000-0"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-000000000-0');
</script>

Your "UA-000000000-0" will have your own ID, we used "UA-000000000-0" as an example. (you could have something like "UA-183690025-4" or "UA-100927809-8") your Google Analytics ID will be unique, and no other person will have the same ID as you.

More info on UA tracking IDs can be read at help.cool-tabs.com

Simply copy the whole code, select the analytics code, and right-click on a copy.

copy and paste your google analytics code

 

Step 8

Now very simply, you are going to add your Google Analytics code between the codes shown below;

<?php wp_head(); ?>

&

</head>

Now you are going to have to add your Google Analytics code between the head, this will prevent you from editing any header codes, JavaScript, or breaking anything. (see the image below for reference)

Adding your Google Analytics tracking code above closing </head> is the right way to place your tracking code on your WordPress website directly within the theme, it will appear on all pages of your website.

Right-click and click paste to add your code just above the </head> and below the wp_head(); ?>

If you are missing "wp_head(); ?> do not panic, you might see that you have totally different html/php code above this area, that is totally fine, just make sure your Google Analytics code is above the </head> [shown at line 23 in the image below][/su_note]

 

add your google analytics code above the closing header code

Once you're done, hit save and exit!

You have now installed Google Analytics on your WordPress theme without using any WordPress plugins.

 

2025 Update: If you guys have any question on recent updates on GA4 Google Analytics, please drop them below, I will do my best to get back to you. 

It's pretty much the same process, the code will be shown when you create the GA4 account. If you lose your tracking code, you will probably need to create another GA4 account, as finding this script is basically like walking over the mountain of Everest in one day, I think google should improve the visual tracking code for analytics in GA4.  

But yes, it can be retrieved within admin panel of your analytics.

To be honest, I spend 1 hour looking for the new Google Analytics code and was not able to find the new GA4 tracking code, quite disappointing that they made it so much harder to find. 

Has anyone had the same issue?

 
Posted : 20/04/2025 3:48 pm
Share: