diff --git a/php/Plugin.php b/php/Plugin.php index daad882..b39de73 100644 --- a/php/Plugin.php +++ b/php/Plugin.php @@ -99,8 +99,11 @@ public function inject_performance_observer() { window.sitePerformanceObserver = ; window.sitePerformanceObserver.send = function( name, startTime, duration ) { if ( 'undefined' !== typeof( window.ga ) ) { - var trackerName = window.ga.getAll()[0].get('name'); - window.ga(trackerName + '.send', 'event', { + var trackerName = ''; + if ( 'undefined' !== typeof( window.ga.getAll ) ) { + trackerName = window.ga.getAll()[0].get('name') + '.'; + } + window.ga(trackerName + 'send', 'event', { eventCategory: window.sitePerformanceObserver.categoryName, eventAction: name, eventValue: Math.round( startTime + duration ), @@ -113,7 +116,9 @@ public function inject_performance_observer() { if ( 'first-input' === entry.entryType ) { const fid = entry.processingStart - entry.startTime; if ( fid > 100 ) { - // Only track first-input delay of over 100ms. + // Only track first-input delay of over 100ms: + // https://developers.google.com/web/fundamentals/performance/rail#ux + // > 100ms Users experience perceptible delay. window.sitePerformanceObserver.send( entry.entryType, entry.startTime, fid ); } } else if ( 'navigation' === entry.entryType ) { diff --git a/site-performance-tracker.php b/site-performance-tracker.php index 002217c..4972f8d 100644 --- a/site-performance-tracker.php +++ b/site-performance-tracker.php @@ -8,7 +8,7 @@ * Plugin Name: Site Performance Tracker * Plugin URI: https://github.com/xwp/site-performance-tracker * Description: Allows you to detect and track site performance metrics. - * Version: 0.3.1 + * Version: 0.3.2 * Author: XWP.co * Author URI: https://xwp.co */