up
This commit is contained in:
parent
72a026455d
commit
59ed0ed1f0
2
.gitignore
vendored
2
.gitignore
vendored
@ -114,7 +114,7 @@ out
|
||||
# Nuxt.js build / generate output
|
||||
|
||||
.nuxt
|
||||
dist
|
||||
.dist
|
||||
|
||||
# Gatsby files
|
||||
|
||||
|
16
README.md
16
README.md
@ -67,4 +67,18 @@ Uploaded analytics_with_cloudflare (1.29 sec)
|
||||
Published analytics_with_cloudflare (4.03 sec)
|
||||
https://analytics_with_cloudflare.xxxxx.workers.dev
|
||||
Current Deployment ID: xxxxxxxxxxxxxxxxxxxxxxxxxxxx
|
||||
```
|
||||
```
|
||||
|
||||
|
||||
## Use
|
||||
|
||||
inclout js and add `<span id='page_pv'>?</span> <span id='page_uv'>?</span>`
|
||||
```
|
||||
<script src="/front/dist/index.min.js" data-base-url="https://analytics_with_cloudflare.xxxxx.workers.dev"></script>
|
||||
<script src="/front/dist/index.min.js" data-base-url="diy Url"></script>
|
||||
<script src="/front/dist/index.min.js" data-base-url="diy Url" data-page-pv-id="page_pv" data-page-uv-id="page_uv"></script>
|
||||
```
|
||||
|
||||
- data-base-url: Default value is `https://webviso.yestool.org`
|
||||
- data-page-pv-id: Default value is `page_pv`
|
||||
- data-page-uv-id: Default value is `page_uv`
|
1
front/dist/index.min.js
vendored
Normal file
1
front/dist/index.min.js
vendored
Normal file
@ -0,0 +1 @@
|
||||
!function(){console.info("welcome to WebViso/yestool,author:YesTool,author url: https://webviso.yestool.org"),setTimeout((function(){document.head&&(document.head.innerHTML+='<meta property="og:site_counter_author" content="yestool"></meta><meta property="og:site_counter_author_url" content="https://webviso.yestool.org"></meta>')}),500);const e=document.currentScript;let t=e.getAttribute("data-base-url"),o=e.getAttribute("data-page-pv-id"),n=e.getAttribute("data-page-uv-id");const r={version:"0.0.0"};let i="https://webviso.yestool.org";r.page_pv_id="page_pv",r.page_uv_id="page_uv",t&&(i=t),o&&(r.page_pv_id=o),n&&(r.page_uv_id=n),r.init=async function(){const e=getLocation(window.location.href),t=document.getElementById(r.page_pv_id),o=document.getElementById(r.page_uv_id),n={url:e.pathname,hostname:e.hostname,referrer:document.referrer};var a,s;t&&(n.pv=!0),o&&(n.uv=!0),await(a=`${i}/api/visit`,s=n,new Promise((e=>{fetch(a,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(s)}).then((e=>e.json())).then((function(t){e(t)})).catch((e=>{console.error(e)}))}))).then((e=>{if("OK"!=e.ret)return void console.error("WebViso.init error",e.message);const n=e.data;t&&(t.innerText=n.pv),o&&(o.innerText=n.uv)})).catch((e=>{console.log("WebViso.init fetch error",e)}))};const getLocation=function(e){const t=document.createElement("a");return t.href=e,t};"undefined"!=typeof window&&(r.init(),window.WebViso=r)}();
|
17
src/index.ts
17
src/index.ts
@ -21,9 +21,8 @@ app.post('/api/visit', async (c) => {
|
||||
const hostname = body.hostname
|
||||
const url_path = body.url
|
||||
const referrer = body.referrer
|
||||
if (!visitorIP){
|
||||
visitorIP = "127.0.0.2";
|
||||
}
|
||||
const pv = body.pv
|
||||
const uv = body.uv
|
||||
let referrer_path = ''
|
||||
let referrer_domain = ''
|
||||
if (referrer&&checkUrl(referrer)){
|
||||
@ -44,8 +43,16 @@ app.post('/api/visit', async (c) => {
|
||||
'insert into t_web_visitor (website_id, url_path, referrer_domain, referrer_path, visitor_ip) values(?, ?, ?, ?, ?)',
|
||||
[websiteId, url_path, referrer_domain, referrer_path, visitorIP]);
|
||||
}
|
||||
const total = await c.env.DB.prepare('SELECT COUNT(*) AS total from (select DISTINCT visitor_ip from t_web_visitor where website_id = ? and url_path = ?) t').bind(websiteId, url_path).first('total');
|
||||
return c.json({ret: "OK", data: total});
|
||||
const resData:{pv?: number, uv?: number} = {}
|
||||
if (pv){
|
||||
const total = await c.env.DB.prepare('SELECT COUNT(*) AS total from t_web_visitor where website_id = ? and url_path = ?').bind(websiteId, url_path).first('total');
|
||||
resData['pv'] = Number(total)
|
||||
}
|
||||
if (uv){
|
||||
const total = await c.env.DB.prepare('SELECT COUNT(*) AS total from (select DISTINCT visitor_ip from t_web_visitor where website_id = ? and url_path = ?) t').bind(websiteId, url_path).first('total');
|
||||
resData['uv'] = Number(total)
|
||||
}
|
||||
return c.json({ret: "OK", data: resData});
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
return c.json(retObj);
|
||||
|
Loading…
x
Reference in New Issue
Block a user