

Plugin settings page for Lightweight Google Analytics
This simple plugin adds Google Analytics 4 (GA4) to your WordPress site using your Measurement ID. It prints Google’s standard gtag.js snippet, nothing more, with a few options for where it loads, who gets tracked, privacy and testing.
Features
The plugin does not include any reporting. To see your statistics, open Google Analytics.
Note: Universal Analytics (UA-) was shut down by Google in 2023 and is no longer supported. If you still have a UA- ID saved, the plugin outputs nothing until you enter a GA4 Measurement ID.
Change the options passed to gtag("config", ...), for example to disable the automatic page view or set cookie flags:
add_filter( 'lightweight_ga_gtag_config', function ( $config, $measurement_id ) {
$config['send_page_view'] = false;
$config['cookie_flags'] = 'SameSite=None;Secure';
return $config;
}, 10, 2 );
Change the Consent Mode defaults, for example to only deny storage for EU visitors:
add_filter( 'lightweight_ga_consent_defaults', function ( $defaults ) {
$defaults['region'] = array( 'AT', 'BE', 'DE', 'FR', 'IE', 'NL' );
return $defaults;
} );
Skip the tracking code for any request:
add_filter( 'lightweight_ga_disable_tracking', function ( $disabled ) {
return $disabled || is_page( 'internal-dashboard' );
} );