From d1c2c26dd34b005432bacba171f22beec946449f Mon Sep 17 00:00:00 2001
From: Cory Dransfeldt <coryd@hey.com>
Date: Sun, 24 Mar 2024 16:12:19 -0700
Subject: [PATCH] chore: eventing

---
 .env                 | 1 -
 api/event.js         | 9 +++------
 src/pages/contact.md | 2 +-
 3 files changed, 4 insertions(+), 8 deletions(-)

diff --git a/.env b/.env
index ec2f27ab..4840fddb 100644
--- a/.env
+++ b/.env
@@ -3,7 +3,6 @@ SECRET_KEY_B2=
 BUCKET_B2=
 API_KEY_LASTFM=
 API_KEY_FATHOM=
-API_KEY_FATHOM_EVENTING=
 API_KEY_TRAKT=
 API_KEY_MOVIEDB=
 API_TOKEN_READWISE=
diff --git a/api/event.js b/api/event.js
index 63c57a0e..3573921e 100644
--- a/api/event.js
+++ b/api/event.js
@@ -2,14 +2,13 @@ import crypto from 'node:crypto'
 import { getStore } from '@netlify/blobs';
 
 export default async (request, context) => {
-  const FATHOM_KEY = Netlify.env.get("API_KEY_FATHOM_EVENTING")
-  const FATHOM_EVENT_URL = 'https://api.usefathom.com/v1/sites/CWSVCDJC/events/'
   const ns = new URL(request['url']).searchParams.get('ns')
   const page = new URL(request['url']).searchParams.get('page')
   const num = new URL(request['url']).searchParams.get('num')
   const lang = decodeURIComponent(new URL(request['url']).searchParams.get('lang'))
   const nav = decodeURIComponent(new URL(request['url']).searchParams.get('nav'))
   const ig = new URL(request['url']).searchParams.get('ig')
+  const setUrl = (id, event) => `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${id}&name=${encodeURIComponent(event)}`
   const headers = {}
   if (lang) headers['Accept-Language'] = lang;
   if (nav) headers['User-Agent'] = nav;
@@ -22,11 +21,9 @@ export default async (request, context) => {
     const userId = await ids.get(id)
     if (!userId) await ids.set(id, id)
     const idVal = await ids.get(id)
-    url = `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${idVal}`
-    fetch(`${FATHOM_EVENT_URL}no-script-visit-id-${idVal}`, { headers: { "Authorization": `Bearer ${FATHOM_KEY}` }})
+    url = setUrl(idVal, `[noscript visit] ID: ${idVal}`)
   } else {
-    url = `https://cdn.usefathom.com/?h=${encodeURIComponent(page)}&sid=CWSVCDJC&cid=${num}`
-    fetch(`${FATHOM_EVENT_URL}blocked-visit-id-${num}`, { headers: { "Authorization": `Bearer ${FATHOM_KEY}` }})
+    url = setUrl(num, `[Blocked visit] ID: ${num}`)
   }
 
   fetch(url, { headers })
diff --git a/src/pages/contact.md b/src/pages/contact.md
index 11a7edc5..6afd252f 100644
--- a/src/pages/contact.md
+++ b/src/pages/contact.md
@@ -20,7 +20,7 @@ description: 'How to contact me.'
       <li>File an issue on the appropriate repo over at <a href="https://github.com/cdransf">GitHub</a></li>
     </ul>
   </div>
-  <form class="column" method="POST" action="/contact/success" name="contact" netlify netlify-honeypot="bot-field">
+  <form onsubmit="fathom.trackEvent('Contact form submitted');" class="column" method="POST" action="/contact/success" name="contact" netlify netlify-honeypot="bot-field">
     <label class="hidden">
       Don't fill this out if you're human: <input name="bot-field" />
     </label>