Place the Google tag in the <head> of every page on your WordPress site, as high in the head as you can. You can do that with the Site Kit by Google plugin, a header-code plugin such as WPCode, a few lines in a child theme or small plugin that use the wp_head hook, or a Google Tag Manager container. Pick one method only. Adding the same tag twice makes your reports count each visit more than once.
What the Google tag is
The Google tag is a single piece of JavaScript, also called gtag.js, that connects your site to Google products. It sends page views and events to Google Analytics, and it can also support Google Ads conversion tracking. You get the snippet from your Google Analytics data stream or from the Google tag settings, and it includes an ID that starts with G- for a Google Analytics 4 measurement ID.
Google says to put the tag in the head of every page you want to measure. The head loads before the visible page, so the tag can start collecting data early. Putting it in the footer can work, but a visitor who leaves quickly may leave before it runs, which means missed visits. For the full picture of reports once the tag is live, read our guide to Google Analytics 4.
Choose a method
| Method | Best for | Trade-off |
|---|---|---|
| Site Kit by Google | Most site owners | Connects several Google services. Installs a plugin. |
| Header-code plugin (WPCode and similar) | Pasting the snippet without editing files | Needs a plugin just for the snippet. |
Child theme or small plugin with wp_head | Developers who want no extra plugin | You maintain the code. |
| Google Tag Manager | Several tags and frequent changes | An extra layer to set up and learn. |
Method 1: Site Kit by Google
Site Kit by Google is Google’s official WordPress plugin. You install it, sign in with your Google account, and connect the services you want, such as Analytics and Search Console. It then places the tag for you and shows summary reports in your WordPress dashboard. Because it handles the placement, you do not paste any code, which removes most chances for a typo. This is the easiest route for most people. If you want other ways to connect Analytics, see our list of WordPress plugins for Google Analytics.
Method 2: a header-code plugin
A header-code plugin lets you paste the snippet into a box and have it printed in the head of every page. WPCode is one widely used example, with a header and footer area and a snippet manager. The steps are the same in any of these plugins:
- Copy the Google tag snippet from your Analytics data stream settings.
- Open the plugin’s header scripts area.
- Paste the snippet exactly as Google gave it, including both script tags.
- Save the change.
- Clear any page or server cache so visitors get the new head.
The benefit is that the tag survives a theme change, because it lives in the plugin and not in the theme. If you use a caching or optimisation plugin that delays JavaScript, check that it does not delay the Google tag in a way that loses visits.
Method 3: code with the wp_head hook
If you are comfortable with PHP, you can print the tag from the wp_head action. Put the code in a child theme’s functions.php or in a small custom plugin. Do not edit a parent theme’s files directly, because a theme update will erase your change. A child theme keeps your edits safe across updates.
Example code, replace G-XXXXXXXXXX with your own measurement ID:
add_action( 'wp_head', 'example_print_google_tag', 1 );
function example_print_google_tag() {
if ( is_admin() || is_user_logged_in() && current_user_can( 'edit_posts' ) ) {
return;
}
?>
<script async src="https://www.googletagmanager.com/gtag/js?id=G-XXXXXXXXXX"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'G-XXXXXXXXXX');
</script>
<?php
}
The priority of 1 prints the tag early in the head. The check at the top skips logged-in editors, so your own visits while you work on the site do not count. Remove that check if you want to measure everyone. This is a short example, so adapt it to your needs, and keep your real ID out of public code samples.
Many themes also have a built-in field for header scripts in their settings. Where one exists, using it is simpler than writing code, but the tag then lives in the theme settings, so note where you put it. If you want to understand where theme areas such as the footer sit, read where the footer is in WordPress.
Method 4: Google Tag Manager
Google Tag Manager is a container that holds your tags. You install the container code once on your site, then add, change and remove tags, including the Google tag, inside the Tag Manager dashboard without touching WordPress again. This pays off when marketing teams add pixels and conversion tags often.
The container has two parts. A script goes as high in the head as possible. A noscript iframe goes right after the opening body tag, for visitors with JavaScript off. Site Kit and some header plugins can place the container for you. Inside Tag Manager you create a Google tag with your measurement ID and set it to fire on all pages.
The rule that matters: do not load the Google tag directly on the site and also inside Tag Manager. Choose one route.
Finding your measurement ID and snippet
In Google Analytics, open Admin, choose the data stream for your website, and look for the measurement ID, which starts with G-. The same screen has a link to view tag instructions, where Google shows the installation snippet and options for common platforms. If you also run Google Ads, your tag settings may list more than one destination, such as an Analytics ID and an Ads ID, under the same Google tag. Menu labels can change, so if your screen looks different, search Google’s help pages for “set up the Google tag”.
Multisite, staging and local copies
Keep your test sites out of your reports. A staging copy of your site that carries the live tag will send its visits to the same property and pollute your numbers. Either leave the tag out of staging, use a separate property for it, or print the tag only when the environment is the live one. WordPress offers an environment type setting that developers can check in code, which makes a simple guard possible. On a multisite network, decide whether each site gets its own measurement ID or shares one, and place the tag accordingly.
After the tag is live
A working tag gives you page views, but the useful data comes from events you choose to track, such as form submissions, button clicks and purchases. Google Analytics 4 calls the important ones key events. Some are collected automatically, and others you set up in Analytics or Tag Manager. Start with the one or two actions that matter to your site, confirm them in DebugView, and then mark them as key events. Link Search Console to your property too, so you can see which searches bring people in.
How to check that the tag fires
- Google Tag Assistant. Open Google’s Tag Assistant, enter your site address and browse a page. It tells you which Google tags it found and whether they loaded.
- Realtime report in Google Analytics. Open the site in another browser tab or on your phone, then look at the Realtime report in Analytics. Your visit should appear within moments.
- DebugView. In Analytics, DebugView shows events from a device in debug mode as they arrive, which helps when you add custom events.
- View source. Open a page, view its source, and search for your measurement ID. You should find it once. Finding it twice means a duplicate.
- Browser developer tools. The network panel should show requests to Google’s tag servers when the page loads.
If you test while logged in as an admin and your setup excludes admins, you will see nothing. Use a private window or a different device.
Troubleshooting
- No data at all. Check the measurement ID, clear caches, and make sure the tag is on the live theme and not a staging copy.
- Doubled page views. The tag is probably loaded twice, for example by a plugin and by the theme. Remove one.
- Data from your own visits. Exclude internal traffic in Analytics, or skip logged-in editors in code.
- Tag blocked. Ad blockers and consent tools can stop the tag. If you use a consent banner, configure it to control the Google tag according to the rules where your visitors live.
- Delayed scripts. A performance plugin that delays JavaScript may delay the tag. Exclude it if you see missing visits.
- Tag disappears after a theme change. You put it in the theme. Move it to a plugin or a child theme.
Privacy and consent
Analytics tags collect data about visitors, and many countries require consent before they run. Use a consent tool that works with Google’s consent settings, and mention analytics in your privacy policy. This is a legal matter that depends on where you and your visitors are, so check the rules that apply to you. Related tools are covered in our guide to Google Search Console.
Frequently asked questions
Where do I put the Google tag in WordPress?
Put it in the head of every page. In WordPress, that means a plugin like Site Kit or WPCode, the wp_head hook in a child theme, or a Tag Manager container.
Should the Google tag go in the header or the footer?
The header. Google tells site owners to place the tag in the head, so it loads early and records visits even when someone leaves quickly.
Do I need a plugin to add the Google tag?
No. You can print it with a few lines of code in a child theme. A plugin is easier and safer for most people, because it survives theme changes.
What is the difference between the Google tag and Google Tag Manager?
The Google tag is the snippet that sends data to Google products. Tag Manager is a container that holds many tags, including the Google tag, so you can manage them without editing the site.
Can I use both Site Kit and Tag Manager?
You can, but make sure the Google tag loads only once. If Tag Manager loads it, turn off any other method that also prints it.
How long does it take for data to appear?
The Realtime report shows visits within moments. Standard reports can take longer to fill in, so use Realtime or DebugView to check a new setup.
Why are my visits counted twice?
The tag is probably on the page twice. View the page source, search for your measurement ID, and remove the extra copy.
Will the tag slow down my site?
It loads asynchronously and is small, but any script adds some weight. Keep the number of tags down and test your page speed after changes.
Next step
Choose one method, add the tag, and confirm it in Realtime. Then read our guide to Google Analytics 4 to set up the reports and events you actually use.