From eb73f22bfc6ff5393a3c6bc70b3d9b523acbc02c Mon Sep 17 00:00:00 2001 From: Mike Crantea Date: Wed, 14 Apr 2021 12:16:53 +0100 Subject: [PATCH] WebVitals: Remove dataset, make solution more flexible --- php/Plugin.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/php/Plugin.php b/php/Plugin.php index b71160d..4015a3c 100644 --- a/php/Plugin.php +++ b/php/Plugin.php @@ -257,8 +257,9 @@ public function enqueue_scripts() { var randNumber = Math.random(); if ( randNumber <= window.webVitalsAnalyticsData.chance ) { requestIdleCallback( function() { - webVitalsAnalyticsScript = document.getElementById( 'web-vitals-analytics-js' ); + webVitalsAnalyticsScript = document.querySelector( 'script[data-src*=\"web-vitals-analytics.js\"]' ); webVitalsAnalyticsScript.src = webVitalsAnalyticsScript.dataset.src; + delete webVitalsAnalyticsScript.dataset.src; } ); } }