Close Menu
GeekBlog

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    Android 17 Has Been Out Since June. Your Phone Probably Still Does Not Have It.

    August 17, 2026

    A Black Hole Shredded a Super Sun. Astronomers Now Think Part of It Survived.

    August 16, 2026

    France Passed Europe’s First Under-15 Social Media Ban. Its Own Top Court Just Killed It.

    August 16, 2026
    Facebook X (Twitter) Instagram Threads
    GeekBlog
    • Home
    • Mobile
    • Tech News
    • Blog
    • How-To Guides
    • AI & Software
    Facebook
    GeekBlog
    Home»Blog»How to Add Google Analytics to WordPress (4 Methods)
    Blog

    How to Add Google Analytics to WordPress (4 Methods)

    Marcus BennettBy Marcus BennettJuly 30, 2026Updated:July 30, 202613 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Email Copy Link
    Analytics dashboard on a laptop screen showing traffic charts after you add Google Analytics to WordPress
    Share
    Facebook Twitter LinkedIn Pinterest Email Copy Link

    To add Google Analytics to WordPress, create a GA4 property with a Web data stream, copy the Measurement ID that starts with G-, then load Google’s gtag.js snippet on every page. You can do that with a plugin, through Google Tag Manager, by hooking into wp_head in a child theme, or through a field your theme already provides.

    Quick answer: In Google Analytics go to Admin → Create → Property, then Admin → Data collection and modification → Data streams → Add stream → Web. Copy the Measurement ID. Install Site Kit by Google (or paste the gtag.js snippet into wp_head) and check Reports → Realtime within 30 minutes. Pick one method only — two installs double-count every page view.

    This guide assumes you have a live WordPress site and admin access, plus a Google account. You do not need a paid plan: GA4 is free at the volumes a normal blog or small business site produces. If you are still building on your machine, tracking a localhost install is mostly pointless, so finish setting up WordPress on a local host first and add analytics once the site is public.

    Updated July 2026: Universal Analytics is dead. It stopped processing hits on 1 July 2023 and Google deleted the historical data a year later. Every “UA-” tracking code and every tutorial built around analytics.js is obsolete. GA4 is the only version, and Google now calls the snippet the Google tag rather than the Analytics tag, because the same ID can also feed Google Ads.

    Step 1: Create a GA4 property and a Web data stream

    Sign in at analytics.google.com. If this is your first property, the onboarding wizard walks you through it. Otherwise:

    1. Click the gear icon for Admin in the bottom left.
    2. Click Create at the top, then choose Property.
    3. Name the property after your site, set the reporting time zone and currency, and click Next. Get the time zone right — it decides where your “days” start, and changing it later leaves a seam in the data.
    4. Answer the industry and business-size questions, then click Create and accept the terms.
    5. Under Data collection and modification, open Data streams, click Add stream and pick Web.
    6. Enter your URL and a stream name. Leave Enhanced measurement on.
    7. Click Create stream.

    Enhanced measurement is worth understanding before you start building anything custom. With the toggle on, GA4 already collects page_view, scroll, outbound click, view_search_results, file_download, form_start, form_submit and the video events without a line of code. Most people who ask how to track a custom event in Google Analytics find half of what they wanted is already there.

    Step 2: Find your Measurement ID

    Open Admin → Data collection and modification → Data streams and click the stream. The Measurement ID sits at the top right of the stream details panel and looks like G-XXXXXXXXXX. That single string is all any plugin needs. If you want the full snippet instead, click View tag instructions and then Install manually.

    The four install methods compared

    MethodDifficultySurvives theme updates?Extra featuresPage weight
    Plugin (Site Kit or a GA4 plugin)EasiestYesDashboard reports, logged-in exclusion, consent hooksHighest — plugin PHP plus the tag
    Google Tag Manager containerMediumYes, if added by plugin or child themeEvery other pixel and tag from one place, versioningOne extra container request
    gtag.js via wp_head in a child themeNeeds PHP comfortYes (child theme) / No (parent theme edit)None — you build what you needLowest
    Theme’s built-in analytics fieldEasiestYes, but dies if you switch themesNoneLowest

    Method 1: A plugin

    Site Kit by Google is the safe default. It is Google’s own plugin, sits on more than five million sites, and connects Search Console, Analytics, PageSpeed Insights, AdSense and Tag Manager behind one OAuth flow. Install it from Plugins → Add New, run the setup wizard, sign in with the Google account that owns the property, and pick your property and Web data stream from the dropdowns. Site Kit writes the tag for you and pulls a summary of your traffic into the WordPress dashboard.

    Dedicated GA4 plugins are lighter and give you more control over things like ecommerce parameters or custom dimensions. Whichever you pick, remember the settings live in your database, not in a file — useful context when you are hunting down a stale ID later and wondering where WordPress plugin settings are stored.

    Recommended for you:

    Installing Elasticsearch on Cloudways (Complete Guide)
    Blog·Jul 30, 2026

    Installing Elasticsearch on Cloudways (Complete Guide)

    Heads up: Do not run Site Kit’s Analytics module and a second GA4 plugin at the same time, and do not paste the snippet into your theme while a plugin is also injecting it. Two copies of the Google tag on one page means two page_view hits, a bounce rate that looks impossibly good, and session numbers you cannot trust.

    Method 2: Google Tag Manager as the container

    If you expect to add more than one tracking tool — a conversion pixel, a heatmap script, a chat widget — put Tag Manager in first and let GA4 live inside it. You install one container, then add and remove everything else from the Tag Manager interface without touching WordPress again. The full walkthrough is in our guide to installing Google Tag Manager on WordPress correctly, including the second snippet that most tutorials get wrong. The same container is how you would later add something like the TikTok pixel without another plugin.

    Method 3: The gtag.js snippet in wp_head

    This is the lightest option and the one I use on sites where speed matters more than convenience. Put it in a child theme’s functions.php, or in a code-snippets plugin such as WPCode if you would rather not touch theme files at all. Editing the parent theme directly works until the next theme update wipes it out.

    <?php
    // Child theme functions.php
    // Replace G-XXXXXXXXXX with your own Measurement ID.
    
    add_action( 'wp_head', 'geekblog_ga4_tag', 1 );
    
    function geekblog_ga4_tag() {
    
        // Keep your own admin sessions out of the data.
        if ( is_user_logged_in() ) {
            return;
        }
        ?>
    <!-- Google tag (gtag.js) -->
    <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 pushes the tag near the top of <head>, which is what Google asks for. The async attribute means it will not block rendering.

    Method 4: Your theme’s built-in field

    Plenty of commercial themes ship a “Google Analytics” or “Header scripts” box in their options panel. Paste the Measurement ID or the whole snippet, save, done. It is fine, and it is the fastest route for a non-technical client. The catch is portability: switch themes and your tracking silently disappears. Most other content systems have the same trade-off, so if you are weighing platforms, our walkthrough of how to create a Joomla website covers where the equivalent template and plugin hooks live there.

    Step 3: Verify the tag is actually firing

    Do all three of these, in order. They catch different failures.

    1. Realtime report. Open your site in a private window, click through two pages, then look at Reports → Realtime in GA4. You should see yourself within a minute or two. Google says collection can take up to 30 minutes to begin on a brand new stream.
    2. Tag Assistant. Go to tagassistant.google.com, click Add domain, enter your URL and click Connect. A debug window opens and lists every Google tag on the page, each event, and any errors. This is where duplicate tags become obvious — you will see two containers or two G- IDs side by side.
    3. View source. Load your homepage, view source, and search for gtag/js?id=. Exactly one hit is correct. Zero means the tag never rendered; two means you installed it twice.

    Exclude your own traffic

    An analytics account that counts your own editing sessions is worse than useless on a low-traffic site. Two filters fix it.

    Logged-in users. The is_user_logged_in() check in the snippet above handles this. Most GA4 plugins offer the same thing as a checkbox, usually phrased as excluding administrators and editors.

    Your IP address. In GA4, open Admin → Data collection and modification → Data streams, click the stream, then Configure tag settings → Show more → Define internal traffic → Create. Add your office and home IP ranges. That rule stamps matching hits with a traffic_type of internal but does not remove them yet. Then go to Admin → Data collection and modification → Data filters, create an Internal Traffic filter, and switch it from Testing to Active. Google notes it takes roughly 24 to 36 hours to take effect.

    Tip: Leave the data filter in Testing for a day and check the Test data filter name dimension before you activate it. Active filters permanently drop data, and a wrong IP range means a chunk of real visitors vanishes with no way to get them back.

    Consent mode and why US publishers still need a cookie notice

    Google’s consent mode lets the tag load in a restricted state until a visitor makes a choice, and it is mandatory if you serve visitors in the EEA or UK. In the US there is no federal equivalent, but that does not mean you can ignore it. More than twenty states have now enacted comprehensive consumer privacy laws, and several more took effect in January 2026. Most give residents the right to opt out of the sale or sharing of personal data and targeted advertising, and several require you to honor a browser-level opt-out signal such as Global Privacy Control.

    Practically: if you only run plain GA4 with no advertising features, a clear privacy policy and a working opt-out link are usually enough. The moment you switch on Google Signals, remarketing, or an ad pixel, you are into “sharing for targeted advertising” territory and you want a consent banner that actually gates the tags. A consent management plugin that supports Google consent mode is the cheapest way to do it properly. The IAPP state privacy legislation tracker is the reference I check when a client asks which states apply to them.

    Connect Search Console

    Do this while you are in the Admin screen. Go to Admin → Product links → Search Console links and link the Search Console property for the same domain. You need Editor access in Analytics and verified owner status in Search Console. Once linked, the Google Organic Search Queries and Google Organic Search Traffic reports appear in GA4, which is what lets you see the query that earned a session next to what that session did. Data takes about 48 hours to show up.

    Troubleshooting

    No data after 24 hours

    Check the page source for gtag/js?id= first. If the snippet is missing, a caching or optimization plugin is probably stripping or deferring it — purge the cache and exclude the tag from JavaScript minification and delay-until-interaction settings. If the snippet is present, confirm the ID in your source matches the ID in the data stream character for character. A trailing space pasted into a theme field breaks it silently.

    Duplicate page views

    Almost always two installs. Common combinations: Site Kit plus a standalone GA4 plugin, a theme field plus a plugin, or a GA4 tag inside Tag Manager while gtag.js is also hardcoded. Remove one. Tag Assistant will show you both.

    Ad blockers and browser protections

    Expect to lose traffic. Blockers, Safari’s tracking prevention and privacy-focused browsers all drop GA4 requests, and the gap is real — a technical audience blocks far more than a general one. Your GA4 numbers are a consistent sample, not a census. Compare GA4 trends against server logs or Search Console clicks rather than treating either as absolute truth.

    “Data stream is not receiving traffic”

    This banner in the stream details usually means the tag has genuinely never fired, not that something subtle is wrong. Work through it in this order: is the site public and not password-protected, is the tag on the page, is the tag on the page the visitor actually loads (a cached AMP or mobile variant may differ), and is your own traffic already being filtered out by an internal-traffic rule you forgot about.

    Recommended for you:

    How to Run a Database Query in WordPress (4 Safe Methods)
    Blog·Jul 30, 2026

    How to Run a Database Query in WordPress (4 Safe Methods)

    Old UA property still connected

    If a plugin or theme field still holds a UA- code, delete it. It does nothing, adds a request, and confuses whoever inherits the site. If you need to confirm what is stored where, our guide to running a database query in WordPress shows how to search the options table for a stray ID.

    Frequently asked questions

    Do I need a plugin to add Google Analytics to WordPress?

    No. A plugin is the easiest route, but the gtag.js snippet in a child theme’s wp_head hook does the same job with less overhead. Use a plugin if you want in-dashboard reports and a checkbox for excluding logged-in users; skip it if page weight is your priority.

    Where do I find my GA4 Measurement ID?

    In Google Analytics, open Admin → Data collection and modification → Data streams, click your web stream, and read the Measurement ID at the top of the stream details panel. It starts with G- followed by ten characters. That is the only value most plugins ask for.

    Is Google Analytics still free in 2026?

    Yes. The standard GA4 property is free and covers the event volumes typical WordPress sites generate. Google sells Analytics 360 for enterprises that need higher limits, longer retention and service guarantees, but nothing about basic web tracking sits behind a paywall.

    How long until data appears in GA4?

    Realtime usually shows a visit within a minute or two, and Google allows up to 30 minutes for collection to begin on a new stream. Standard reports lag further: expect up to 24 to 48 hours before the main reports and comparisons look complete.

    Should I use Google Tag Manager instead of installing GA4 directly?

    Use Tag Manager if you will run more than one tag, want version control, or need to hand tag changes to a marketer without deploy access. For a single GA4 install on a small site, direct installation is simpler and one request lighter.

    Will Google Analytics slow down my WordPress site?

    Barely, if installed correctly. The gtag.js file is small and loads asynchronously, so it does not block rendering. The real cost comes from stacking a heavy plugin on top of it, or from delay-until-interaction settings that push the tag so late that you lose short visits entirely.

    Wrapping up

    For most people the answer is Site Kit by Google, one property, one data stream, and an internal-traffic filter you actually verified. It takes fifteen minutes and it will not break when you update your theme. Choose the wp_head snippet instead if you care about every kilobyte, and choose Tag Manager if you already know you will be adding more tags.

    Whatever you pick, install it once, verify it in Tag Assistant, and resist the urge to add a second plugin “just to be sure”. Then spend your time on the part that pays: turning the numbers into decisions, which is where our guide to using Google Analytics for marketing picks up.

    Share. Facebook Twitter Pinterest LinkedIn Tumblr Telegram Email Copy Link
    Previous ArticleInstalling Elasticsearch on Cloudways (Complete Guide)
    Next Article How to Install Google Tag Manager on WordPress Correctly
    Marcus Bennett

      Marcus Bennett is GeekBlog's Android expert, covering everything from Google's Pixel line and Samsung Galaxy flagships to OnePlus, Nothing, Xiaomi and the broader Android ecosystem. He follows each Android OS release, One UI and Pixel Feature Drop, custom ROMs and the foldable wave, translating spec sheets and beta builds into hands-on guidance for readers choosing their next Android phone, tablet or wearable.

      Related Posts

      12 Mins Read

      A Toddler Needed a $20,000 Wheelchair. A High School Robotics Team Built Him One Instead.

      18 Mins Read

      Scientists Didn’t Say Earth Is Becoming Uninhabitable. Here’s What the “Hothouse Earth” Study Actually Says

      14 Mins Read

      Florida Is Putting Restaurant Oyster Shells Back in the Gulf — and the Seafloor Is Waking Up

      18 Mins Read

      New York vs Florida: Which State Is Better to Move To?

      15 Mins Read

      What State Is Best to Invest in Real Estate in 2026?

      15 Mins Read

      Texas vs California: Which State Is Better in 2026?

      Top Posts

      Microsoft Is Deleting Four Copilot Features on August 18, and One of Them Cannot Be Saved

      August 16, 20262 Views

      Best Low-End Android Games for 2GB/3GB RAM (That Actually Run Well)

      July 11, 20262 Views

      Android 17 Has Been Out Since June. Your Phone Probably Still Does Not Have It.

      August 17, 20261 Views
      Stay In Touch
      • Facebook

      Subscribe to Updates

      Get the latest tech news from FooBar about tech, design and biz.

      Most Popular

      Best Stores for Buying MP3 and Digital Music You Can Keep Forever (2026)

      August 2, 2025930 Views

      Discord will require a face scan or ID for full access next month

      February 9, 2026770 Views

      Trade in your old phone and get up to $1,100 off a new iPhone 17 at AT&T – here’s how

      September 10, 2025383 Views
      Our Picks

      Android 17 Has Been Out Since June. Your Phone Probably Still Does Not Have It.

      August 17, 2026

      A Black Hole Shredded a Super Sun. Astronomers Now Think Part of It Survived.

      August 16, 2026

      France Passed Europe’s First Under-15 Social Media Ban. Its Own Top Court Just Killed It.

      August 16, 2026

      Subscribe to Updates

      Get the latest creative news from FooBar about art, design and business.

      HEICJPG.online - Convert HEIC to JPG online
      Facebook
      • About Us
      • Contact us
      • Privacy Policy
      • Disclaimer
      • Terms and Conditions
      © 2026 GeekBlog

      Type above and press Enter to search. Press Esc to cancel.