diff --git a/readme.txt b/readme.txt index c5b2d594..a44374c8 100644 --- a/readme.txt +++ b/readme.txt @@ -278,6 +278,9 @@ Please make sure you make a backup of your database before updating any version == Changelog == += 2.6.3 = +* Improved: the tracker script now loads asynchronously (like Plausible Analytics' own snippet) instead of deferred, so it can no longer hold up the rest of the page when it can't be reached. + = 2.6.2 = * *Important!* This release rebuilds the WooCommerce (and EDD) purchase funnel for sites using WPML with a translated product base. If you built your own funnels using the same goals, please rebuild them after installing this update. * Added: TranslatePress "different domain per language" (Multiple Domains) compatibility. Each language domain can be mapped to its own Plausible Analytics dashboard, just like WPML. diff --git a/src/Compatibility.php b/src/Compatibility.php index 5fa66217..ff761c76 100644 --- a/src/Compatibility.php +++ b/src/Compatibility.php @@ -113,9 +113,15 @@ public function exclude_from_cloudflare_rocket_loader( $tag, $handle ) { } /** + * async (like Plausible Analytics' own snippet) instead of defer: a deferred script holds up DOMContentLoaded + * until it has loaded, so a script that can't be reached (e.g. a proxied script on a server that's gone offline) + * stalls everything waiting for that event. The tracker handles loading before or after plausible.init(). + * * the data-cfasync ensures this script isn't processed by CF Rocket Loader @see https://developers.cloudflare.com/speed/optimization/content/rocket-loader/ignore-javascripts/ + * + * @since 2.6.3 async instead of defer. */ - $params = "defer data-cfasync='false'"; + $params = "async data-cfasync='false'"; $params = apply_filters( 'plausible_analytics_script_params', $params ); return str_replace( ' src', " {$params} src", $tag ); diff --git a/tests/integration/CompatibilityTest.php b/tests/integration/CompatibilityTest.php new file mode 100644 index 00000000..2e69e04f --- /dev/null +++ b/tests/integration/CompatibilityTest.php @@ -0,0 +1,28 @@ +exclude_from_cloudflare_rocket_loader( + '', + 'plausible-analytics' + ); + + $this->assertStringContainsString( " async data-cfasync='false'", $tag ); + $this->assertStringNotContainsString( 'defer', $tag ); + } +}