Skip to content

Commit

Permalink
Merge pull request #20 from xwp/feature/032
Browse files Browse the repository at this point in the history
0.3.2 - Fix for non GTM users
  • Loading branch information
mehigh authored Mar 16, 2020
2 parents d595ba0 + 94ea146 commit 4405610
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions php/Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,11 @@ public function inject_performance_observer() {
window.sitePerformanceObserver = <?php echo wp_json_encode( $options ); ?>;
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 ),
Expand All @@ -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 ) {
Expand Down
2 changes: 1 addition & 1 deletion site-performance-tracker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down

0 comments on commit 4405610

Please sign in to comment.