diff --git a/src/Filters.php b/src/Filters.php index 8255123..ac79eb2 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -51,8 +51,11 @@ public function add_plausible_attributes( $tag, $handle ) { $api_url = Helpers::get_data_api_url(); $domain_name = Helpers::get_domain(); - // We need the correct id attribute for IE compatibility. - $tag = preg_replace( "/\sid=(['\"])plausible-analytics-js(['\"])/", " id=$1plausible$2", $tag ); + if ( Helpers::is_enhanced_measurement_enabled( 'compat' ) ) { + // We need the correct id attribute for IE compatibility. + $tag = preg_replace( "/\sid=(['\"])plausible-analytics-js(['\"])/", " id=$1plausible$2", $tag ); + } + /** * 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/ */ diff --git a/tests/TestCase.php b/tests/TestCase.php index 084027d..83cf3c2 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -36,6 +36,19 @@ public function enableRevenue( $settings ) { return $settings; } + /** + * Enable Enhanced Measurements > IE Compatibility + * + * @param $settings + * + * @return mixed + */ + public function enableCompat( $settings ) { + $settings[ 'enhanced_measurements' ] = [ 'compat' ]; + + return $settings; + } + /** * Enable form completions by modifying the settings array. * diff --git a/tests/integration/FiltersTest.php b/tests/integration/FiltersTest.php index ac99f5c..e448126 100644 --- a/tests/integration/FiltersTest.php +++ b/tests/integration/FiltersTest.php @@ -18,6 +18,15 @@ public function testAddPlausibleAttributes() { $this->assertStringContainsString( 'example.org', $tag ); $this->assertStringContainsString( 'plausible.io/api/event', $tag ); + $this->assertStringContainsString( 'plausible-analytics-js', $tag ); + + add_filter( 'plausible_analytics_settings', [ $this, 'enableCompat' ] ); + + $class = new Filters(); + $tag = $class->add_plausible_attributes( '