Add Google Analytics into Wordpress without a plugin
Blogging,  Google Analytics,  Website

Easily Add Google Analytics Tracking Code into WordPress Without a Plugin

Needless to say, website tracking can provide very beneficial insights. One of the most popular ways to get that tracking is through Google Analytics. Once you have an account set up, you’ll need to add the tracking code – the Global Site Tag (gtag.js) – into your website. This time, I’d like to show you how to add Google Analytics into a WordPress site without a plugin.

Benefits of Adding GA Code into Your WordPress Site

Google Analytics can give incredible insights about your web visitors behaviour. Here are some of the benefits of Google Analytics:

  • Free insights: Google Analytics is free to use.

  • Real-time data:  the information Google Analytics collects is ongoing, and it shows real-time engagement.

  • Visualisation of your data:  create lists, spreadsheets, charts, graphs, pie charts, and more.

  • Reporting: collect and compare any data set or several data sets together.

  • Learn from your data: see the full picture, identify where your readers are coming from. Connect your website traffic with your marketing campaigns and optimise your content to get better conversions and sales.

Add Google Analytics into WordPress in 3 Simple Steps

First, let’s just say some plugins can help you add Google Analytics to your WordPress site. But that said,  sometimes you just don’t want to add yet another plugin. I’m assuming you have a Google Analytics account (if not, then you’ll have to create one). Now, let’s find where to get your tracking code.

Step 1:  Find Your Google Analytics Tracking ID

Log into your account and go to the Admin area – it’s located at the bottom-left corner of the main dashboard.

Step 1 Google Analytics into WordPress - find admin area

Then you will see 3 main Google Analytics sections. In the middle one, click on Tracking Info and then on the Tracking Code option.

Find the Google Analytics tracking ID

Step 2:  Copy The Tracking Code

Once you open the Tracking Code tab, you will see your unique Tracking ID and the full Google Analytics Tracking code. Copy this code, starting with <!– Global site tag (gtag.js) – Google Analytics –> and finishing with </script>, as this is what will you need to add Google Analytics to WordPress.

Step 3: Log into WordPress and Add Your Google Analytics Code

Please note, that it’s always recommended to create a child theme for your WordPress site before editing the theme files.  And remember to always back-up your website.

So where do you place your tracking code? Once you’re logged into your WordPress site, go to the back-end admin area, Appearance > Editor tab (or Theme Editor) on the left sidebar. Assuming that you want to track all activity and not just specific pages’ web activity, you’ll need to look for the header.php file (located on the right side of the page).

Open the header.php – you will see the code editor appear on your screen. In there, you’ll need to look for the closing Head tag </head>. You can use Cntr + F to find it quicker. Once you find it, paste the Google Analytics tracking code just above it. It needs to sit before the closing Head tag.

Note: Sometimes, if you’re using a child theme, you might not see the header.php in your theme editor. In that case, your child theme is most likely using the header.php from the parent theme.

Make sure you click on Update File button (below the code editor) – this will save your changes.

Just to be clear, to have Google Analytics on your site, you need to have the tracking code in the header. Having it inserted into something like a custom HTML widget will not work.

Test Your Connection

Voilà, you have just added your Google Analytics into your WordPress Site. If steps were done correctly, and changes were saved, your tracking code is there. Make sure to test your connection, but remember, sometimes it may take up to 24-48 hours for new data to start flowing in.

How to test your connection? You can do that from Google Analytics. Go back to the Tracking Code section, and you’ll see the “Send test traffic” button. Check if you can see any activity.

Send test traffic button

Enjoy the insights!

Published February 2021

Leave a Reply

Your email address will not be published. Required fields are marked *