=== Lean GA4 Tracker === Contributors: maidulcu Tags: google analytics, GA4, tracking, lightweight Requires at least: 6.2 Tested up to: 6.7 Stable tag: 1.1.4 Requires PHP: 8.2 License: GPLv2 or later License URI: http://www.gnu.org/licenses/gpl-2.0.html Lightweight GA4 tracker with GTM support, custom events, privacy-friendly setup, and tabbed settings. Manual GA4 API token support included. == 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. = Resources = - [Documentation](https://www.dynamicweblab.com/plugins/lean-ga4-tracker/docs/) - [Plugin Landing Page](https://www.dynamicweblab.com/plugins/lean-ga4-tracker/) 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. == 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 == Frequently Asked Questions == = 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. == Changelog == = 1.1.4 = * Added new Script Load Mode option: "Idle (after page load)" using requestIdleCallback with fallback * Improved admin settings UI for script placement options * Enhanced sanitization to support new load mode * Minor code refactoring and documentation updates = 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 * Enhanced WooCommerce tracking security and GA4 payload accuracy — added JSON-encoded event payloads, quantity/currency support, duplicate purchase prevention, and front-end-only tracking hooks = 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 `` and `