Title: Lightweight Google Analytics
Author: Andy Feliciotti
Published: <strong>24 Ctember 2020</strong>
Last modified: 13 Tuber 2026

---

Search plugins

![](https://ps.w.org/lightweight-google-analytics/assets/banner-772x250.jpg?rev=
2719903)

![](https://ps.w.org/lightweight-google-analytics/assets/icon-256x256.png?rev=2387397)

# Lightweight Google Analytics

 By [Andy Feliciotti](https://profiles.wordpress.org/someguy9/)

[Download](https://downloads.wordpress.org/plugin/lightweight-google-analytics.1.7.0.zip)

 * [Details](https://kab.wordpress.org/plugins/lightweight-google-analytics/#description)
 * [Reviews](https://kab.wordpress.org/plugins/lightweight-google-analytics/#reviews)
 *  [Installation](https://kab.wordpress.org/plugins/lightweight-google-analytics/#installation)
 * [Development](https://kab.wordpress.org/plugins/lightweight-google-analytics/#developers)

 [Support](https://wordpress.org/support/plugin/lightweight-google-analytics/)

## Description

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

 * Performance focused with no bloat and never any upsells
 * Only needs your GA4 Measurement ID (G-XXXXXXXX), or paste Google’s whole tag 
   snippet and the ID is picked out of it
 * Load the tracking code in the header or footer
 * Exclude logged-in users by role (admins, editors and authors are excluded by 
   default)
 * Post previews and the Customizer are never tracked
 * Option to disable Google’s advertising features (Google signals)
 * Google Consent Mode v2 support for GDPR/CCPA compliance, working automatically
   with consent plugins that support the WP Consent API (such as Complianz and CookieYes)
 * Option to honor Global Privacy Control, the opt-out signal sent by Brave, DuckDuckGo
   and Firefox
 * Optional content groups: the post’s category (or page type) as GA4’s Content 
   group, plus the author’s name, so you can compare sections and authors in reports
 * Warns you on the settings page when another plugin, your theme or a pasted snippet
   also adds Google Analytics, so page views aren’t counted twice
 * Debug Mode for testing in GA4 DebugView
 * Optional Minimal Analytics 4 mode: a 3.5 KB inline script that reports page views,
   scrolls, downloads, outbound clicks and site searches without loading gtag.js
   at all
 * The settings page tells you whether tracking is live and why your own visits 
   may not show up
 * Filters for developers to change the gtag config, the consent defaults or when
   tracking is skipped

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.

#### For developers

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;
    } );
    ```

Change the content group or author sent with each page (when Content Groups is on),
or add more page-level parameters:

    ```
    add_filter( 'lightweight_ga_page_dimensions', function ( $dimensions ) {
        if ( is_page( 'pricing' ) ) {
            $dimensions['content_group'] = 'Sales';
        }
        return $dimensions;
    } );
    ```

Skip the tracking code for any request:

    ```
    add_filter( 'lightweight_ga_disable_tracking', function ( $disabled ) {
        return $disabled || is_page( 'internal-dashboard' );
    } );
    ```

## Screenshots

[⌊Plugin settings page for Lightweight Google Analytics⌉⌊Plugin settings page for
Lightweight Google Analytics⌉[

Plugin settings page for Lightweight Google Analytics

## Installation

 1. Upload the plugin to the wp-content/plugins directory, or install it from the Plugins
    screen.
 2. Activate it from the Plugins screen.
 3. Go to Settings > Lightweight Google Analytics, enter your Measurement ID and save.

## FAQ

### How do I find my Google Analytics 4 Measurement ID?

In Google Analytics go to Admin > Data Streams, open your web stream and copy the
Measurement ID. It starts with G-.

### Tracking is enabled but I don’t see my own visits

By default the tracking code is not loaded for logged-in administrators, editors
and authors, so your own browsing does not pollute your reports. The status message
at the top of the settings page tells you whether this applies to your account. 
Change the Tracking Level setting to « Track all users » if you want to be counted.

### What is Consent Mode and do I need it?

Google Consent Mode v2 tells Google that analytics and advertising storage are denied
until the visitor consents. Enable it if you use a cookie consent plugin that updates
the consent state through `gtag("consent", "update", ...)` and you need to comply
with GDPR or similar rules. It only applies to Google’s gtag.js code.

### Which consent plugins work with Consent Mode?

Any consent plugin that supports the [WP Consent API](https://wordpress.org/plugins/wp-consent-api/),
such as Complianz and CookieYes, works automatically: install and activate the WP
Consent API plugin, then turn on Consent Mode. Statistics consent controls Google
Analytics storage and marketing consent controls the advertising storage types, 
and both follow the visitor’s choice when it changes. Note that the WP Consent API
treats a site with no consent plugin as having consent. Other consent plugins need
to call `gtag("consent", "update", ...)` themselves.

### What does the Global Privacy Control option do?

Global Privacy Control is an opt-out signal built into Brave and DuckDuckGo and 
available in Firefox. California’s CCPA and similar US state laws treat it as a 
request to opt out of the sale or sharing of personal information. When the option
is on, visitors who send the signal are not measured: gtag.js gets Google’s documented
opt-out flag, and Minimal Analytics doesn’t run at all.

### How do I see content groups and authors in Google Analytics?

Turn on Content Groups in the plugin settings. The content group shows up under 
the built-in « Content group » dimension in reports such as Pages and screens. To
report on authors, add an event-scoped custom dimension named `author` in Google
Analytics under Admin > Custom definitions; it fills in from then on, usually within
48 hours.

### Why does the settings page say my page views are counted twice?

The plugin checks whether another analytics plugin is set up to add Google Analytics
too (such as Site Kit, MonsterInsights or Rank Math), and looks at your home page
for other Google tags added by your theme or a code snippet plugin. Remove the extra
copy so each visit is only counted once. Tags that only appear on some pages, or
only after cookie consent, can’t be detected.

### What is the Minimal Analytics 4 option?

It replaces Google’s gtag.js with [Minimal Analytics 4](https://github.com/idarek/minimal-analytics-4)
by Dariusz Wieckiewicz (MIT), a small inline script that talks to Google Analytics
directly. It sends page views, session start and engagement events, 90% scrolls,
file downloads, outbound link clicks and site searches, plus UTM campaign attribution.
It does not support Consent Mode or Google’s enhanced measurement, and it stores
its client and session IDs in localStorage, so check your privacy requirements before
using it. With the WP Consent API and Consent Mode turned on, it waits until the
visitor allows statistics before it runs.

### How do I test if tracking is working?

Enable Debug Mode in the plugin settings, then in Google Analytics go to Admin >
DebugView to watch hits arrive in real time. Turn Debug Mode off when you are done.

### Is Universal Analytics (UA-) still supported?

No. Google stopped processing Universal Analytics data in July 2023 and deleted 
the properties in 2024, so version 1.6.0 removed the UA code. Enter a GA4 Measurement
ID instead.

## Reviews

![](https://secure.gravatar.com/avatar/bc248f07aded6aecc5c40cd06ea1cabce5a4fc651a8fc9bc099573200d840d61?
s=60&d=retro&r=g)

### 󠀁[Good plugin…](https://wordpress.org/support/topic/good-plugin-5436/)󠁿

 [VannDigital](https://profiles.wordpress.org/vdn-staff/) 16 Γuct 2021 2 replies

…so far. Hope it stays updated!!!

![](https://secure.gravatar.com/avatar/5c8f0880b104c6acfa0f0f9ffc9fc5733eda817ae78f89ab07387328bf47e777?
s=60&d=retro&r=g)

### 󠀁[Significantly reduced page load time](https://wordpress.org/support/topic/significantly-reduced-page-load-time/)󠁿

 [Ryan Robinson](https://profiles.wordpress.org/ryrob/) 30 Ctember 2020

I've been on a quest to speed up my blog for a long time, and reducing the number
of requests my previous Google Analytics plugin was making (and the amount of code
it was injecting onto my site) was a major tipping point for getting my pages loading
lightning fast after making some other site-wide optimizations. I'm using the minimal
analytics option with the plugin and it took my GA file size down to 2kb (instead
of 17kb where it previously was with Monster Analytics). This plugin is incredibly
simple, easy-to-use and straight forward… it does exactly what it says!

 [ Read all 2 reviews ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/)

## Contributors & Developers

“Lightweight Google Analytics” is open source software. The following people have
contributed to this plugin.

Contributors

 *   [ Andy Feliciotti ](https://profiles.wordpress.org/someguy9/)

“Lightweight Google Analytics” has been translated into 5 locales. Thank you to 
[the translators](https://translate.wordpress.org/projects/wp-plugins/lightweight-google-analytics/contributors)
for their contributions.

[Translate “Lightweight Google Analytics” into your language.](https://translate.wordpress.org/projects/wp-plugins/lightweight-google-analytics)

### Interested in development?

[Browse the code](https://plugins.trac.wordpress.org/browser/lightweight-google-analytics/),
check out the [SVN repository](https://plugins.svn.wordpress.org/lightweight-google-analytics/),
or subscribe to the [development log](https://plugins.trac.wordpress.org/log/lightweight-google-analytics/)
by [RSS](https://plugins.trac.wordpress.org/log/lightweight-google-analytics/?limit=100&mode=stop_on_copy&format=rss).

## Changelog

#### 1.7.0

 * Fixed: saving the settings for the first time on a new install switched on Consent
   Mode, Debug Mode and Disable Display Features by themselves (since 1.5.0). Sites
   updating from an affected version that have any of them on get a one-time notice
   asking to check them.
 * Fixed: with Minimal Analytics in the header (the default), page views were sent
   before the page title existed, so GA4 showed « (not set) » titles, and scrolling
   at the top of the page caused a JavaScript error.
 * Fixed: saving a mistyped or pasted Measurement ID cleared the working one and
   stopped tracking. The previous ID is now kept, and the ID is picked out of a 
   pasted gtag snippet or URL.
 * Fixed: with the tracking code in the footer, the Consent Mode defaults were printed
   in the footer too, after consent banners could already update them. They now 
   always go in the head.
 * Fixed: setup notices were shown to all logged-in users on every admin screen.
   They now only show to admins, and the setup reminder only on the Dashboard and
   Plugins screens.
 * Fixed: the settings page told new installs to tick « Enable Google Analytics »
   although it was already ticked.
 * New: works with consent plugins that support the WP Consent API when Consent 
   Mode is on, for gtag.js and Minimal Analytics.
 * New: option to honor Global Privacy Control.
 * New: optional content groups (post category or page type) and author names for
   GA4 reports, with a `lightweight_ga_page_dimensions` filter.
 * New: duplicate tracking warning when another plugin, the theme or a snippet also
   adds Google Analytics.
 * New: a warning when Consent Mode is on but Minimal Analytics would ignore it,
   and a hint when the WP Consent API is active but Consent Mode is off.
 * Network super admins are excluded along with administrators, and deleting the
   plugin on a multisite network removes its settings from every site.
 * Settings fields are now properly labeled for screen readers.

#### 1.6.0

 * Removed Universal Analytics (UA-) support, which Google shut down in 2023. UA-
   IDs are no longer accepted and the IP anonymization option, which only applied
   to UA, is gone because GA4 always anonymizes IPs.
 * New status message on the settings page that shows whether tracking is active
   and whether it is disabled for your own account.
 * Post previews and the Customizer are no longer tracked.
 * New filters for developers: `lightweight_ga_gtag_config`, `lightweight_ga_consent_defaults`
   and `lightweight_ga_disable_tracking`.
 * Updated Minimal Analytics 4 to the current release, which adds session handling,
   engagement time, UTM attribution and outbound click tracking, and keeps all of
   its variables out of the global scope. Its source and license now ship alongside
   the minified file, and Debug Mode applies to it too.
 * Tracking code is printed through WordPress’s script tag functions, so Content
   Security Policy nonces added with the `wp_inline_script_attributes` and `wp_script_attributes`
   filters are applied.
 * The Measurement ID is validated and escaped on output, including IDs saved before
   validation was added in 1.5.0.
 * Text domain corrected to `lightweight-google-analytics` so translations from 
   WordPress.org load.
 * Deleting the plugin now removes its settings.
 * Tested up to WordPress 7.1. Requires WordPress 5.7 or newer.

#### 1.5.0

 * Added Google Consent Mode v2 support for GDPR/CCPA compliant tracking.
 * Added Debug Mode toggle for GA4 testing via DebugView.
 * Updated messaging to prioritize Google Analytics 4 (GA4) over deprecated Universal
   Analytics.
 * Added admin notice warning for sites still using Universal Analytics (UA-) tracking
   IDs.
 * Added note clarifying that IP anonymization is automatic in GA4.
 * Added input sanitization and validation for tracking IDs and all settings.
 * Code cleanup and optimization.
 * Tested up to WordPress 6.9.

#### 1.4.3

 * Tested up to WordPress 6.5.
 * Upgraded minimal analytics tracking scripts.

#### 1.4.2

 * Tested up to WordPress 6.3.

#### 1.4.1

 * PHP Error bugfix.

#### 1.4

 * Included MinimalAnalytics4 by [idarek on GitHub](https://gist.github.com/idarek/9ade69ac2a2ef00d98ab950426af5791).
   This allows you to use a gtag tracking code for page views & site search without
   loading Google’s bloated tracking library.
 * Removed jQuery references in the admin for vanilla JS.
 * Tested up to WordPress 6.0.

#### 1.3

 * Tested up to WordPress 5.8.
 * Added link to analytics.google.com in settings page

#### 1.2.2

 * PHP Warning bug fix.

#### 1.2.1

 * Tested up to WordPress 5.7.

#### 1.2.0

 * Added the ability to use Global site tag measurement ID (gtag.js) as well as 
   Universal Analytics tracking ID (analytics.js).

#### 1.1.1

 * Admin page tweaks and added a setup prompt at first install

#### 1.1.0

 * Added option to use MinimalAnalytics.com’s tracking code

#### 1.0.0

 * Initial Release.

## Meta

 *  Version **1.7.0**
 *  Last updated **1 n waggur ago**
 *  Active installations **400+**
 *  WordPress version ** 5.7 or higher **
 *  Tested up to **7.1.4**
 *  PHP version ** 7.0 or higher **
 *  Languages
 * [English (US)](https://wordpress.org/plugins/lightweight-google-analytics/), 
   [Spanish (Chile)](https://cl.wordpress.org/plugins/lightweight-google-analytics/),
   [Spanish (Colombia)](https://es-co.wordpress.org/plugins/lightweight-google-analytics/),
   [Spanish (Mexico)](https://es-mx.wordpress.org/plugins/lightweight-google-analytics/),
   [Spanish (Spain)](https://es.wordpress.org/plugins/lightweight-google-analytics/),
   akked [Spanish (Venezuela)](https://ve.wordpress.org/plugins/lightweight-google-analytics/).
 *  [Translate into your language](https://translate.wordpress.org/projects/wp-plugins/lightweight-google-analytics)
 * Tags
 * [analytics](https://kab.wordpress.org/plugins/tags/analytics/)[consent mode](https://kab.wordpress.org/plugins/tags/consent-mode/)
   [ga4](https://kab.wordpress.org/plugins/tags/ga4/)[GDPR](https://kab.wordpress.org/plugins/tags/gdpr/)
   [google analytics](https://kab.wordpress.org/plugins/tags/google-analytics/)
 *  [Advanced View](https://kab.wordpress.org/plugins/lightweight-google-analytics/advanced/)

## Ratings

 5 out of 5 stars.

 *  [  2 5-star reviews     ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/?filter=5)
 *  [  0 4-star reviews     ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/?filter=4)
 *  [  0 3-star reviews     ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/?filter=3)
 *  [  0 2-star reviews     ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/?filter=2)
 *  [  0 1-star reviews     ](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/?filter=1)

[Your review](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/#new-post)

[See all reviews](https://wordpress.org/support/plugin/lightweight-google-analytics/reviews/)

## Contributors

 *   [ Andy Feliciotti ](https://profiles.wordpress.org/someguy9/)

## Support

Got something to say? Need help?

 [View support forum](https://wordpress.org/support/plugin/lightweight-google-analytics/)

## Donate

Would you like to support the advancement of this plugin?

 [ Donate to this plugin ](https://www.buymeacoffee.com/someguy)