Get a free website with any plan

See how
WORDPRESS

Adding Google Analytics to WordPress (with and without a plugin)

Last updated

IN SHORT

To add Google Analytics 4 to WordPress on Flashcloud, use a plugin like Site Kit or paste the GA4 gtag.js snippet into your theme header. Plugins show reports in wp-admin. Manual code avoids an extra plugin, but requires a child theme to survive updates. Never use both methods at once to avoid double-counting visitors.

The fastest way to add Google Analytics to WordPress is a dedicated plugin like Site Kit by Google, MonsterInsights, or Analytics for WordPress. If you want zero dependencies and full control over where the tracking code loads, paste the GA4 gtag.js snippet directly into your theme's header. Both work. The plugin route is faster to set up and gives you reports inside wp-admin; the manual route is one less plugin to keep updated.

Before you start: get your GA4 measurement ID

Create a GA4 property at analytics.google.com if you don't have one, then add a "Web" data stream for your domain. Google gives you a measurement ID that looks like G-XXXXXXXXXX. You'll need this for either method below.

Method 1: with a plugin

From wp-admin, go to Plugins → Add New and search for one of these:

  • Site Kit by Google - official Google plugin, connects your Google account directly, shows Analytics and Search Console data in wp-admin.
  • MonsterInsights - popular third-party option, free tier covers basic GA4 setup, paid tiers add ecommerce and form tracking.

Install, activate, then follow the plugin's setup wizard. It walks you through authorizing with your Google account and picking (or creating) the GA4 property. The plugin inserts the tracking snippet into every page automatically, no code editing required.

This is the right choice if you want in-dashboard reports, don't want to touch theme files, or you're not comfortable editing PHP. It's also the safer option if you update themes often, since manual snippet edits get wiped out on a theme update unless you're using a child theme.

Method 2: manual snippet, no plugin

Copy the gtag.js snippet from your GA4 property (Admin → Data Streams → your stream → View tag instructions → Install manually). It looks like this:

<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>

Then add it to your theme's <head> section, right before the closing </head> tag. Two ways to do that:

  • wp-admin → Appearance → Theme File Editor, open header.php, paste the snippet before </head>. Works, but if you're not on a child theme, a theme update overwrites this and you lose tracking silently.
  • A child theme's functions.php, hooked into wp_head instead of editing the template file directly. This survives parent theme updates. Add this to functions.php:
function flashcloud_add_ga4() {
    ?>
    <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
}
add_action('wp_head', 'flashcloud_add_ga4');

Use the portal's File Manager tile (Services → your hosting → File Manager) or an FTP client to reach these theme files if you'd rather not use the in-admin theme editor.

Verify it's actually tracking

Load your site in an incognito window, then check GA4's Reports → Realtime view. You should see yourself as an active user within a minute or two. If nothing shows up:

  • View page source and confirm the gtag.js script tag is actually present in the HTML. If it's missing, the snippet didn't save, or a cache is serving an old version of the page.
  • Check for a caching plugin or server-level page cache holding a stale copy. Purge it and reload.
  • Confirm you used the measurement ID from the right GA4 property. If you manage multiple sites, double-check which ID you copied.
  • Ad blockers and privacy extensions block gtag.js in the browser you're testing with. Try a different browser or disable the extension for the test.

A note on performance and duplicate tracking

Only run one tracking method at a time. If you install a plugin and later add the manual snippet (or vice versa), you'll double-count every pageview and your bounce rate and session numbers will be wrong. Check your theme's header and your active plugins before troubleshooting numbers that look off.

The gtag.js snippet is small and loads async, so it won't meaningfully affect page speed either way. If you're chasing every millisecond, the plugin route adds a small amount of admin-side overhead (settings pages, wp-admin queries) that the manual snippet doesn't, but it has no effect on your actual page load time for visitors.

Common questions

Will Google Analytics slow down my WordPress site?

No, it will not hurt your visitor load times. The gtag.js snippet loads asynchronously and remains very small. Plugins introduce minor admin overhead inside wp-admin, but visitors experience no difference.

Why are my pageviews counting twice?

You likely have two tracking methods active at the same time. Check your active plugins and your theme header to make sure you are not running both a plugin and the manual snippet.

Why is real-time tracking not working?

An ad blocker, a caching layer, or an incorrect measurement ID is usually the cause. Disable browser extensions, purge your site and server cache, and confirm the gtag.js tag appears in your page source.

Will updating my theme break my manual tracking code?

Yes, if you pasted the snippet directly into a parent theme header.php file. Use a child theme functions.php file or a plugin to make your tracking code survive theme updates.

CAN'T FIND IT?

Real humans answer fast.

Hosting with us? Open a ticket and a real person replies - no scripts, no upsells. Still choosing a host? The same team is included with every plan, from day one.