Knowing which pages get traffic, where visitors come from, and what content actually drives engagement transforms how you run a WordPress site. Google Analytics provides all of that — free, powerful, and trusted by millions of sites. The question is: what is the right way to connect it? Getting Google Analytics WordPress set up right from the start saves hours of debugging later. Adding Google Analytics WordPress correctly makes all the difference. has three main approaches, each with different tradeoffs in speed, accuracy, and maintenance. This guide covers all three so you can choose the right method for your setup and skill level. For the bigger picture, our Complete Guide to WordPress How pulls everything together.
How to Add Google Analytics to WordPress — Before You Start
Before adding any tracking code for Google Analytics WordPress integration, you need a Google Analytics 4 (GA4) property. Google Analytics Universal Analytics (UA) was retired in July 2023 — all new setups use GA4 exclusively. Google Analytics WordPress setup with GA4 requires a Measurement ID rather than a Tracking ID, and the configuration steps differ from older UA instructions you may find online.
Create a GA4 property: navigate to analytics.google.com → Admin → Create → Property → enter your site name → select your reporting time zone and currency → Next → fill in business details → Create. On the next screen, select “Web” as your data stream → enter your website URL and stream name → Create stream. Google generates a Measurement ID in the format G-XXXXXXXXXX. Copy this ID — it is required in all three methods below. Also note the “Google tag” code snippet shown on the same screen, which is needed for the manual method.
Choosing the right Google Analytics WordPress method depends on your technical level and existing plugin setup. The three methods are: using a dedicated analytics plugin (easiest, no code), adding the code via your theme or a code snippet plugin (intermediate, no additional plugin required), and using Google Tag Manager as an intermediary (advanced, best for sites with multiple tracking scripts). Each method achieves the same outcome — a fully tracked site with Google Analytics WordPress data flowing correctly — but the implementation and maintenance differ significantly. Sites already using a plugin like MonsterInsights or Site Kit should use that plugin’s built-in GA4 connection rather than adding tracking code manually, which would result in duplicate tracking and inflated data.
Method 1 — Install an Analytics Plugin
The fastest and most reliable way to complete Google Analytics WordPress setup without touching any code is through a dedicated analytics plugin. These plugins handle the code insertion, provide a settings UI inside the WordPress admin, and often add bonus features like dashboard reporting, event tracking, and GDPR compliance tools.
The two most widely used free Google Analytics WordPress plugin options are MonsterInsights (Lite) and Google Site Kit. To set up with Google Site Kit: WordPress admin → Plugins → Add New → search “Site Kit by Google” → Install → Activate → Begin Setup → sign in with your Google account → Grant Site Kit the required permissions → Select your GA4 property from the dropdown → Complete Setup. Site Kit automatically inserts the Google tag into every page of your WordPress site and shows a summary dashboard inside WordPress admin. The entire process takes about five minutes and requires no code knowledge. MonsterInsights Lite follows a similar OAuth-based setup wizard and also shows analytics data directly in the WordPress dashboard.
The plugin Google Analytics WordPress method has one important consideration: it adds a small performance overhead compared to manually inserting the code because the plugin itself loads on every page request. For performance-critical sites, consider using a lightweight code snippet approach instead. For most sites — including those prioritising simplicity, ongoing team access, and built-in reporting — the plugin is the correct choice. The plugin method also handles future GA4 configuration changes (such as connecting to Google Search Console or setting up conversion events) without requiring any further code edits. Our guide on optimising WordPress performance covers how analytics scripts affect page load speed and the optimal loading strategies for third-party tracking code.
Method 2 — Add GA4 Code Directly to WordPress
Adding GA4 code directly without a plugin is the lightest-weight Google Analytics WordPress approach. It loads no additional plugin files and gives you full control over exactly when and how the tracking script loads.
The most maintainable way to add the GA4 code directly is through the wp_head hook in your child theme’s functions.php. Open your WordPress child theme’s functions.php (wp-content/themes/your-child-theme/functions.php) and add this code, replacing G-XXXXXXXXXX with your actual Measurement ID:
function add_google_analytics() {
echo '<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>';
}
add_action('wp_head', 'add_google_analytics');This inserts the Google Analytics WordPress tracking tag into the <head> of every page. If you do not have a child theme, use a code snippet plugin like Code Snippets (free, from the plugin directory) to add PHP functions without editing theme files. Code Snippets is ideal for Google Analytics WordPress code insertion — add, enable, and disable snippets from the admin without FTP. Adding the GA4 code through Code Snippets rather than functions.php keeps the tracking code intact if you later switch themes. According to Google’s Analytics documentation, the Google tag should be placed in the <head> section of every page as early as possible to ensure all pageview events are captured accurately.
Method 3 — Add GA4 via Google Tag Manager
Setting up Google Analytics WordPress through Google Tag Manager (GTM) is the most powerful and flexible approach, recommended for sites that already use or plan to use multiple tracking and marketing scripts alongside Analytics. GTM serves as a central hub for all tags — you install GTM once in WordPress and then manage every tracking script from the GTM interface without touching WordPress again.
Create a GTM account at tagmanager.google.com → New Account → enter account and container name → select “Web” → Create. Google provides two code snippets: one for the <head> and one for the <body>. Install both in WordPress using the same methods as direct Google Analytics WordPress code insertion — either functions.php/Code Snippets for the head script, and a separate action for the body snippet. Several WordPress plugins also handle GTM insertion: Insert Headers and Footers (free) provides a UI for pasting both snippets into head and body without code.
Once GTM is installed in WordPress, configure the GA4 tag inside GTM: GTM dashboard → Tags → New → Tag Configuration → Google Analytics: GA4 Configuration → enter your G-XXXXXXXXXX Measurement ID → Triggering → All Pages → Save → Submit → Publish. GTM sends GA4 tracking data to your Analytics property for every page view. Adding additional tracking later — Facebook Pixel, LinkedIn Insight Tag, Hotjar, TikTok Pixel — requires only adding new tags in GTM without touching WordPress at all. This is the scalable Google Analytics WordPress method in a way that scales cleanly to any number of additional tracking and marketing requirements.
Verifying GA4 Tracking and Fixing Common Issues
After completing any method, verifying that your Google Analytics WordPress connection is tracking correctly before considering the setup complete prevents silent tracking failures that waste weeks of data.
Verify with GA4 Realtime: navigate to your GA4 property → Reports → Realtime → open your WordPress site in a browser tab → if Realtime shows your visit within 30 seconds, tracking is working correctly. Also use the Google Tag Assistant Chrome extension: visit your site → click Tag Assistant → verify the GA4 tag fires on each page with a green status. A yellow or red status provides a specific error message indicating what needs to be fixed. Common Google Analytics WordPress issues: the Measurement ID is entered incorrectly (verify exact format G-XXXXXXXXXX), the tag fires but shows no data (check that your IP is not filtered in GA4 Data Settings → Data Filters), or the plugin is conflicting with another script that blocks the Google tag from loading.
Check for duplicate Google Analytics WordPress tracking: if you have followed multiple methods or installed multiple analytics plugins, GA4 may be receiving two hits per page view, doubling all your metrics. In Tag Assistant, a page that shows two GA4 tags firing indicates duplication. Remove one implementation — either the code-based or the plugin-based version — so only one GA4 configuration tag fires per page. Set up GA4 data retention before collecting any meaningful data: GA4 → Admin → Data Settings → Data Retention → change from 2 months to 14 months to retain event-level data for full year-over-year comparison. Without this change, GA4 deletes event data after 2 months by default, limiting your historical analytics significantly. Our guide on securing the WordPress admin covers user role management that is relevant when granting Analytics access to team members who need to view GA4 reports without full WordPress admin privileges.
Understanding the difference between GA4 sessions, events, and users helps you configure Google Analytics WordPress correctly from the start. GA4 tracks everything as events — pageviews, clicks, scrolls, form submissions — rather than the session-based model of Universal Analytics. By default, GA4 automatically tracks: page_view (every page load), session_start, user_engagement (when a user actively interacts with a page), and first_visit (first time a user lands on the site). For a WordPress blog or business site, these default events are sufficient for measuring traffic, engagement, and content performance. WooCommerce stores need additional ecommerce events — add_to_cart, begin_checkout, purchase — which require either the GA4 ecommerce configuration in GTM, a dedicated plugin like MonsterInsights Pro, or manual GA4 event tracking code.
Filtering your own visits from Google Analytics WordPress data ensures your daily admin and development activity does not distort the traffic data. The most reliable method for WordPress site owners: GA4 → Admin → Data Settings → Data Filters → create a “Developer Traffic” filter → configure it to exclude traffic from your IP address. Alternatively, install a Google Analytics Opt-Out browser extension on your own browser — this tells GA4 to ignore all tracking events from that browser session regardless of which WordPress site you visit. Without IP or session filtering, site owners who frequently visit their own site inflate pageview counts and reduce average engagement time metrics, making it harder to interpret actual visitor behaviour.
Connecting Google Analytics WordPress data to Google Search Console provides the complete picture of organic search performance: which queries drive traffic, which pages rank, and the relationship between search position and click-through rate. Link GA4 and Search Console: GA4 → Admin → Product Links → Search Console Links → Link → select your Search Console property → Next → Complete. After linking, the “Search Console” reports appear in GA4 under Reports → Acquisition → Search Console, showing landing page performance and search query data alongside the standard Analytics traffic and engagement metrics. This integration is the most valuable GA4 configuration step after the initial tracking setup and requires no code changes in WordPress. Our guide on adding SSL to WordPress covers the HTTPS configuration that ensures GA4 correctly attributes traffic sources, since insecure HTTP pages lose referral attribution data due to the browser’s referrer policy.
Setting up goals and conversions in Google Analytics WordPress turns raw traffic data into actionable business insights. In GA4, “conversions” replace the Universal Analytics “goals” concept. Mark key events as conversions: GA4 → Admin → Events → find the event you want to track as a conversion (e.g., form_submit, purchase, generate_lead) → toggle “Mark as conversion.” For WordPress contact form submissions, configure your form plugin to push a custom GA4 event on successful submission — Contact Form 7 supports this through its official add-on, Gravity Forms through its add-on, and WPForms through its Google Analytics integration. Once the conversion event fires and appears in GA4’s event list, marking it as a conversion immediately starts populating conversion data in all GA4 reports and Exploration analyses.
For Google Analytics WordPress data privacy compliance, ensure your setup respects GDPR and other applicable privacy regulations before collecting user data. GA4 by default collects IP addresses, device identifiers, and behavioural data — which requires user consent under GDPR in the EU. Implement a cookie consent plugin (CookieYes, Complianz, or GDPR Cookie Consent) that delays Google Analytics tag firing until the user accepts tracking cookies. In GTM, use a consent trigger that only fires the GA4 tag when consent is granted. The MonsterInsights and Site Kit plugins both include consent mode support that automatically handles this requirement. Collecting data without consent exposes the site to regulatory penalties; implementing consent management correctly from the start is significantly less work than retrofitting compliance after the fact.






