Skip to content

armgit / umami

Public Imported from GitHub
0

Umami is a privacy-first web and product analytics platform. Traffic, campaigns, behavior, conversions, and revenue in one place. No cookies, no surveillance, self-hosted or in the cloud.

fix pjax, tested on my website

天空Blond7d3bc66a503e
diff --git a/tracker/index.js b/tracker/index.js
index fc8458b00..8f58fae3d 100644
--- a/tracker/index.js
+++ b/tracker/index.js
@@ -134,19 +134,25 @@ import { removeTrailingSlash } from '../lib/url';
const handlePush = (state, title, url) => {
removeEvents();
-
- currentRef = currentUrl;
- const newUrl = url.toString();
-
- if (newUrl.substring(0, 4) === 'http') {
- currentUrl = '/' + newUrl.split('/').splice(3).join('/');
- } else {
- currentUrl = newUrl;
+ // 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;
+ const newUrl = url.toString();
+
+ if (newUrl.substring(0, 4) === 'http') {
+ currentUrl = '/' + newUrl.split('/').splice(3).join('/');
+ } else {
+ 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) {
+ trackView(currentUrl, currentRef);
+ setTimeout(addEvents, 300);
+ }
}
-
- trackView(currentUrl, currentRef);
-
- setTimeout(addEvents, 300);
};
/* Global */