jiacai2050 / pageview-worker

Page View backend based on Cloudflare Workers and KV.

Home Page:http://jiacai2050.github.io/pageview-worker/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

Page View backend based on Cloudflare Workers and KV.

http://jiacai2050.github.io/pageview-worker/

License:GNU General Public License v3.0


Languages

Language:JavaScript 96.3%Language:Makefile 3.7%