Skip to content

Commit

Permalink
Merge pull request #226 from plausible/fix_404_tracking
Browse files Browse the repository at this point in the history
Fix #4542 - Fix 404 Tracking
  • Loading branch information
Dan0sz authored Sep 25, 2024
2 parents ff82abc + 87dd51f commit 2b73e33
Showing 1 changed file with 6 additions and 1 deletion.
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

0 comments on commit 2b73e33

Please sign in to comment.