Open cosminstefanxp opened 2 years ago
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?
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');
}
}
}
Versions
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:
history.replaceState()
;