Installing GA4 manually means adding the Google tag to your WordPress frontend and verifying that events reach the correct property. A manual installation is useful when your theme already has a maintained code workflow; it is not automatically faster or better than a well-configured integration.
Check for an existing installation first
Review your theme, Site Kit, analytics plugins, Google Tag Manager container, and any header-code feature. If GA4 already fires through one of these, do not add a second copy. Duplicate tags can create misleading page views and events.
Get the measurement ID
In Google Analytics, open the intended property and its web data stream under Admin. Copy the measurement ID beginning with G-. Check that the stream belongs to the production website, not a staging property.
Plan consent before loading the tag
The example below is a basic installation, not a complete consent integration. Where your site requires consent before analytics runs, connect the tag to your consent system before using it. Google’s consent mode communicates consent states; it does not obtain consent for you.
For basic consent mode, the consent system should prevent the tag from loading until the required choice is granted. Other implementations need default states set before measurement commands and appropriate updates when the visitor makes a choice. Follow your consent platform’s integration guidance rather than combining unrelated snippets.
Add the tag through a child theme hook
Back up your child theme and use a staging environment first. Add this to its existing functions.php, replacing both occurrences of the example ID. Do not add another PHP opening tag if the file already has one.
add_action( 'wp_head', function () {
if ( is_admin() ) {
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
}, 20 );This emits the tag on frontend pages where the theme calls wp_head(). It does not exclude logged-in administrators from frontend measurement. It also does not automatically track WooCommerce purchases, enquiry submissions, or every custom interaction.
A hook avoids copying an entire parent header.php just to insert the tag. Switching themes still requires reviewing the integration. PHP syntax errors can break the site, so keep file access available for rollback.
Verify measurement
- Clear relevant page caches after deployment.
- Open a logged-out browser session and make the intended consent choice.
- Use Tag Assistant to check the measurement ID and tag firing.
- Verify activity in GA4 Realtime; use DebugView with debug mode enabled for event-level checks.
- Test several pages and confirm page views are not duplicated.
- Test denied and granted consent states separately.
Track enquiries as a separate step
Measure confirmed form submissions, bookings, or purchases with events appropriate to the website. A button click is not proof of a completed enquiry. Do not send names, email addresses, or other personal details to analytics.
References: Google tag installation and Google consent mode setup. For managing theme snippets, read adding WordPress header and footer code safely.
Need help implementing this?
Explore my WordPress development services or send your website URL and requirements for a scoped implementation and verification.
Need help fixing this on your website?
Need help fixing this on your website? Chat with me on WhatsApp.
