Sign inDocsBlogAboutSupportContact
Analytics

Add GA4 to WordPress without a plugin or Tag Manager

Measurement ID in one hand, one command in the other. GA4 tracking live in under 30 seconds, no theme edits, no GTM middleware.

3 min read May 2026 enable ga4

The WordPress way to install GA4 is clunky

Your site has no analytics. You can't tell which blog post converted best, what device people actually use, or when traffic spiked.

The canonical WordPress paths are: install an analytics plugin (comes with admin pages, updates, subscription nags), paste the snippet into functions.php (breaks when you switch themes), or set up Google Tag Manager as middleware (overkill for one pixel).

What most people do instead

Install a dedicated GA4 pluginYet another plugin. Admin page, settings, update nag. Some have premium tiers to unlock basic features.
Paste the tracking code into functions.phpTied to the active theme. Switch themes → tracking disappears. No conditional logic.
Set up GTM as middlewareAdds another layer. GTM itself has to be installed. Overkill if GA4 is the only thing you need.

How to add GA4 to WordPress without a plugin

If you only need GA4 and nothing else, you can output the tag yourself. Drop a must-use plugin in wp-content/mu-plugins/ that prints Google's gtag.js snippet into the page head:

// wp-content/mu-plugins/ga4.php
add_action( 'wp_head', function () { ?>
  <!-- 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 } );

Swap G-XXXXXXXXXX for your Measurement ID and GA4 starts collecting. It works, with the usual trade-offs:

  • In functions.php it dies the moment you switch themes. The mu-plugins folder avoids that.
  • The ID is hardcoded, so you edit the file to change it.
  • It fires for everyone, including logged-in admins, so your own visits skew the data.

The command below does the same thing with no file to maintain.

A better way: one command, one ID, tracking live

Run enable ga4 with your Measurement ID. The command auto-registers as a startup command so the tracking snippet outputs on every page load. No theme edit, no plugin, no GTM middleware.

TrueCommander
GA4 enabled
Tracking live on next page load
Measurement ID: G-XXXXXXX
Registered as startup commandactive

Shown in advanced mode, where commands start with tp. In easy mode you type the same command without the tp prefix.

Stored in the database, not your theme. The Measurement ID survives theme switches and updates. Change it anytime by re-running the command, and disable it from Startup Commands.

How it works

The command hooks wp_head with the Google-provided tracking snippet, then auto-registers itself in Startup Commands so the tracking stays active across requests. Re-running with a different ID updates the existing entry. Disable from Startup Commands to remove.

1
Get your Measurement IDGoogle Analytics → Admin → Data Streams
2
Run the command with the IDtp enable ga4 -mid=G-XXXXXXX
3
Verify in Google's dashboardGA4 shows tracking events within minutes
ParameterValue
-mid (required)Measurement ID (format: G-XXXXXXX)
ScopeAuto-registered as startup command, runs on every frontend page load
Where to find the IDGoogle Analytics → Admin → Data Streams
Can be used in

Real example

Your marketing director wants GA4 on the site by Friday. Without this command, you'd install Site Kit (requires Google account auth dance) or MonsterInsights (premium features gated). Instead, you grab the Measurement ID from Google Analytics, run tp enable ga4 -mid=G-ABC123, done. Traffic starts hitting GA4 within minutes.

Goes further with TrueCommander

Frequently asked questions

Ready?

GA4 tracking in 30 seconds.

This is one of 91 commands. All included with every license.

Cookies. The short version.

Essential cookies keep the cart and theme working. Analytics only fire if you say yes. Read our policy.