PHPackages                             wearerequired/required-google-analytics - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Queues &amp; Workers](/categories/queues)
4. /
5. wearerequired/required-google-analytics

ActiveWordpress-plugin[Queues &amp; Workers](/categories/queues)

wearerequired/required-google-analytics
=======================================

WordPress plugin to add Google's global site tag (gtag.js) to your site, the modern way.

3.1.0(2y ago)413.6k↓50%[1 issues](https://github.com/wearerequired/required-google-analytics/issues)GPL-2.0-or-laterPHPPHP &gt;=7.4

Since Jun 10Pushed 2y ago1 watchersCompare

[ Source](https://github.com/wearerequired/required-google-analytics)[ Packagist](https://packagist.org/packages/wearerequired/required-google-analytics)[ Docs](https://github.com/wearerequired/required-google-analytics)[ RSS](/packages/wearerequired-required-google-analytics/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (1)Versions (14)Used By (0)

Google Analytics
================

[](#google-analytics)

A lightweight WordPress plugin to add Google's global site tag (gtag.js) to your site, the modern way.

The modern way? The script is added with support for preloading, which will provide a small performance boost on modern browsers.
Modern browsers are those that support the `async` script attribute. This does not include IE 9 and older mobile browsers.

You can use this plugin with Universal Analytics or Google Analytics 4 properties or, to help ease the transition period, dual tagging is also supported.

Beside that, the plugin doesn't do more. No fancy report view in your admin, no authentication requirements, no additional scripts, and no ads for random blog posts.

Installation
------------

[](#installation)

Install via Composer

```
$ composer require wearerequired/required-google-analytics

```

Add you property ID at Settings &gt; Reading &gt; Google Analytics.

Disable Analytics for opted-out users
-------------------------------------

[](#disable-analytics-for-opted-out-users)

The plugin provides a function to let users [opt out of Google Analytics measurement](https://developers.google.com/analytics/devguides/collection/gtagjs/user-opt-out). If the function `window.requiredGADoOptOut()` is called a `ga-opted-out` item is stored in the local browser storage and the `window` property `window['ga-disable-PROPERTY_ID']` will be set to `true`.

Example:

```
Opt-out from Google Analytics for this site.

```

Event Tracking for Universal Analytics
--------------------------------------

[](#event-tracking-for-universal-analytics)

The plugin provides a small layer that transform data attributes on an HTML element to a [Google Analytics event](https://developers.google.com/analytics/devguides/collection/gtagjs/events). To enable the layer use the following filter:

```
add_filter( 'required_ga.enable_event_tracking', '__return_true' );

```

To track the click event of a button you can now use the following data attributes:

- `data-ga-event-action`: Event action.
- `data-ga-event-on`: Optional. Event trigger. Defaults to `click` and can be any [DOM event](https://developer.mozilla.org/en-US/docs/Web/Events).
- `data-ga-event-category`: Optional. Event category.
- `data-ga-event-label`: Optional. Event label.
- `data-ga-event-value`: Optional. Event value.

Example usage:

```
Click me!

Click me!

```

Additional Config Info
----------------------

[](#additional-config-info)

To configure [custom dimensions and metrics](https://developers.google.com/analytics/devguides/collection/gtagjs/custom-dims-mets) you can use the `required_ga.additional_config_info` filter. By default the [`forceSSL`](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#forceSSL) and [`anonymizeIp`](https://developers.google.com/analytics/devguides/collection/analyticsjs/field-reference#anonymizeIp) fields are set to true.

Example usage:

```
add_filter( 'required_ga.enable_event_tracking', function( $config ) {
	$config['custom_map'] = [
		'dimension1' => 'author',
	];

	if ( is_singular( 'post' ) ) {
		$config['author'] = get_the_author_meta( 'display_name', get_post()->post_author )
	}

	return $config;
} );

```

Support for analytics.js (Universal Analytics)
----------------------------------------------

[](#support-for-analyticsjs-universal-analytics)

Starting with version 2.0 the plugin enqueues [gtag.js](https://developers.google.com/analytics/devguides/collection/gtagjs/). If you need support for analytics.js you can continue using the 1.x branch.

```
$ composer require wearerequired/required-google-analytics:"^1.0"

```

###  Health Score

35

—

LowBetter than 80% of packages

Maintenance15

Infrequent updates — may be unmaintained

Popularity28

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity70

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~151 days

Recently: every ~231 days

Total

13

Last Release

1082d ago

Major Versions

1.2.0 → 2.0.02019-05-14

2.4.0 → 3.0.02022-05-09

PHP version history (2 changes)1.0.0PHP &gt;=7.0

3.0.0PHP &gt;=7.4

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/1446895?v=4)[required](/maintainers/wearerequired)[@wearerequired](https://github.com/wearerequired)

---

Top Contributors

[![ocean90](https://avatars.githubusercontent.com/u/617637?v=4)](https://github.com/ocean90 "ocean90 (61 commits)")[![krokodok](https://avatars.githubusercontent.com/u/10128264?v=4)](https://github.com/krokodok "krokodok (1 commits)")[![swissspidy](https://avatars.githubusercontent.com/u/841956?v=4)](https://github.com/swissspidy "swissspidy (1 commits)")

---

Tags

google-analyticsgtagwordpresswordpress-pluginasyncwordpressdns-prefetchgoogle-analyticsgtag

### Embed Badge

![Health badge](/badges/wearerequired-required-google-analytics/health.svg)

```
[![Health](https://phpackages.com/badges/wearerequired-required-google-analytics/health.svg)](https://phpackages.com/packages/wearerequired-required-google-analytics)
```

###  Alternatives

[amphp/amp

A non-blocking concurrency framework for PHP applications.

4.4k123.4M323](/packages/amphp-amp)[react/socket

Async, streaming plaintext TCP/IP and secure TLS socket server and client connections for ReactPHP

1.3k116.9M402](/packages/react-socket)[revolt/event-loop

Rock-solid event loop for concurrent PHP applications.

92343.6M138](/packages/revolt-event-loop)[spatie/async

Asynchronous and parallel PHP with the PCNTL extension

2.8k4.5M37](/packages/spatie-async)[amphp/parallel

Parallel processing component for Amp.

85046.2M74](/packages/amphp-parallel)[react/dns

Async DNS resolver for ReactPHP

536114.1M100](/packages/react-dns)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
