Skip to content

LeafYeeXYZ/DenoCount

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

中文 | English

DenoCount

A simple statistics tool to count your sites' visitors. It uses DenoKV as the database and can be deployed to Deno Deploy for free.

Usage

  1. Fork this repository
  2. Deploy on Deno Deploy (The entry point is main.js)
  3. Optionally, set a custom domain
  4. Include the script in your site: <script defer src="https://xxx.xxx/static" data-db="https://xxx.xxx"></script>
  5. 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)
  6. Done!

Note: The same visitor will not be counted as a unique visitor within 12 hours after the last visit

Local Demo

  1. Clone this repository
  2. Run deno run -A --unstable-kv --watch main.js to start the server
  3. Open http://localhost:10222/dev in your browser

Make sure you have installed deno

API Reference

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, where xxx is the server address

/api Request and Response

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

KV Data

interface key {
  hostname: string
  'visitors': 'visitors'
  path: string
  time: string
}

interface value {
  unique: boolean
}

Others

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