This WordPress plugin sends Core Web Vitals data to Google Analytics. It is compatible with Web Vitals Report
This plugin can be installed as a Composer dependency:
composer require xwp/site-performance-tracker
or by downloading a plugin ZIP file from the releases page.
The plugin must be configured by setting the site_performance_tracker_vitals
theme feature with your Analytics IDs. Collected data will be available in Web Vitals Report in a few days.
To send Web Vitals metrics to Google Analytics in a format compatible with the Web Vitals Report, enable the following theme support and passing in the ID:
GA4 Analytics is supported, requires passing the ID using ga4_id
:
add_theme_support( 'site_performance_tracker_vitals', array(
'ga4_id' => 'G-XXXXXXXXXX',
) );
The following hooks can be added to a theme or a custom plugin to configure the plugin, alternatively you can configure the plugin through the settings screen, in case of duplication, plugin will take programmatically set settings. To confirm they were applied look for the webVitalsAnalyticsData
global variable in the page source.
The following filter can be used to limit the number of tracking events to a percentage of your traffic. For example, to limit the tracking events to 5% of requests, use the following logic:
add_filter( 'site_performance_tracker_chance', function() {
return 0.05;
} );
Programmatically disable the plugin.
add_filter( 'site_performance_tracker_disabled', '__return_true' );
Programmatically delay web vitals tracking to minimise impact on interactivity. By default, an idle callback request is postponed by 5000ms, a value which can be adjusted via a filter:
add_filter( 'site_performance_tracker_web_vitals_delay', function() {
return 1000;
} );
All contributions are welcome! Please create an issue for bugs and feature requests, and use pull requests for code contributions.
-
We use
wp-env
for local development environment. See all theenv:*
scripts inpackage.json
for supported commands and helpers. -
webpack.config.js
configures how@wordpress/scripts
transforms JS and CSS assets during packaging. -
We use the
@wordpress/eslint-plugin/recommended-with-formatting
ruleset for JS linting since the Prettier integration is currently unreliable in@wordpress/scripts
.
- Add tracking support for Google Tag Manager setup GA4 with window.dataLayer.
- Fix bug in INP reporting when some attributions were empty.
- Deprecated GA3 support.
- Used attribution build of web vitals.
- Improved admin interface for GA4.
- Bumped up build process to use Node 16.
- Updated GA4 Settings.
- Added WP-Rocket exclusion to web-vitals-analytics.
- Cleaned up/refactored settings code.
- Added INP metric.
- Support for smaller web vitals ratio.
- Clean up settings code.
- Fix GA delivery bug.
- Fix GA not tracking bug when using the UI.
- Adding TTFB.
- Improve performance by loading and executing the script in quiter periods.
- Make chunk hash a part of the output filename.
- Fix UI to prefill configured data.
- Fix duplicated page view when using gtag.
- Fix duplicitous page views when using gtag.
- Fix PHP notices.
- Introduces an UI in WordPress Admin for easier configuration. If any config parameters are set in the theme files, the UI will not allow changing those parameters.
- Update docs to start the "Usage" section with the required configuration for the plugin to do anything.
- Switch to basic PHP includes for loading the PHP files instead of Composer autoload.
- Introduce helper methods for working with asset paths and URLs.
- Introduce VIP Go coding standards.
- Introduce PHP unit testing.
- Fix
configureGtag
call
- Update web vitals JS library to 2.0.1
- Remove Performance Observer functionality
- Code cleanup
- Add support for Google Analytics 4.
- Fix Google Analytics support.
- Code cleanup - remove unused metric and dimension.
- Feature: Add support for sending data in the web vitals report format.
- Feature: Add support to Analytics added through Google Tag Managere.
- Feature: Track 'first-delay' of over 100ms.
- Make autoload.php optional to support project-wide autoload.
- Add an action
xwp/performance_tracker/render_mark
as an alternative way for adding performance marks in the front-end. - Bugfix: Use proper JS escaping (as per WordPress VIP review).
- The plugin is no longer using a singleton pattern. Instead it is just a regular class that is being instantiated in the main plugin file.
- Namespace has been added.
- The PHP version check has been added (>= 5.3).
- The helper functions are extracted to a separate file and they are now using static functions inside the class.
- The
$default_entry_types
array is no longer defined as static.
- Initial release.
Please follow the contribution guide.
Created by XWP and contributors. Licensed under GNU General Public License v2.0 or later.