Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 7 additions & 1 deletion src/Compatibility.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down
28 changes: 28 additions & 0 deletions tests/integration/CompatibilityTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php
/**
* @package Plausible Analytics Integration Tests - Compatibility
*/

namespace Plausible\Analytics\Tests\Integration;

use Plausible\Analytics\Tests\TestCase;
use Plausible\Analytics\WP\Compatibility;

class CompatibilityTest extends TestCase {
/**
* The tracker script should load async, so a script that can't be reached doesn't hold up DOMContentLoaded (like a
* deferred script does), and be excluded from Cloudflare's Rocket Loader.
*
* @see Compatibility::exclude_from_cloudflare_rocket_loader()
* @return void
*/
public function testTrackerScriptLoadsAsync() {
$tag = ( new Compatibility() )->exclude_from_cloudflare_rocket_loader(
'<script src="https://example.org/js/pa-test.js" id="plausible-analytics-js"></script>',
'plausible-analytics'
);

$this->assertStringContainsString( " async data-cfasync='false'", $tag );
$this->assertStringNotContainsString( 'defer', $tag );
}
}
Loading