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

Page views not tracked when using History's replaceState #18

Open
cosminstefanxp opened this issue Oct 14, 2021 · 2 comments
Open

Page views not tracked when using History's replaceState #18

cosminstefanxp opened this issue Oct 14, 2021 · 2 comments
Labels
bug Something isn't working

Comments

@cosminstefanxp
Copy link

Versions

  • 0.3.1

Describe the bug

When using a router that makes use of History.replaceState, the page views are tracked. E.g. using Vue Router, such as $router.replace("/"), the mutation is not tracked.

Expected behavior

When replacing state, the page view should be tracked.

Steps to reproduce

Steps:

  1. Install normally
  2. Set it up
  3. User history.replaceState();
@cosminstefanxp cosminstefanxp added the bug Something isn't working label Oct 14, 2021
@cosminstefanxp
Copy link
Author

The solution should be relatively easy: override the implementation for replaceState() similar to how it's done for pushState. @Maronato, am I missing something? Is there any reason why it wasn't done in the first place?

@bfritscher
Copy link

Hi,
Is there a design reason which makes it not desired to track replaceState?
Would a pull request be accepted? Does it have to be behind a flag?

Here a proof of concept custom code to workaround

const originalReplaceState = window.history.replaceState;
if (originalReplaceState) {
    window.history.replaceState = function (data, title, url) {
        originalReplaceState.apply(this, [data, title, url]);
        if (window.plausible) {
            window.plausible('pageview');
        }
    }
}

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

2 participants