<?php /** * Plugin Name: ETH Web Vitals * Plugin URI: https://ethitter.com * Description: Record performance metrics in analytics platforms. * Version: 1.0 * License: GPLv2 * Author: Erick Hitter */ namespace ETH\Web_Vitals; define( 'ETH\\Web_Vitals\\PLUGIN_PATH', plugin_dir_path( __FILE__ ) ); /** * Output the Web Vitals script. */ function render(): void { $data = [ 'config' => [ 'eventCategory' => 'Web Vitals', ], 'queue' => [], ]; ?> <script> window.ethWebVitals = window.ethWebVitals || {}; window.ethWebVitals = <?php echo wp_json_encode( $data ); ?>; <?php echo file_get_contents( PLUGIN_PATH . 'assets/build/web-vitals.js' ); ?> </script> <?php } add_action( 'wp_head', __NAMESPACE__ . '\render', 0 );