Skip to content

jiacai2050/pageview-worker

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pageview Worker

Page View backend based on Cloudflare Workers and KV.

pageview.jpg

Live demo:

There are two pages containing demo/tracking.js for this live demo:

⚠️ Demo pages will collect your IP/Country/City, click at your own risk.

Use at you own website

  • Setup workers, refer to quickstarts
  • Add KV binding, refer to referencing KV from Workers
    • Binding name is KV in this project.
  • Add following tracking code to HTML files you want to track, replace apiEndpoint with your worker address.
    const apiEndpoint = 'https://pageview-demo.jiacai2050.workers.dev/write';
    const payload = {
      'url': document.location.href,
      'title': document.title,
      'referrer': window.frames.top.document.referrer,
    };
    fetch(`${apiEndpoint}?${new URLSearchParams(payload)}`, {mode: 'no-cors'})
      .catch(console.log);
        
  • Then when visit HTML, following information will be saved to KV via workers:
    • URL
    • Title
    • Referrer
    • User-Agent
    • IP
    • Country
    • City
  • demo/index.html is provided to view saved pageviews.
    • Replace apiEndpoint with your worker address.

Other fun workers project

License

GPL-3