Setting up your Google tag with WordPress Editor is a straightforward process that helps you track visitor activity on your website. This essential step enables you to gather valuable data about how people interact with your site, which can inform your marketing decisions and website improvements.
How to work on Google tag setup
Using WordPress editor
Before you can use your Google tag with WordPress Editor, you’ll need to add the Google tag code snippet to every page on your website. This code needs to be placed in the head section of your HTML pages to work properly.
First, you’ll need to find your Google tag snippet. You can locate this in the “Install Manually” section of your “Set up your Google tag” instructions. The snippet will look something like this:
<script async
src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
The process of adding your Google tag to WordPress is quite simple. Start by logging into your WordPress website. It’s important to make sure that your site is publicly accessible and not in maintenance mode or protected by a password.
Once you’re logged in, look for the Navigation panel on the left side of your dashboard. From there, click on “Appearance” to access theme options. Under the Appearance section, you’ll find “Theme File Editor” – click on this option to proceed.
After clicking on Theme File Editor, you’ll see a panel on the right side that lists various theme files. Look for “Theme Header (header.php)” under Theme Files and click on it. This will open the code editor where you can make changes to your site’s header section.
Now comes the important part – pasting your Google tag snippet. Scroll to the bottom of the code editor and paste your tag snippet there. Once you’ve added the code, click on the “Update File” button to save your changes. You’ll know the process has been successful when you see a banner that says “File edited successfully”.
It’s worth noting that if you decide to change your WordPress theme in the future, you’ll need to repeat this process again. This is because the header.php file might be overwritten when you switch themes, which would remove your Google tag.
Using a plugin
The above is one of the methods but it’s not optimal since you have to touch the theme file and it won’t last if you change themes. So we have other options for you. One of them is using a reliable plugin.
There are several plugins that can help you do the job. We advise you to read the reviews carefully and pick out the one you feel is most trustworthy and has a lot of users.
For example, you can use WPCode (Insert Headers and Footers). Here’s how:
- Install and activate the WPCode – Insert Headers and Footers plugin from the WordPress Plugin Directory.
- Go to Settings > Headers and Footers
- Copy your Google tag snippet from Google Tag Manager or Google Analytics. The snippet will look something like this:
<script async src="https://www.googletagmanager.com/gtag/js?id=TAG_ID"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'TAG_ID');
</script>
- Paste the snippet into the “Header” section.
- Click Save Changes.
Using Google Tag Manager
If you manage multiple tracking scripts, Google Tag Manager (GTM) is a more flexible solution:
- Sign up for a Google Tag Manager account and create a new container for your website.
- Copy the GTM script provided during setup.
- Install the Google Tag Manager for WordPress plugin and paste your GTM container ID in the plugin settings.
- Add your Google tag within GTM instead of directly in WordPress.