Skip to content
This repository was archived by the owner on Aug 12, 2025. It is now read-only.

Pageviews is duplicated when using hashMode and browser back button #58

@eferroni

Description

@eferroni

I'm using the hashMode property as true and the enableAutoPageviews method to start plausible tracker in my index.tsx file.
It's working as expect when I navigate between pages with hashes, except when I use the browser back button.
When I use the browser back button, plausible tracker is tracking the destination page twice.
Example: from /test#tab to /test
Probably because of:

    const page = () => trackPageview();
    // Attach pushState and popState listeners
    const originalPushState = history.pushState;
    if (originalPushState) {
      // eslint-disable-next-line functional/immutable-data
      history.pushState = function (data, title, url) {
        originalPushState.apply(this, [data, title, url]);
        page();
      };
      addEventListener('popstate', page); // track the browser back behavior
    }

    // Attach hashchange listener
    if (defaults && defaults.hashMode) {
      addEventListener('hashchange', page); // track when the hash changes from #tab to no hash fragment
    } 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions