Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4542 - Fix 404 Tracking #226

Merged
merged 4 commits into from
Sep 25, 2024
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
7 changes: 6 additions & 1 deletion src/Actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ); });"
Expand Down
2 changes: 1 addition & 1 deletion src/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -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}\"";
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion tests/integration/Integrations/WooCommerceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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 );
}
Expand Down