Trigger pageviews on pages loaded from bfcache (#4656)

* trigger pageview on pageshow with event.persisted

* update _tracking.html to do the same
This commit is contained in:
RobertJoonas
2024-10-08 11:11:03 +02:00
committed by GitHub
parent 2359cb920c
commit 799edec81c
2 changed files with 16 additions and 0 deletions

View File

@ -32,6 +32,13 @@
}
plausible('pageview', defaultEventOptions)
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
// Page was restored from bfcache - trigger a pageview
plausible('pageview', defaultEventOptions);
}
})
</script>
<% end %>
<% end %>

View File

@ -231,6 +231,15 @@
} else {
page()
}
{{#if pageleave}}
window.addEventListener('pageshow', function(event) {
if (event.persisted) {
// Page was restored from bfcache - trigger a pageview
page();
}
})
{{/if}}
{{/unless}}
{{#if (any outbound_links file_downloads tagged_events)}}