diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 70880acb..4337a1a8 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -91,3 +91,4 @@ jobs: with: token: ${{ secrets.CODECOV_TOKEN }} slug: plausible/wordpress + continue-on-error: true diff --git a/src/Assets.php b/src/Assets.php index 8741f837..81e5a17f 100644 --- a/src/Assets.php +++ b/src/Assets.php @@ -40,6 +40,7 @@ public function maybe_enqueue_cloaked_affiliate_links_assets() { PLAUSIBLE_ANALYTICS_PLUGIN_URL . 'assets/dist/js/plausible-affiliate-links.js', [ 'plausible-analytics' ], filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-affiliate-links.js' ), + [ 'in_footer' => true ], ); $affiliate_links = Helpers::get_settings()['affiliate_links'] ?? []; diff --git a/src/Integrations/FormSubmit.php b/src/Integrations/FormSubmit.php index d7e46d5f..534a2cd7 100644 --- a/src/Integrations/FormSubmit.php +++ b/src/Integrations/FormSubmit.php @@ -58,7 +58,8 @@ public function add_js() { 'plausible-form-submit-integration', PLAUSIBLE_ANALYTICS_PLUGIN_URL . 'assets/dist/js/plausible-form-submit-integration.js', [ 'plausible-analytics' ], - filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-form-submit-integration.js' ) + filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-form-submit-integration.js' ), + [ 'in_footer' => true ], ); wp_localize_script( diff --git a/src/Integrations/WooCommerce.php b/src/Integrations/WooCommerce.php index e20c408c..02627b09 100644 --- a/src/Integrations/WooCommerce.php +++ b/src/Integrations/WooCommerce.php @@ -117,7 +117,8 @@ public function add_js() { 'plausible-woocommerce-integration', PLAUSIBLE_ANALYTICS_PLUGIN_URL . 'assets/dist/js/plausible-woocommerce-integration.js', [], - filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-woocommerce-integration.js' ) + filemtime( PLAUSIBLE_ANALYTICS_PLUGIN_DIR . 'assets/dist/js/plausible-woocommerce-integration.js' ), + [ 'in_footer' => true ], ); } diff --git a/tests/integration/AssetsTest.php b/tests/integration/AssetsTest.php index 5efd16fe..32944fa5 100644 --- a/tests/integration/AssetsTest.php +++ b/tests/integration/AssetsTest.php @@ -10,13 +10,13 @@ class AssetsTest extends TestCase { /** + * @see Assets::maybe_enqueue_cloaked_affiliate_links_assets() * @return void * @throws \Exception - * @see Assets::maybe_enqueue_main_script() */ - public function testEnqueueMainScript() { + public function testEnqueueCloakedAffiliateLinksScript() { try { - add_filter( 'plausible_analytics_settings', [ $this, 'enableAdministratorTracking' ] ); + add_filter( 'plausible_analytics_settings', [ $this, 'enableCloakedAffiliateLinks' ] ); $class = $this->getMockBuilder( Assets::class ) ->disableOriginalConstructor() @@ -29,94 +29,94 @@ public function testEnqueueMainScript() { $class->method( 'get_js_url' ) ->willReturn( 'https://plausible.test/js/plausible.js' ); - wp_set_current_user( 1 ); - $user = wp_get_current_user(); - $user->add_role( 'administrator' ); + ob_start(); $class->maybe_enqueue_main_script(); + $class->maybe_enqueue_cloaked_affiliate_links_assets(); - global $wp_scripts; - $data = $wp_scripts->get_data( 'plausible-analytics', 'after' ); + do_action( 'wp_footer' ); - $this->assertStringContainsString( 'window.plausible', implode( '', $data ) ); - $this->assertStringContainsString( 'plausible.init', implode( '', $data ) ); + $output = ob_get_clean(); + + $this->assertStringContainsString( 'plausible-affiliate-links.js', $output ); + $this->assertStringContainsString( 'const plausibleAffiliateLinks', $output ); } finally { - remove_filter( 'plausible_analytics_settings', [ $this, 'enableAdministratorTracking' ] ); - wp_set_current_user( null ); + remove_filter( 'plausible_analytics_settings', [ $this, 'enableCloakedAffiliateLinks' ] ); } } /** + * @see Assets::maybe_enqueue_four_o_four_script() * @return void * @throws \Exception - * @see Assets::maybe_enqueue_cloaked_affiliate_links_assets() */ - public function testEnqueueCloakedAffiliateLinksScript() { + public function testEnqueueFourOFourScript() { try { - add_filter( 'plausible_analytics_settings', [ $this, 'enableCloakedAffiliateLinks' ] ); + add_filter( 'plausible_analytics_settings', [ $this, 'enableFourOFour' ] ); + add_filter( 'plausible_analytics_is_404', '__return_true' ); $class = $this->getMockBuilder( Assets::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'get_js_url' ] ) ->getMock(); - $this->removeAction( 'wp_enqueue_scripts', 'maybe_enqueue' ); - $this->removeAction( 'wp_enqueue_scripts', 'maybe_enqueue', 11 ); - $class->method( 'get_js_url' ) ->willReturn( 'https://plausible.test/js/plausible.js' ); - ob_start(); - $class->maybe_enqueue_main_script(); - $class->maybe_enqueue_cloaked_affiliate_links_assets(); - - do_action( 'wp_head' ); + $class->maybe_enqueue_four_o_four_script(); - $output = ob_get_clean(); + global $wp_scripts; - $this->assertStringContainsString( 'plausible-affiliate-links.js', $output ); - $this->assertStringContainsString( 'const plausibleAffiliateLinks', $output ); + $this->assertArrayHasKey( 'plausible-analytics', $wp_scripts->registered ); + $this->assertTrue( $this->arrayHasString( '404', $wp_scripts->registered['plausible-analytics']->extra['after'] ) ); } finally { - remove_filter( 'plausible_analytics_settings', [ $this, 'enableCloakedAffiliateLinks' ] ); + remove_filter( 'plausible_analytics_settings', [ $this, 'enableFourOFour' ] ); + remove_filter( 'plausible_analytics_is_404', '__return_true' ); } } /** + * @see Assets::maybe_enqueue_main_script() * @return void * @throws \Exception - * @see Assets::maybe_enqueue_four_o_four_script() */ - public function testEnqueueFourOFourScript() { + public function testEnqueueMainScript() { try { - add_filter( 'plausible_analytics_settings', [ $this, 'enableFourOFour' ] ); - add_filter( 'plausible_analytics_is_404', '__return_true' ); + add_filter( 'plausible_analytics_settings', [ $this, 'enableAdministratorTracking' ] ); $class = $this->getMockBuilder( Assets::class ) ->disableOriginalConstructor() ->onlyMethods( [ 'get_js_url' ] ) ->getMock(); + $this->removeAction( 'wp_enqueue_scripts', 'maybe_enqueue' ); + $this->removeAction( 'wp_enqueue_scripts', 'maybe_enqueue', 11 ); + $class->method( 'get_js_url' ) ->willReturn( 'https://plausible.test/js/plausible.js' ); + wp_set_current_user( 1 ); + $user = wp_get_current_user(); + $user->add_role( 'administrator' ); + $class->maybe_enqueue_main_script(); - $class->maybe_enqueue_four_o_four_script(); global $wp_scripts; + $data = $wp_scripts->get_data( 'plausible-analytics', 'after' ); - $this->assertArrayHasKey( 'plausible-analytics', $wp_scripts->registered ); - $this->assertTrue( $this->arrayHasString( '404', $wp_scripts->registered['plausible-analytics']->extra['after'] ) ); + $this->assertStringContainsString( 'window.plausible', implode( '', $data ) ); + $this->assertStringContainsString( 'plausible.init', implode( '', $data ) ); } finally { - remove_filter( 'plausible_analytics_settings', [ $this, 'enableFourOFour' ] ); - remove_filter( 'plausible_analytics_is_404', '__return_true' ); + remove_filter( 'plausible_analytics_settings', [ $this, 'enableAdministratorTracking' ] ); + wp_set_current_user( null ); } } /** + * @see Assets::maybe_enqueue_query_params_script() * @return void * @throws \Exception - * @see Assets::maybe_enqueue_query_params_script() */ public function testEnqueueQueryParamsScript() { try { @@ -146,9 +146,9 @@ public function testEnqueueQueryParamsScript() { } /** + * @see Assets::maybe_enqueue_search_queries_script() * @return void * @throws \Exception - * @see Assets::maybe_enqueue_search_queries_script() */ public function testEnqueueSearchQueriesScript() { try {