mirror of
https://github.com/gohugoio/hugo.git
synced 2026-08-24 15:28:54 +00:00
theme: Move tracking to turbo:load
This commit is contained in:
+6
-4
@@ -48,6 +48,7 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {};
|
||||
|
||||
{
|
||||
let containerScrollTops = {};
|
||||
let turboLoaded = false;
|
||||
|
||||
// To preserve scroll position in scrolling elements on navigation add data-turbo-preserve-scroll-container="somename" to the scrolling container.
|
||||
addEventListener('turbo:click', () => {
|
||||
@@ -56,14 +57,15 @@ var debug = 0 ? console.log.bind(console, '[index]') : function () {};
|
||||
});
|
||||
});
|
||||
|
||||
addEventListener('turbo:render', () => {
|
||||
if (document.documentElement.hasAttribute('data-turbo-preview')) {
|
||||
addEventListener('turbo:load', () => {
|
||||
if (turboLoaded) {
|
||||
// Minimal Analytics does not support SPA out of the box, so we need to manually track page views on Turbo navigation.
|
||||
// Render may be called twice, once for preview and once for the real render.
|
||||
// Track only on the real render.
|
||||
window.track('page_view');
|
||||
}
|
||||
turboLoaded = true;
|
||||
});
|
||||
|
||||
addEventListener('turbo:render', () => {
|
||||
document.querySelectorAll('[data-turbo-preserve-scroll-container]').forEach((ele) => {
|
||||
const containerScrollTop = containerScrollTops[ele.dataset.turboPreserveScrollContainer];
|
||||
if (containerScrollTop) {
|
||||
|
||||
Reference in New Issue
Block a user