A simple statistics tool to count your sites' visitors. It uses DenoKV
as the database and can be deployed to Deno Deploy
for free.
- Fork this repository
- Deploy on Deno Deploy (The entry point is
main.js
) - Optionally, set a custom domain
- Include the script in your site:
<script defer src="https://xxx.xxx/static" data-db="https://xxx.xxx"></script>
- Add containers to your site:
<span id="SV"></span>
for total visitors (Site Visitors)<span id="SUV"></span>
for unique visitors (Site Unique Visitors)<span id="PV"></span>
for total visitors of the current page (Page Visitors)<span id="PUV"></span>
for unique visitors of the current page (Page Unique Visitors) - Done!
Note: The same visitor will not be counted as a unique visitor within
12
hours after the last visit
- Clone this repository
- Run
deno run -A --unstable-kv --watch main.js
to start the server - Open
http://localhost:10222/dev
in your browser
Make sure you have installed
deno
Path | Description | Method | Request | Response |
---|---|---|---|---|
/static |
Return static JS file |
GET |
None | JS |
/dev |
Return a test page | GET |
None | HTML |
/api |
Record and return counts | GET |
See below | json |
Just include
<script defer src="xxx/static" data-db="xxx"></script>
in your site, wherexxx
is the server address
Request Parameters | Type | Description |
---|---|---|
hostname |
string |
The hostname of the site |
path |
string |
The path of the site |
time |
string |
The time of the visit |
unique |
string |
Whether to count as a unique visitor |
Response Parameters | Type | Description |
---|---|---|
SV |
number |
Total visitors of the site |
SUV |
number |
Total unique visitors of the site |
PV |
number |
Total visitors of the page |
PUV |
number |
Total unique visitors of the page |
interface key {
hostname: string
'visitors': 'visitors'
path: string
time: string
}
interface value {
unique: boolean
}
When I use a domain hosted on Cloudflare
to access this service, I encountered a problem that I cannot get the static JS
file, but when I use deno.dev
to import the static file and set data-db
to my server address (hosted on Cloudflare
), it works fine; to solve this problem, you can directly import static.js
locally, or use xxx.deno.dev/static
to import the static file