Update tracker script.

This commit is contained in:
Mike Cao 2021-02-01 22:49:00 -08:00
parent 44d1704b21
commit b1d8a58e22

View File

@ -133,11 +133,10 @@ import { removeTrailingSlash } from '../lib/url';
/* Handle history changes */ /* Handle history changes */
const handlePush = (state, title, url) => { const handlePush = (state, title, url) => {
if (!url) return;
removeEvents(); removeEvents();
// url is not guaranteed
// thus calling `url.toString()` might causes exception, then break the pjax update
// track only if url is validate
if (url) {
currentRef = currentUrl; currentRef = currentUrl;
const newUrl = url.toString(); const newUrl = url.toString();
@ -146,13 +145,12 @@ import { removeTrailingSlash } from '../lib/url';
} else { } else {
currentUrl = newUrl; currentUrl = newUrl;
} }
// this function under some framework might be called multiple times
// thus only track if currentUrl and currentRef are not same
if (currentUrl !== currentRef) { if (currentUrl !== currentRef) {
trackView(currentUrl, currentRef); trackView(currentUrl, currentRef);
}
setTimeout(addEvents, 300); setTimeout(addEvents, 300);
}
}
}; };
/* Global */ /* Global */