Lean GA4 Tracker

Description

A lightweight, developer-friendly plugin to integrate Google Analytics 4 (GA4) tracking with WordPress. Designed for performance and simplicity, Lean GA4 Tracker lets you implement advanced GA4 tracking without the bloat of larger analytics plugins.

Includes lightweight WooCommerce tracking for product views, cart actions, checkout, and purchases — no extra setup required. Consent Mode integration supports Complianz, CookieYes, Cookiebot, and native WordPress consent APIs.

Key Features:

  • Easy integration with GA4 using your Measurement ID
  • Lightweight, performance-first architecture with no bloat
  • Manual GA4 API access using user-supplied access tokens and property IDs
  • Optional Google Tag Manager (GTM) container injection with support for Web, AMP, and Custom containers
  • Enable GTM Debug Mode for container preview/testing
  • Custom GA4 Event Tracking via JSON input
  • Tabbed settings UI for clean configuration management
  • Debug Mode for inspecting events in the console (admin only)
  • Error notices for invalid JSON in Custom Events field
  • Site-level and Multisite Network-level settings with optional enforcement
  • Configurable script loading (default, async, or defer)
  • Clean, class-based architecture with Composer and PSR-4 autoloading
  • Developer-friendly and extensible for custom implementations
  • Privacy-aware: Optional integration with Consent Mode and cookie banner plugins (e.g., Complianz, CookieYes)
  • Exclude specific user roles from GTM injection
  • Toggle support for automatic integration with Complianz, CookieYes, and Cookiebot cookie banners
  • Track form submissions from popular plugins including Contact Form 7, WPForms, Gravity Forms, Ninja Forms, Formidable Forms, and Fluent Forms
  • WooCommerce support: track product views, add to cart, checkout, and purchases using GA4 eCommerce event schema

Whether you’re a developer building custom themes or a site owner who wants full control over analytics, Lean GA4 Tracker delivers exactly what you need — nothing more, nothing less.

Screenshots

  • General tab: Configure GA4 Measurement ID, Script Load Mode, and optional GTM Container ID
  • Authentication tab: Enter GA4 Property ID and Manual Access Token
  • Events tab: Define custom GA4 events using a JSON array
  • Debug tab: Enable Debug Mode to print event tracking output for admins
  • Privacy & Consent tab: Enable Consent Mode and integrate with cookie banner plugins

Installation

  1. Upload the plugin files to /wp-content/plugins/lean-ga4-tracker
  2. Activate the plugin from your WordPress dashboard
  3. Go to Settings Lean GA4 Tracker to configure

FAQ

Can I track custom events without writing JavaScript?

Yes. You can enter a JSON array of custom GA4 events in the settings panel, and they will be dispatched automatically.

How does the plugin support Consent Mode?

It initializes GA4 with ad_storage: denied and analytics_storage: granted by default. You can modify or extend this via hooks.

Does this plugin support multisite networks?

Yes. Network admins can enforce a GA4 configuration across all sites or allow individual site overrides.

Where is the GA4 script loaded?

The script can be loaded using standard, async, or defer attributes — configurable from the admin settings.

Is the plugin suitable for developers?

Absolutely. The plugin is built using PSR-4 autoloading, Composer, and separates concerns with namespaced classes. It’s ready for extension or integration in your theme or stack.

Does the plugin support cookie consent banners?

Yes. While Lean GA4 Tracker does not include a built-in banner, it supports integration with popular cookie consent plugins including Complianz, CookieYes, and Cookiebot. You can optionally enable this integration from the Privacy tab in the plugin settings.

Can I use Google Consent Mode with this plugin?

Yes. If enabled in the Privacy tab, the plugin will initialize GA4 with Consent Mode defaults. You can manually trigger gtag('consent', 'update', ...) after consent is granted.

Can I track form submissions automatically?

Yes. Lean GA4 Tracker includes a Forms tab where you can enable GA4 event tracking for popular form plugins like Contact Form 7, WPForms, Fluent Forms, and others. No coding required.

Can I use this plugin with WooCommerce?

Yes. Lean GA4 Tracker includes built-in WooCommerce support. You can enable event tracking for product views, add to cart actions, checkout steps, and purchases — all dispatched using GA4 eCommerce event schema.

Reviews

There are no reviews for this plugin.

Contributors & Developers

“Lean GA4 Tracker” is open source software. The following people have contributed to this plugin.

Contributors

Translate “Lean GA4 Tracker” into your language.

Interested in development?

Browse the code, check out the SVN repository, or subscribe to the development log by RSS.

Changelog

1.1.3

  • Improved Consent Mode compatibility with WordPress and third-party consent plugins
  • Added listener for WordPress’s wp_consent_granted event
  • Confirmed WooCommerce support with product, cart, checkout, and order tracking
  • Enhanced leanGA4ConsentGranted()
  • Added WooCommerce tab for toggling GA4 event tracking
  • Supports product views, add to cart, begin checkout, and purchase events
  • Events dispatched using gtag() with product ID, name, price, and order data

1.1.1

  • Added Forms tab with toggles for form submission tracking
  • Supports Contact Form 7, WPForms, Gravity Forms, Ninja Forms, Formidable Forms, and Fluent Forms
  • GA4 events include form title and form ID using gtag()

1.1.0

  • Added toggle to enable/disable cookie plugin integration (Complianz, CookieYes, Cookiebot)
  • Integrated JS listeners for automatic consent handling via supported plugins
  • Improved ConsentManager logic with extensible update function
  • Added dynamic consent update helpers for developers and cookie plugins

1.0.9

  • Added “Exclude User Roles” option in Tag Manager settings
  • Added AMP-compatible container injection using tag
  • Added support for “Custom” container type to allow manual GTM handling
  • Ensured all Tag Manager settings are properly registered on admin_init
  • Improved container-type-specific GTM rendering logic
  • Fixed settings save behavior for checkboxes and radios with fallback handling

1.0.8

  • Added GTM Debug Mode toggle in Tag Manager settings
  • Enhanced container type support: Web, AMP, and Custom
  • Improved script injection logic and frontend behavior

1.0.7

  • Improved Multisite Compatibility for Custom Events
  • Added sample GA4 event JSON and live validation to both site-level and network-level settings
  • Enhanced admin UI guidance for defining custom events across installations

1.0.6

  • Added Privacy & Consent settings tab with support for Google Consent Mode
  • Added notice recommending cookie banner plugins for frontend consent control
  • Improved ConsentManager handling and script modularity

1.0.5

  • Introduced tab-based settings UI with General, Authentication, Events, and Debug sections
  • Added manual GA4 access token and property ID input for non-OAuth usage
  • Added GTM container injection option with <head> and <noscript> support
  • Improved internal structure for OAuth and manual mode support (future-ready)

1.0.4

  • Added async script loading via WordPress 6.3+ ‘strategy’ attribute
  • Replaced placeholder script with inline-only registration for GA4 config
  • Injected official gtag.js loader from Google using proper async method
  • Improved inline script structure using wp_json_encode and output validation

1.0.3

  • Improved GA4 inline script injection with reliable output structure
  • Replaced empty script handle with placeholder registration for consistent rendering
  • Verified compatibility with themes and ensured presence of GA4 tag in frontend

1.0.2

  • Refactored to a modular, class-based architecture using namespaces
  • Added support for multisite network settings with enforcement
  • Introduced debug mode and custom event JSON handling
  • Integrated script loading mode (default, async, defer)
  • Added error notices for invalid JSON input

1.0.1

  • Update code following PHPCS
  • escaped all code properly

1.0

  • Initial Release