Skip to content

Plausible SPA compatibility - #5830

Merged
falkoschindler merged 3 commits into
zauberzeug:mainfrom
evnchn:plausible-spa-compat
Feb 23, 2026
Merged

Plausible SPA compatibility#5830
falkoschindler merged 3 commits into
zauberzeug:mainfrom
evnchn:plausible-spa-compat

Conversation

@evnchn

@evnchn evnchn commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator

Motivation

image

NiceGUI's SPA is totally not known to Plausible, as such the analytics is quite messed up.

Implementation

This pull request updates the Plausible analytics script to a newer version that automatically handles Single-Page Application (SPA) tracking.

Progress

  • I chose a meaningful title that completes the sentence: "If applied, this PR will..."
  • The implementation is complete.
  • If this PR addresses a security issue, it has been coordinated via the security advisory process.
  • Pytests have been added (or are not necessary).
  • Documentation has been added (or is not necessary).

@evnchn
evnchn requested a review from rodja February 22, 2026 06:13
@evnchn evnchn added the documentation Type/scope: Documentation, examples and website label Feb 22, 2026
@evnchn

evnchn commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator Author

9c596dc is tested by using {captureOnLocalhost: true} in plausible.init

I can verify that the pageview event is emitted without the SPA on_path_changed change on localhost.

async, the HTML comment, and the missing semicolon in plausible.init() is all came from the below:

image

@rodja rodja left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for digging into this @evnchn. Just two things I noticed:

  • non-sub-page hashes are not tracked anymore (for example there are no events fired to plausible if you go to documentation/markdown and then use the side bar to navigate to different demos)
  • description of the PR still says "Added a handler... " which is not in the code

@evnchn

evnchn commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator Author

@rodja as mentioned privately, I do not think we should track the hash when our page isn't doing hash based routing.

As a reminder, hash-based routing is intended for websites which use /#pages/mypage to serve distinct and click-navigated pages. NiceGUI is not that. Sections appear on the same page and is use scroll to navigate among them.

Since we use the hash for sections inside a page, insist on tracking the hash with Plausible assuming hash-based routing has several disadvantages:

  • The visits for the different hashes are separated with no way to aggregate them on the dashboard.
  • It is a flawed metric anyways, since it only captures sidebar clicks, not when the users scrolls into it.

A real solution would be to use custom events to track if the particular hash's content appeared on screen.

Nevertheless, if you prefer following old behaviour, you may change to

plausible.init({
  hashBasedRouting: true
})

I intend to change the PR description when I am back home. done with AI while not at home

@rodja rodja left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right about the hash tracking. Maybe we will do your suggested "real solution" with custom events to track if the particular hash's content appeared on screen at some point. But this PR is good to go from my side.

@rodja
rodja requested a review from falkoschindler February 22, 2026 13:02
@evnchn

evnchn commented Feb 22, 2026

Copy link
Copy Markdown
Collaborator Author

When this is merged, I intend to export all data off Plausible, then reset site data, modify it to unify all hash based paths, and re-load the modified data. We are rewriting the history as if hash-based navigation logging was never enabled on day 1.

@falkoschindler falkoschindler added the review Status: PR is open and needs review label Feb 23, 2026
@falkoschindler
falkoschindler added this pull request to the merge queue Feb 23, 2026
@falkoschindler falkoschindler added this to the 3.8 milestone Feb 23, 2026
Merged via the queue into zauberzeug:main with commit cc50d24 Feb 23, 2026
7 checks passed
@evnchn
evnchn deleted the plausible-spa-compat branch February 23, 2026 11:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Type/scope: Documentation, examples and website review Status: PR is open and needs review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants