feat: bye analytics
This commit is contained in:
parent
94d58d0f0c
commit
2bf2fba325
20 changed files with 14 additions and 185 deletions
|
@ -1,39 +0,0 @@
|
|||
const scriptName = '/js/script.js'
|
||||
const endpoint = '/api/event'
|
||||
|
||||
addEventListener("fetch", (event) => {
|
||||
event.passThroughOnException()
|
||||
event.respondWith(handleRequest(event))
|
||||
})
|
||||
|
||||
async function handleRequest(event) {
|
||||
const url = new URL(event.request.url)
|
||||
const pathname = url.pathname
|
||||
|
||||
if (pathname === scriptName) {
|
||||
return getScript(event)
|
||||
} else if (pathname === endpoint) {
|
||||
return postData(event)
|
||||
}
|
||||
return new Response(null, { status: 404 })
|
||||
}
|
||||
|
||||
async function getScript(event) {
|
||||
const cache = caches.default
|
||||
let response = await cache.match(event.request)
|
||||
|
||||
if (!response) {
|
||||
const scriptUrl =
|
||||
'https://plausible.io/js/plausible.outbound-links.tagged-events.js'
|
||||
response = await fetch(scriptUrl)
|
||||
if (response.ok) event.waitUntil(cache.put(event.request, response.clone()))
|
||||
}
|
||||
|
||||
return response
|
||||
}
|
||||
|
||||
async function postData(event) {
|
||||
const request = new Request(event.request)
|
||||
request.headers.delete('cookie')
|
||||
return await fetch('https://plausible.io/api/event', request)
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
name = "analytics-worker"
|
||||
main = "./index.js"
|
||||
compatibility_date = "2023-01-01"
|
||||
|
||||
account_id = "${CF_ACCOUNT_ID}"
|
||||
workers_dev = true
|
||||
|
||||
[env.production]
|
||||
name = "analytics-worker-production"
|
||||
routes = [
|
||||
{ pattern = "coryd.dev/js/*", zone_id = "${CF_ZONE_ID}" },
|
||||
{ pattern = "coryd.dev/api/event", zone_id = "${CF_ZONE_ID}" }
|
||||
]
|
Reference in a new issue