From b0317d1bb1905473bcfd8c44321e794331e5bfbc Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 19:57:16 +0800 Subject: [PATCH 1/8] Update tracker.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 修改上报路径 --- public/tracker.js | 149 +++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 75 deletions(-) diff --git a/public/tracker.js b/public/tracker.js index 1bc1c32..3530655 100644 --- a/public/tracker.js +++ b/public/tracker.js @@ -1,81 +1,80 @@ ((window) => { - const { location, document, navigator } = window; - const { hostname: host, pathname } = location; - const { currentScript, referrer } = document; - const currentRef = !referrer.includes(host) ? referrer : ""; - if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; - const attr = currentScript.getAttribute.bind(currentScript); - const website = attr("data-website-id"); - const sendURL = new URL(currentScript.src).origin + "/send"; - let visitor = true; - let visit = true; - // 访问间隔 (分钟) - const AccessInterval = 30; - // 页面访问 - let PathVisit = {}; - try { - PathVisit = JSON.parse(localStorage.getItem("_vhLastVisit")) || {}; - if (typeof PathVisit != "object") PathVisit = {}; - } catch (error) { - localStorage.removeItem("_vhLastVisit"); - } - const vhLastVisit = PathVisit[pathname] || 0; - // 访客访问 - const vhLastVisitor = localStorage.getItem("_vhLastVisitor") || 0; - // 是否是今天缓存 - const nowVisitDate = new Date(); - const vhLastVisitorDate = new Date(Number(vhLastVisitor)); - const vhLastVisitDate = new Date(Number(vhLastVisit)); - // 访客访问 - if (nowVisitDate.getFullYear() === vhLastVisitorDate.getFullYear() && nowVisitDate.getMonth() === vhLastVisitorDate.getMonth() && nowVisitDate.getDate() === vhLastVisitorDate.getDate()) { - // 今天缓存即老用户 - visitor = false; - } else { - // 否则更新缓存时间 - localStorage.setItem("_vhLastVisitor", Date.now()); - } - // 访问次数访问 - if (Date.now() - vhLastVisitDate.getTime() < AccessInterval * 60 * 1000) { - // 超过访问间隔即老访客 - visit = false; - } else { - // 否则更新缓存时间 - PathVisit[pathname] = Date.now(); - localStorage.setItem("_vhLastVisit", JSON.stringify(PathVisit)); - } - - // URL转码 - const encode = (str) => { - if (!str) return ""; + const { location, document, navigator } = window; + const { search } = location; + const { currentScript, referrer } = document; + const currentRef = !referrer.includes(location.host) ? referrer : ""; + if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; + const attr = currentScript.getAttribute.bind(currentScript); + const website = attr("data-website-id"); + const sendURL = new URL(currentScript.src).origin + "/send"; + let visitor = true; + let visit = true; + // 访问间隔 (分钟) + const AccessInterval = 30; + // 页面访问 + let PathVisit = {}; try { - if (decodeURI(str) !== str) return decodeURI(str); - } catch (e) { - return str; + PathVisit = JSON.parse(localStorage.getItem("_vhLastVisit")) || {}; + if (typeof PathVisit != "object") PathVisit = {}; + } catch (error) { + localStorage.removeItem("_vhLastVisit"); + } + const vhLastVisit = PathVisit[location.pathname + location.search] || 0; + // 访客访问 + const vhLastVisitor = localStorage.getItem("_vhLastVisitor") || 0; + // 是否是今天缓存 + const nowVisitDate = new Date(); + const vhLastVisitorDate = new Date(Number(vhLastVisitor)); + const vhLastVisitDate = new Date(Number(vhLastVisit)); + // 访客访问 + if (nowVisitDate.getFullYear() === vhLastVisitorDate.getFullYear() && nowVisitDate.getMonth() === vhLastVisitorDate.getMonth() && nowVisitDate.getDate() === vhLastVisitorDate.getDate()) { + // 今天缓存即老用户 + visitor = false; + } else { + // 否则更新缓存时间 + localStorage.setItem("_vhLastVisitor", Date.now()); + } + // 访问次数访问 + if (Date.now() - vhLastVisitDate.getTime() < AccessInterval * 60 * 1000) { + // 超过访问间隔即老访客 + visit = false; + } else { + // 否则更新缓存时间 + PathVisit[location.pathname + location.search] = Date.now(); + localStorage.setItem("_vhLastVisit", JSON.stringify(PathVisit)); } - return encodeURI(str); - }; - // 上报 - const send = async () => { - if (!website) return; - try { - await fetch(sendURL, { - method: "POST", - body: JSON.stringify({ - website, - host, - path: encode(pathname), - referrer: encode(currentRef), - visitor, - visit - }), - headers: { - "Content-Type": "application/json" + // URL转码 + const encode = (str) => { + if (!str) return ""; + try { + if (decodeURI(str) !== str) return decodeURI(str); + } catch (e) { + return str; } - }); - } catch (e) { - /* empty */ - } - }; - send(); + return encodeURI(str); + }; + + // 上报 + const send = async () => { + if (!website) return; + try { + await fetch(sendURL, { + method: "POST", + body: JSON.stringify({ + website, + path: encode(location.pathname + location.search), + referrer: encode(currentRef), + visitor, + visit + }), + headers: { + "Content-Type": "application/json" + } + }); + } catch (e) { + /* empty */ + } + }; + send(); })(window); From f10fdcf89d7216e7b3682070e3c7ee73bd42ae19 Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:03:21 +0800 Subject: [PATCH 2/8] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/tracker.js | 1 + 1 file changed, 1 insertion(+) diff --git a/public/tracker.js b/public/tracker.js index 3530655..81d9b11 100644 --- a/public/tracker.js +++ b/public/tracker.js @@ -63,6 +63,7 @@ method: "POST", body: JSON.stringify({ website, + host, path: encode(location.pathname + location.search), referrer: encode(currentRef), visitor, From fcab8adf385a808c71b5467b36e8bad51242608b Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:07:37 +0800 Subject: [PATCH 3/8] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/tracker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/tracker.js b/public/tracker.js index 81d9b11..b2f3712 100644 --- a/public/tracker.js +++ b/public/tracker.js @@ -1,6 +1,6 @@ ((window) => { const { location, document, navigator } = window; - const { search } = location; + const { hostname: host, pathname,search} = location; const { currentScript, referrer } = document; const currentRef = !referrer.includes(location.host) ? referrer : ""; if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; From 60c65abc251203f14f9f372d153ff23a19825539 Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:10:31 +0800 Subject: [PATCH 4/8] =?UTF-8?q?=E8=B7=AF=E5=BE=84=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/tracker.js | 150 +++++++++++++++++++++++----------------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/public/tracker.js b/public/tracker.js index b2f3712..d084d00 100644 --- a/public/tracker.js +++ b/public/tracker.js @@ -1,81 +1,81 @@ ((window) => { - const { location, document, navigator } = window; - const { hostname: host, pathname,search} = location; - const { currentScript, referrer } = document; - const currentRef = !referrer.includes(location.host) ? referrer : ""; - if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; - const attr = currentScript.getAttribute.bind(currentScript); - const website = attr("data-website-id"); - const sendURL = new URL(currentScript.src).origin + "/send"; - let visitor = true; - let visit = true; - // 访问间隔 (分钟) - const AccessInterval = 30; - // 页面访问 - let PathVisit = {}; + const { location, document, navigator } = window; + const { hostname: host, pathname } = location; + const { currentScript, referrer } = document; + const currentRef = !referrer.includes(host) ? referrer : ""; + if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; + const attr = currentScript.getAttribute.bind(currentScript); + const website = attr("data-website-id"); + const sendURL = new URL(currentScript.src).origin + "/send"; + let visitor = true; + let visit = true; + // 访问间隔 (分钟) + const AccessInterval = 30; + // 页面访问 + let PathVisit = {}; + try { + PathVisit = JSON.parse(localStorage.getItem("_vhLastVisit")) || {}; + if (typeof PathVisit != "object") PathVisit = {}; + } catch (error) { + localStorage.removeItem("_vhLastVisit"); + } + const vhLastVisit = PathVisit[pathname] || 0; + // 访客访问 + const vhLastVisitor = localStorage.getItem("_vhLastVisitor") || 0; + // 是否是今天缓存 + const nowVisitDate = new Date(); + const vhLastVisitorDate = new Date(Number(vhLastVisitor)); + const vhLastVisitDate = new Date(Number(vhLastVisit)); + // 访客访问 + if (nowVisitDate.getFullYear() === vhLastVisitorDate.getFullYear() && nowVisitDate.getMonth() === vhLastVisitorDate.getMonth() && nowVisitDate.getDate() === vhLastVisitorDate.getDate()) { + // 今天缓存即老用户 + visitor = false; + } else { + // 否则更新缓存时间 + localStorage.setItem("_vhLastVisitor", Date.now()); + } + // 访问次数访问 + if (Date.now() - vhLastVisitDate.getTime() < AccessInterval * 60 * 1000) { + // 超过访问间隔即老访客 + visit = false; + } else { + // 否则更新缓存时间 + PathVisit[pathname] = Date.now(); + localStorage.setItem("_vhLastVisit", JSON.stringify(PathVisit)); + } + + // URL转码 + const encode = (str) => { + if (!str) return ""; try { - PathVisit = JSON.parse(localStorage.getItem("_vhLastVisit")) || {}; - if (typeof PathVisit != "object") PathVisit = {}; - } catch (error) { - localStorage.removeItem("_vhLastVisit"); - } - const vhLastVisit = PathVisit[location.pathname + location.search] || 0; - // 访客访问 - const vhLastVisitor = localStorage.getItem("_vhLastVisitor") || 0; - // 是否是今天缓存 - const nowVisitDate = new Date(); - const vhLastVisitorDate = new Date(Number(vhLastVisitor)); - const vhLastVisitDate = new Date(Number(vhLastVisit)); - // 访客访问 - if (nowVisitDate.getFullYear() === vhLastVisitorDate.getFullYear() && nowVisitDate.getMonth() === vhLastVisitorDate.getMonth() && nowVisitDate.getDate() === vhLastVisitorDate.getDate()) { - // 今天缓存即老用户 - visitor = false; - } else { - // 否则更新缓存时间 - localStorage.setItem("_vhLastVisitor", Date.now()); - } - // 访问次数访问 - if (Date.now() - vhLastVisitDate.getTime() < AccessInterval * 60 * 1000) { - // 超过访问间隔即老访客 - visit = false; - } else { - // 否则更新缓存时间 - PathVisit[location.pathname + location.search] = Date.now(); - localStorage.setItem("_vhLastVisit", JSON.stringify(PathVisit)); + if (decodeURI(str) !== str) return decodeURI(str); + } catch (e) { + return str; } + return encodeURI(str); + }; - // URL转码 - const encode = (str) => { - if (!str) return ""; - try { - if (decodeURI(str) !== str) return decodeURI(str); - } catch (e) { - return str; - } - return encodeURI(str); - }; - - // 上报 - const send = async () => { - if (!website) return; - try { - await fetch(sendURL, { - method: "POST", - body: JSON.stringify({ - website, - host, - path: encode(location.pathname + location.search), - referrer: encode(currentRef), - visitor, - visit - }), - headers: { - "Content-Type": "application/json" - } - }); - } catch (e) { - /* empty */ + // 上报 + const send = async () => { + if (!website) return; + try { + await fetch(sendURL, { + method: "POST", + body: JSON.stringify({ + website, + host, + path: encode(pathname + location.search), + referrer: encode(currentRef), + visitor, + visit + }), + headers: { + "Content-Type": "application/json" } - }; - send(); + }); + } catch (e) { + /* empty */ + } + }; + send(); })(window); From a4f1440dfb9d5fd1006a035d46d10d6e7e81e25e Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:19:40 +0800 Subject: [PATCH 5/8] Create tracker-all.js --- public/tracker-all.js | 81 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 public/tracker-all.js diff --git a/public/tracker-all.js b/public/tracker-all.js new file mode 100644 index 0000000..703cd89 --- /dev/null +++ b/public/tracker-all.js @@ -0,0 +1,81 @@ +((window) => { + const { location, document, navigator } = window; + const { hostname: host, pathname } = location; + const { currentScript, referrer } = document; + const currentRef = !referrer.includes(host) ? referrer : ""; + if (!currentScript || navigator.userAgent.indexOf("Electron") > 0) return; + const attr = currentScript.getAttribute.bind(currentScript); + const website = attr("data-website-id"); + const sendURL = new URL(currentScript.src).origin + "/send"; + let visitor = true; + let visit = true; + // 访问间隔 (分钟) + const AccessInterval = 30; + // 页面访问 + let PathVisit = {}; + try { + PathVisit = JSON.parse(localStorage.getItem("_vhLastVisit")) || {}; + if (typeof PathVisit != "object") PathVisit = {}; + } catch (error) { + localStorage.removeItem("_vhLastVisit"); + } + const vhLastVisit = PathVisit[pathname] || 0; + // 访客访问 + const vhLastVisitor = localStorage.getItem("_vhLastVisitor") || 0; + // 是否是今天缓存 + const nowVisitDate = new Date(); + const vhLastVisitorDate = new Date(Number(vhLastVisitor)); + const vhLastVisitDate = new Date(Number(vhLastVisit)); + // 访客访问 + if (nowVisitDate.getFullYear() === vhLastVisitorDate.getFullYear() && nowVisitDate.getMonth() === vhLastVisitorDate.getMonth() && nowVisitDate.getDate() === vhLastVisitorDate.getDate()) { + // 今天缓存即老用户 + visitor = false; + } else { + // 否则更新缓存时间 + localStorage.setItem("_vhLastVisitor", Date.now()); + } + // 访问次数访问 + if (Date.now() - vhLastVisitDate.getTime() < AccessInterval * 60 * 1000) { + // 超过访问间隔即老访客 + visit = false; + } else { + // 否则更新缓存时间 + PathVisit[pathname] = Date.now(); + localStorage.setItem("_vhLastVisit", JSON.stringify(PathVisit)); + } + + // URL转码 + const encode = (str) => { + if (!str) return ""; + try { + if (decodeURI(str) !== str) return decodeURI(str); + } catch (e) { + return str; + } + return encodeURI(str); + }; + + // 上报 + const send = async () => { + if (!website) return; + try { + await fetch(sendURL, { + method: "POST", + body: JSON.stringify({ + website, + host, + path: encode(pathname + location.search), //上报带参数的路径 + referrer: encode(currentRef), + visitor, + visit + }), + headers: { + "Content-Type": "application/json" + } + }); + } catch (e) { + /* empty */ + } + }; + send(); +})(window); From ecbe12c7e97b57ed8b19690632061b0df1229592 Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:19:56 +0800 Subject: [PATCH 6/8] Update tracker.js --- public/tracker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/public/tracker.js b/public/tracker.js index d084d00..1bc1c32 100644 --- a/public/tracker.js +++ b/public/tracker.js @@ -64,7 +64,7 @@ body: JSON.stringify({ website, host, - path: encode(pathname + location.search), + path: encode(pathname), referrer: encode(currentRef), visitor, visit From 6235e8d77b68647158f32964774b2a4358b2b865 Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:23:15 +0800 Subject: [PATCH 7/8] Create tracker-all.min.js --- public/tracker-all.min.js | 1 + 1 file changed, 1 insertion(+) create mode 100644 public/tracker-all.min.js diff --git a/public/tracker-all.min.js b/public/tracker-all.min.js new file mode 100644 index 0000000..b8c1b74 --- /dev/null +++ b/public/tracker-all.min.js @@ -0,0 +1 @@ +(a=>{const{location:b,document:c,navigator:d}=a,{hostname:e,pathname:f}=b,{currentScript:g,referrer:h}=c,i=h.includes(e)?"":h;if(!g||0{if(!a)return"";try{if(decodeURI(a)!==a)return decodeURI(a)}catch(b){return a}return encodeURI(a)},v=async()=>{if(k)try{await fetch(l,{method:"POST",body:JSON.stringify({website:k,host:e,path:u(f+b.search),referrer:u(i),visitor:m,visit:n}),headers:{"Content-Type":"application/json"}})}catch(a){}};v()})(window); From 18c17bd15fdb824cdc1cc8e5777ca9ce6877b471 Mon Sep 17 00:00:00 2001 From: FengZiLeo Date: Wed, 25 Jun 2025 20:28:56 +0800 Subject: [PATCH 8/8] Update README.md --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 65ae221..ef90b69 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,8 @@ AnalyticsDataset ```js // 在网站底部插入以下代码即可集成网站分析仪表板 +// 如果需要在统计页面显示访问的路径以及参数,如“/path/?hello=word”,则在网站底部插入以下代码 + ``` ### 数据问题 @@ -65,4 +67,4 @@ https://www.vvhan.com/article/han-analytics ## Stargazers over time -![Stargazers over time](https://starchart.cc/uxiaohan/HanAnalytics.svg?variant=adaptive) \ No newline at end of file +![Stargazers over time](https://starchart.cc/uxiaohan/HanAnalytics.svg?variant=adaptive)