diff --git a/api/event.js b/api/event.js index 3a8ef9f2..7658b177 100644 --- a/api/event.js +++ b/api/event.js @@ -5,31 +5,34 @@ export default async (request, context) => { const params = new URL(request['url']).searchParams const ns = params.get('ns') const page = params.get('page') - const num = params.get('num') || 'unknown' + const ig = params.get('ig') + + const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}` + const lang = decodeURIComponent(params.get('lang')) const nav = decodeURIComponent(params.get('nav')) const notLang = !lang || lang === 'null' || lang === 'undefined' const notNav = !nav || nav === 'null' || nav === 'undefined' - const ig = params.get('ig') - const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}` const acceptLanguage = notLang ? request['headers'].get('accept-language') : lang const userAgent = notNav ? request['headers'].get('user-agent') : nav const headers = { 'Accept-Language': acceptLanguage, 'User-Agent': userAgent } + let url + const id = crypto.createHash('md5').update(`${context['ip']}${context['geo']['city']}`).digest('hex') + const ids = getStore('ids') + const userId = await ids.get(id) + if (!userId) await ids.set(id, id) + const idVal = await ids.get(id) + if (ig) return if (ns) { - const id = crypto.createHash('md5').update(`${context['ip']}${context['geo']['city']}`).digest('hex') - const ids = getStore('ids') - const userId = await ids.get(id) - if (!userId) await ids.set(id, id) - const idVal = await ids.get(id) url = setUrl(idVal, 'noscript visit') } else { - url = setUrl(num, 'Blocked visit') + url = setUrl(idVal, 'Blocked visit') } fetch(url, { headers }) diff --git a/package.json b/package.json index 36929345..68db6378 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "coryd.dev", - "version": "8.7.4", + "version": "8.7.5", "description": "The source for my personal site. Built using 11ty.", "type": "module", "scripts": { diff --git a/src/assets/scripts/index.js b/src/assets/scripts/index.js index af819c54..23b3f4e4 100644 --- a/src/assets/scripts/index.js +++ b/src/assets/scripts/index.js @@ -1,7 +1,5 @@ -const id = Math.floor(Math.random() * Date.now()) -let i; -let url = `https://coryd.dev/api/event/?page=${encodeURIComponent(window.location.href)}&num=${sessionStorage.getItem('id' || id)}&lang=${encodeURIComponent(navigator.language)}&nav=${encodeURIComponent(navigator.userAgent)}` -if (window.sessionStorage && !window.sessionStorage?.getItem('id')) sessionStorage.setItem('id', id) +let ig; +let url = `https://coryd.dev/api/event/?page=${encodeURIComponent(window.location.href)}&lang=${encodeURIComponent(navigator.language)}&nav=${encodeURIComponent(navigator.userAgent)}` if (window.localStorage && window.localStorage.getItem('ig')) { ig = localStorage.getItem('ig') url = `${url}&ig=${ig}`