In this article, we break down 3 options that you have when implementing the Google Analytics tracking code to your WordPress website. To make things easier going forward, I highly recommend going for option 3 which includes Google Tag Manager.
Google Tag Manager (GTM) is a free tool that makes it easier to add and update tracking tags within your website. It’s recommended to use Google Tag Manager for all the tags on your WordPress website.
Option 1 (the easy way): Using a GA plugin
If you don’t have much experience with WordPress this might be an easy option. However, keep in mind that if in the future you want to track additional things in Google Analytics you might be unable to change the tracking code directly.
There are a bunch of WordPress plugins available that allow you to add the Google Analytics ID and automatically generate the tracking code.
For example, the GA Google Analytics plugin lets you add the Google Analytics code by just adding your Google Analytics tracking ID.
To locate your Google Analytics tracking ID, login to your Google Analytics account and go to Admin > Property > Tracking Info > Tracking Code. The Google Analytics tracking ID looks like UA-XXXXXXXX-X.
Option 2 (the standard way): Adding the GA code using the “Insert Headers and Footers” plugin
Now, compared with the first option there’s not a massive benefit of using this option. It will give you a bit more flexible in case you ever need to change the tracking code.
However, if you go for option 3 you will still need to add the “Insert Headers and Footers” plugin (I recommend you using this plugin regardless!).
Insert Headers and Footers is a simple plugin that lets you insert the Google Tag Manager code easily into your WordPress site header and footer. This means there’s no need to edit your theme files and your codes will stay where they are even after you update your theme!
To install this plugin:
1. Login to the back-end of your website (www.yourwebsite.com/wp-admin).
2. Go to Plugins > Add New and then search for “Insert Headers and Footers”. Press “Install Now” in the “Insert Headers and Footers” square.
3. In the left hand menu, go to Plugins > Installed Plugins and then scroll down to find the “Insert Headers and Footers” plugin. Click on Activate.
Once you installed the plugin, you will have to go to Settings > Insert Headers and Footers in your WordPress dashboard. From here, you can add your your Google Analytics tracking code (not just the ID!) to the “Scripts in Header” section”.
Option 3 (the recommended way): Adding Google Tag Manager using the “Insert Headers and Footers” plugin
Now, Google Tag Manager is a great tool and I highly recommend every website to use it. If you don’t have a GTM account yet, please read our beginner article about Google Tag Manager first.
It will make your life significantly easier going forward and can help you to track things like forms without a thank you page.
If you haven’t done so already, please follow the steps from option 2 to install the “Insert Headers and Footers” WordPress plugins. Then, instead of adding the Google Analytics code place the GTM code in here.
Click save, en voilà: Google Tag Manager is live on your site.