diff --git a/src/Actions.php b/src/Actions.php index 29918a77..e7ab70e6 100644 --- a/src/Actions.php +++ b/src/Actions.php @@ -71,11 +71,16 @@ public function maybe_register_assets() { $data = wp_json_encode( [ 'props' => [ - 'path' => 'documentation.location.pathname', + 'path' => 'document.location.pathname', ], ] ); + /** + * Documentation.location.pathname is a variable. @see wp_json_encode() doesn't allow passing variable, only strings. This fixes that. + */ + $data = str_replace( '"document.location.pathname"', 'document.location.pathname', $data ); + wp_add_inline_script( 'plausible-analytics', "document.addEventListener('DOMContentLoaded', function () { plausible( '404', $data ); });" diff --git a/src/Filters.php b/src/Filters.php index 213cc0d9..8255123e 100644 --- a/src/Filters.php +++ b/src/Filters.php @@ -112,7 +112,7 @@ public function maybe_add_custom_params( $params ) { // Loop through the terms. foreach ( $terms as $term ) { if ( $term instanceof WP_Term ) { - $params .= " event-{$taxonomy}='{$term->name}'"; + $params .= " event-{$taxonomy}=\"{$term->name}\""; } } } diff --git a/tests/integration/Integrations/WooCommerceTest.php b/tests/integration/Integrations/WooCommerceTest.php index 37e97985..b7c3ca70 100644 --- a/tests/integration/Integrations/WooCommerceTest.php +++ b/tests/integration/Integrations/WooCommerceTest.php @@ -5,10 +5,12 @@ namespace Plausible\Analytics\Tests\Integration; +use AllowDynamicProperties; use Plausible\Analytics\Tests\TestCase; use Plausible\Analytics\WP\Integrations\WooCommerce; use function Brain\Monkey\Functions\when; +#[AllowDynamicProperties] class WooCommerceTest extends TestCase { /** * @see WooCommerce::track_entered_checkout() @@ -63,7 +65,7 @@ public function testTrackPurchase() { when( 'wc_get_order' )->justReturn( $mock ); - $this->expectOutputContains( '{"revenue":{"amount":"10.00","currency":"EUR"}}' ); + $this->expectOutputContains( '{"revenue":{"amount":"10","currency":"EUR"}}' ); $class->track_purchase( 1 ); }