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

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

Open
eferroni opened this issue Oct 16, 2023 · 0 comments
Open
Labels
bug Something isn't working

Comments

@eferroni
Copy link

eferroni commented Oct 16, 2023

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
    } 
@eferroni eferroni added the bug Something isn't working label Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant