Skip to content

Comments

Plausible SPA compatibility#5830

Open
evnchn wants to merge 3 commits intozauberzeug:mainfrom
evnchn:plausible-spa-compat
Open

Plausible SPA compatibility#5830
evnchn wants to merge 3 commits intozauberzeug:mainfrom
evnchn:plausible-spa-compat

Conversation

@evnchn
Copy link
Collaborator

@evnchn evnchn commented Feb 22, 2026

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
Copy link
Collaborator Author

evnchn commented Feb 22, 2026

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

Copy link
Member

@rodja rodja left a comment

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
Copy link
Collaborator Author

evnchn commented Feb 22, 2026

@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

Copy link
Member

@rodja rodja left a comment

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
Copy link
Collaborator Author

evnchn commented Feb 22, 2026

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.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants