Skip to content

Open source alternative to Semrush and Ahrefs

feat: add hosted-only PostHog error tracking (#51)

Ben Senescucdd729ec0d2f
diff --git a/.env.example b/.env.example
index 133eb77a..72c9edc4 100644
--- a/.env.example
+++ b/.env.example
@@ -30,6 +30,8 @@
# Required when AUTH_MODE=hosted
# BETTER_AUTH_SECRET=replace-with-a-long-random-secret-at-least-32-characters
# BETTER_AUTH_URL=http://localhost:3001
+# POSTHOG_PUBLIC_KEY=replace-with-your-posthog-project-api-key
+# POSTHOG_HOST=https://us.i.posthog.com
# LOOPS_API_KEY=replace-with-your-loops-api-key
# LOOPS_TRANSACTIONAL_VERIFY_EMAIL_ID=replace-with-your-loops-verify-template-id
# LOOPS_TRANSACTIONAL_RESET_PASSWORD_ID=replace-with-your-loops-reset-template-id
diff --git a/package.json b/package.json
index 84192d20..8adbeade 100644
--- a/package.json
+++ b/package.json
@@ -64,6 +64,8 @@
"jose": "^6.0.12",
"lucide-react": "^0.542.0",
"papaparse": "^5.5.3",
+ "posthog-js": "^1.363.5",
+ "posthog-node": "^5.28.5",
"react": "^19.0.0",
"react-dom": "^19.0.0",
"recharts": "^3.7.0",
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index c0025a1c..d5b8c54f 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -31,10 +31,10 @@ importers:
autumn-js:
specifier: ^1.1.7
better-auth:
specifier: ^1.5.5
cheerio:
specifier: ^1.2.0
version: 1.2.0
@@ -49,7 +49,7 @@ importers:
version: 2.0.19
drizzle-orm:
specifier: ^0.44.4
- version: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])([email protected])
+ version: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])(@opentelemetry/[email protected])([email protected])
fast-xml-parser:
specifier: ^5.4.1
version: 5.4.1
@@ -62,6 +62,12 @@ importers:
papaparse:
specifier: ^5.5.3
version: 5.5.3
+ posthog-js:
+ specifier: ^1.363.5
+ version: 1.363.6
+ posthog-node:
+ specifier: ^5.28.5
+ version: 5.28.6
react:
specifier: ^19.0.0
version: 19.2.4
@@ -1135,6 +1141,78 @@ packages:
resolution: {integrity: sha512-hAX0pT/73190NLqBPPWSdBVGtbY6VOhWYK3qqHqtXQ1gK7kS2yz4+ivsN07hpJ6I3aeMtKP6J6npsEKOAzuTLA==}
engines: {node: '>=20.0'}
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-CjruKY9V6NMssL/T1kAFgzosF1v9o6oeN+aX5JB/C/xPNtmgIJqcXHG7fA82Ou1zCpWGl4lROQUKwUNE1pMCyg==}
+ engines: {node: '>=8.0.0'}
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-gLyJlPHPZYdAk1JENA9LeHejZe1Ti77/pTeFm/nMXmQH/HFZlcS/O2XJB+L8fkbrNSqhdtlvjBVjxwUYanNH5Q==}
+ engines: {node: '>=8.0.0'}
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-FuabnnUm8LflnieVxs6eP7Z383hgQU4W1e3KJS6aOG3RxWxcHyBxH8fDMHNgu/gFx/M2jvTOW/4/PHhLz6bjWw==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.0.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-8xHSGWpJP9wBxgBpnqGL0R3PbdWQndL1Qp50qrg71+B28zK5OQmUgcDKLJgzyAAV38t4tOyLMGDD60LneR5W8g==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.0.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-jOv40Bs9jy9bZVLo/i8FwUiuCvbjWDI+ZW13wimJm4LjnlwJxGgB+N/VWOZUTpM+ah/awXeQqKdNlpLf2EjvYg==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': ^1.3.0
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-gMd39gIfVb2OgxldxUtOwGJYSH8P1kVFFlJLuut32L6KgUC4gl1dMhn+YC2mGn0bDOiQYSk/uHOdSjuKp58vvA==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': ^1.3.0
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-DCFPY8C6lAQHUNkzcNT9R+qYExvsk6C5Bto2pbNxgicpcSWbe2WHShLxkOxIdNcBiYPdVHv/e7vH7K6TI+C+fQ==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': ^1.3.0
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-1pNQf/JazQTMA0BiO5NINUzH0cbLbbl7mntLa4aJNmCCXSj0q03T5ZXXL0zw4G55TjdL9Tz32cznGClf+8zr5A==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.3.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-lID/vxSuKWXM55XhAKNoYXu9Cutoq5hFdkbTdI/zDKQktXzcWBVhNsOkiZFTMU9UtEWuGRNe0HUgmsFldIdxVA==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.3.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-QlAyL1jRpOeaqx7/leG1vJMp84g0xKP6gJmfELBpnI4O/9xPX+Hu5m1POk9Kl+veNkyth5t19hRlN6tNY1sjbA==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.4.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-G5KYP6+VJMZzpGipQw7Giif48h6SGQ2PFKEYCybeXJsOCB4fp8azqMAAzE5lnnHK3ZVwYQrgmFbsUJO/zOnwGw==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.9.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-xWQgL0Bmctsalg6PaXExmzdedSp3gyKV8mQBwK/j9VGdCDu2fmXIb2gAehBKbkXCpJ4HPkgv3QfoJWRT4dHWbw==}
+ engines: {node: ^18.19.0 || >=20.6.0}
+ peerDependencies:
+ '@opentelemetry/api': '>=1.3.0 <1.10.0'
+
+ '@opentelemetry/[email protected]':
+ resolution: {integrity: sha512-cifvXDhcqMwwTlTK04GBNeIe7yyo28Mfby85QXFe1Yk8nmi36Ab/5UQwptOx84SsoGNRg+EVSjwzfSZMy6pmlw==}
+ engines: {node: '>=14'}
+
'@oxc-resolver/[email protected]':
resolution: {integrity: sha512-EhwJNzbfLwQQIeyak3n08EB3UHknMnjy1dFyL98r3xlorje2uzHOT2vkB5nB1zqtTtzT31uSot3oGZFfODbGUg==}
cpu: [arm]
@@ -1404,6 +1482,42 @@ packages:
'@poppinss/[email protected]':
resolution: {integrity: sha512-dCED+QRChTVatE9ibtoaxc+WkdzOSjYTKi/+uacHWIsfodVfpsueo3+DKpgU5Px8qXjgmXkSvhXvSCz3fnP9lw==}
+ '@posthog/[email protected]':
+ resolution: {integrity: sha512-e8AciAnc6MRFws89ux8lJKFAaI03yEon0ASDoUO7yS91FVqbUGXYekObUUR3LHplcg+pmyiJBI0jolY0SFbGRA==}
+
+ '@posthog/[email protected]':
+ resolution: {integrity: sha512-SPU8psjrpK8prfFyYwvb25F1AgqSM32zdU1XPVIhUa107Cyw+VGw38Gv+AeqkEoAYQE2TFlWJT8DWUrw/mNDoQ==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-j+gKExEuLmKwvz3OgROXtrJ2UG2x8Ch2YZUxahh+s1F2HZ+wAceUNLkvy6zKCPVRkU++ZWQrdxsUeQXmcg4uoQ==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-AZkcAA5vnN/v4PDqKyMR5lx7hZttPDgClv83E//FMNhR2TMcLUhfRUBHCmSl0oi9zMgDDqRUJkSxO3wm85+XLg==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-YyFaikqM5sH0ziFZCN3xDC7zeGaB/d0IUb9CATugHWbd1FRFwWwt4ld4OYMPWu5a3Xe01mGAULCdqhMlPl29Jg==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-j9ednRT81vYJ9OfVuXG6ERSTdEL1xVsNgqpkxMsbIabzSo3goCjDIveeGv5d03om39ML71RdmrGNjG5SReBP/Q==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-lljVXpqXebpsijW71PZaCYeIcE5on1w5DlQy5WH6GLbFryLUrBD4932W/E2BSpfRJWseIL4v/KPgBFxDOIdKpQ==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-Ddb+kVXlXst9d+R9PfTIxh1EdNkgoRe5tOX6t01f1lYWOvJnSPDBlG241QLzcyPdoNTsblLUdujGSE4RzrTZGQ==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-kdSefcPdruJiFMVSbn801t4vFK7KB/5gd2fYvrxhuJYg8ILrmn9SKSX2tZdV6V+ksulWqS7aXjBcRXl3wHoD9Q==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-6JOcJ5Tm08dOHAbdR3GrvP+yUUfkjG5ePsHYczMFLq3ZmMkAD98cDgcT2iA1lJ9NVwFd4tH/iSSoe44YWkltEA==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-0kELaGSIDBKvcgS4zkjz1PeddatrjYcmMWOlAuAPwAeccUrPHdUqo/J6LiymHHEiJT5NrF1UVwxY14f+fy4WQw==}
+
+ '@protobufjs/[email protected]':
+ resolution: {integrity: sha512-Vvn3zZrhQZkkBE8LSuW3em98c0FwgO4nxzv6OdSxPKJIEKY2bGbHn+mhGIPerzI4twdxaP8/0+06HBpwf345Lw==}
+
'@reduxjs/[email protected]':
resolution: {integrity: sha512-Kd6kAHTA6/nUpp8mySPqj3en3dm0tdMIgbttnQ1xFMVpufoj+ADi8pXLBsd4xzTRHQa7t/Jv8W5UnCuW4kuWMQ==}
peerDependencies:
@@ -1962,6 +2076,9 @@ packages:
resolution: {integrity: sha512-ilcTH/UniCkMdtexkoCN0bI7pMcJDvmQFPvuPvmEaYA/NSfFTAgdUSLAoVjaRJm7+6PvcM+q1zYOwS4wTYMF9w==}
+ '@types/[email protected]':
+ resolution: {integrity: sha512-ScaPdn1dQczgbl0QFTeTOmVHFULt394XJgOQNoyVhZ6r2vLnMLJfBPd53SB52T/3G36VI1/g2MZaX0cwDuXsfw==}
+
resolution: {integrity: sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==}
@@ -2226,6 +2343,13 @@ packages:
resolution: {integrity: sha512-ei8Aos7ja0weRpFzJnEA9UHJ/7XQmqglbRwnf2ATjcB9Wq874VKH9kfjjirM6UhU2/E5fFYadylyhFldcqSidQ==}
engines: {node: '>=18'}
+ resolution: {integrity: sha512-es1U2+YTtzpwkxVLwAFdSpaIMyQaq0PBgm3YD1W3Qpsn1NAmO3KSgZfu+oGSWVu6NvLHoHCV/aYcsE5wiB7ALg==}
+
+ resolution: {integrity: sha512-uV2QOWP2nWzsy2aMp8aRibhi9dlzF5Hgh5SHaB9OiTGEyDTiJJyx0uy51QXdyWbtAHNua4XJzUKca3OzKUd3vA==}
+ engines: {node: '>= 8'}
+
resolution: {integrity: sha512-TizTzUddG/xYLA3NXodFM0fSbNizXjOKhqiQQwvhlspadZokn1KDy0NZFS0wuEubIYAV5/c1/lAr0TaaFXEXzw==}
@@ -2339,6 +2463,9 @@ packages:
resolution: {integrity: sha512-cgwlv/1iFQiFnU96XXgROh8xTeetsnJiDsTc7TYCLFd9+/WNkIqPTxiM/8pSd8VIrhXGTf1Ny1q1hquVqDJB5w==}
engines: {node: '>= 4'}
+ resolution: {integrity: sha512-Oj6pzI2+RqBfFG+qOaOLbFXLQ90ARpcGG6UePL82bJLtdsa6CYJD7nmiU8MW9nQNOtCHV3lZ/Bzq1X0QYbBZCA==}
+
resolution: {integrity: sha512-6kZKyUajlDuqlHKVX1w7gyslj9MPIXzIFiz/rGu35uC1wMi+kMhQwGhl4lt9unC9Vb9INnY9Z3/ZA3+FhASLaw==}
@@ -2565,6 +2692,9 @@ packages:
resolution: {integrity: sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==}
engines: {node: ^12.20 || >= 14.13}
+ resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==}
+
resolution: {integrity: sha512-YsGpe3WHLK8ZYi4tWDg2Jy3ebRz2rXowDxnld4bkQB00cc/1Zw9AWnC0i9ztDJitivtQvaI9KaLyKrc+hBW0yg==}
engines: {node: '>=8'}
@@ -2697,6 +2827,9 @@ packages:
resolution: {integrity: sha512-waFfC72ZNfwLLuJ2iLaoVaqcNo+CAaLR7xCpAn0Y5WfGzkNHv7ZN39Vbi1y+kb+Zs46XHOX3tZNExroFUPX+Kg==}
engines: {node: '>=18'}
+ resolution: {integrity: sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==}
+
resolution: {integrity: sha512-ekilCSN1jwRvIbgeg/57YFh8qQDNbwDb9xT/qu2DAHbFFZUicIl4ygVaAvzveMhMVr3LnpSKTNnwt8PoOfmKhQ==}
hasBin: true
@@ -2828,6 +2961,9 @@ packages:
resolution: {integrity: sha512-l51N2r93WmGUye3WuFoN5k10zyvrVs0qfKBhyC5ogUQ6Ew6JUSswh78mbSO+IU3nTWsyOArqPCcShdQSadghBQ==}
engines: {node: '>= 12.0.0'}
+ resolution: {integrity: sha512-mNAgZ1GmyNhD7AuqnTG3/VQ26o760+ZYBPKjPvugO8+nLbYfX6TVpJPseBvopbdY+qpZ/lKUnmEc1LeZYS3QAA==}
+
resolution: {integrity: sha512-CdzqowRJCeLU72bHvWqwRBBlLcMEtIvGrlvef74kMnV2AolS9Y8xUv1I0U/MNAWMhBlKIoyuEgoJ0t/bbwHbLQ==}
@@ -2973,6 +3109,10 @@ packages:
resolution: {integrity: sha512-IInvU7fabl34qmi9gY8XOVxhYyMyuH2xUNpb2q8/Y+7552KlejkRvqvD19nMoUW/uQGGbqNpA6Tufu5FL5BZgw==}
+ resolution: {integrity: sha512-ojmeN0qd+y0jszEtoY48r0Peq5dwMEkIlCOu6Q5f41lfkswXuKtYrhgoTpLnyIcHm24Uhqx+5Tqm2InSwLhE6Q==}
+ engines: {node: '>=8'}
+
resolution: {integrity: sha512-Yhpw4T9C6hPpgPeA28us07OJeqZ5EzQTkbfwuhsUg0c237RomFoETJgmp2sa3F/41gfLE6G5cqcYwznmeEeOlQ==}
@@ -3004,6 +3144,21 @@ packages:
resolution: {integrity: sha512-3Ybi1tAuwAP9s0r1UQ2J4n5Y0G05bJkpUIO0/bI9MhwmD70S5aTWbXGBwxHrelT+XM1k6dM0pk+SwNkpTRN7Pg==}
engines: {node: ^10 || ^12 || >=14}
+ resolution: {integrity: sha512-eQ+Ypml3JOEMQWt21XEea6J8vD77TNyoz4Yv/xxjlTRja+ilmJtQw/SuVAB3BobjgHKYUomXX7Fc4gH/zTVpbg==}
+
+ resolution: {integrity: sha512-f3k45gplzVxbhIMj3x6jZP6iH1wacBurKrZxD1VwW+7f8L2DtjJbkiQw0oKwubgtCZcKNroPa8y6t/nDITgOMw==}
+ engines: {node: ^20.20.0 || >=22.22.0}
+ peerDependencies:
+ rxjs: ^7.0.0
+ peerDependenciesMeta:
+ rxjs:
+ optional: true
+
+ resolution: {integrity: sha512-wSAGyk2bYR1c7t3SZ3jHcM6xy0lcBcDel6lODcs9ME6Th++Dx2KU+6D3HD8wMMKGA8Wpw7OMd3/4RGzYRpzwRg==}
+
resolution: {integrity: sha512-UOnG6LftzbdaHZcKoPFtOcCKztrQ57WkHDeRD9t/PTQtmT0NHSeWWepj6pS0z/N7+08BHFDQVUrfmfMRcZwbMg==}
engines: {node: '>=14'}
@@ -3012,10 +3167,17 @@ packages:
resolution: {integrity: sha512-7nJ6v5lnJsXwGprnGXga4wx6d1POjvi5Qmf1ivTRxTjH4Z/9Czja/UCMLVmB9N93GeWOU93XaFaEt6jbuoagNw==}
+ resolution: {integrity: sha512-CvexbZtbov6jW2eXAvLukXjXUW1TzFaivC46BpWc/3BpcCysb5Vffu+B3XHMm8lVEuy2Mm4XGex8hBSg1yapPg==}
+ engines: {node: '>=12.0.0'}
+
resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==}
engines: {node: '>=6'}
+ resolution: {integrity: sha512-lT5yCqEBgfoMYpf3F2xQRK7zEr1rhIIZuceDK6+xRkJQ4NMbHTwXqk4NkwDwQMNqXgG9r9fyHnzwNVs6zV5KRw==}
+
resolution: {integrity: sha512-5fBfMOcDi5SA9qj5jZhWAcTtDfKF5WFdd2uD9nVNlbxVv1baq65aALy6qofpNEGELHvisjjasxQp7BlM9gvMzw==}
engines: {node: '>=18'}
@@ -3148,6 +3310,14 @@ packages:
resolution: {integrity: sha512-Ou9I5Ft9WNcCbXrU9cMgPBcCK8LiwLqcbywW3t4oDV37n1pzpuNLsYiAV8eODnjbtQlSDwZ2cUEeQz4E54Hltg==}
engines: {node: ^18.17.0 || ^20.3.0 || >=21.0.0}
+ resolution: {integrity: sha512-kHxr2zZpYtdmrN1qDjrrX/Z1rR1kG8Dx+gkpK1G4eXmvXswmcE1hTWBWYUzlraYw1/yZp6YuDY77YtvbN0dmDA==}
+ engines: {node: '>=8'}
+
+ resolution: {integrity: sha512-7++dFhtcx3353uBaq8DDR4NuxBetBzC7ZQOhmTQInHEd6bSrXdiEyzCvG07Z44UYdLShWUyXt5M/yhz8ekcb1A==}
+ engines: {node: '>=8'}
+
resolution: {integrity: sha512-ObmnIF4hXNg1BqhnHmgbDETF8dLPCggZWBjkQfhZpbszZnYur5DUljTcCHii5LC3J5E0yeO/1LIMyH+UvHQgyw==}
engines: {node: '>= 0.4'}
@@ -3435,6 +3605,9 @@ packages:
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
engines: {node: '>= 14'}
+ resolution: {integrity: sha512-i2z98bEmaCqSDiHEDu+gHl/dmR4Q+TxFmG3/13KkMO+o8UxQzCqWaDRCiLgEa41nlO4VpXSI0ASa1xWmO9sBlA==}
+
resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==}
@@ -3461,6 +3634,11 @@ packages:
resolution: {integrity: sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==}
+ resolution: {integrity: sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==}
+ engines: {node: '>= 8'}
+ hasBin: true
+
resolution: {integrity: sha512-hUrmaWBdVDcxvYqnyh09zunKzROWjbZTiNy8dBEjkS7ehEDQibXJ7XvlmtbwuTclUiIyN+CyXQD4Vmko8fNm8w==}
engines: {node: '>=8'}
@@ -3667,12 +3845,12 @@ snapshots:
optionalDependencies:
'@cloudflare/workers-types': 4.20260302.0
dependencies:
'@better-auth/utils': 0.3.1
optionalDependencies:
- drizzle-orm: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])([email protected])
+ drizzle-orm: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])(@opentelemetry/[email protected])([email protected])
dependencies:
@@ -4234,6 +4412,82 @@ snapshots:
'@oozcitak/[email protected]': {}
+ '@opentelemetry/[email protected]':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+
+ '@opentelemetry/[email protected]': {}
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/semantic-conventions': 1.40.0
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/semantic-conventions': 1.40.0
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/api-logs': 0.208.0
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/otlp-exporter-base': 0.208.0(@opentelemetry/[email protected])
+ '@opentelemetry/otlp-transformer': 0.208.0(@opentelemetry/[email protected])
+ '@opentelemetry/sdk-logs': 0.208.0(@opentelemetry/[email protected])
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/otlp-transformer': 0.208.0(@opentelemetry/[email protected])
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/api-logs': 0.208.0
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/resources': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/sdk-logs': 0.208.0(@opentelemetry/[email protected])
+ '@opentelemetry/sdk-metrics': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/sdk-trace-base': 2.2.0(@opentelemetry/[email protected])
+ protobufjs: 7.5.4
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/semantic-conventions': 1.40.0
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/core': 2.6.1(@opentelemetry/[email protected])
+ '@opentelemetry/semantic-conventions': 1.40.0
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/api-logs': 0.208.0
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/resources': 2.2.0(@opentelemetry/[email protected])
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/resources': 2.2.0(@opentelemetry/[email protected])
+
+ '@opentelemetry/[email protected](@opentelemetry/[email protected])':
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/core': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/resources': 2.2.0(@opentelemetry/[email protected])
+ '@opentelemetry/semantic-conventions': 1.40.0
+
+ '@opentelemetry/[email protected]': {}
+
'@oxc-resolver/[email protected]':
optional: true
@@ -4383,6 +4637,35 @@ snapshots:
'@poppinss/[email protected]': {}
+ '@posthog/[email protected]':
+ dependencies:
+ cross-spawn: 7.0.6
+
+ '@posthog/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]':
+ dependencies:
+ '@protobufjs/aspromise': 1.1.2
+ '@protobufjs/inquire': 1.1.0
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
+ '@protobufjs/[email protected]': {}
+
dependencies:
'@standard-schema/spec': 1.1.0
@@ -4973,6 +5256,9 @@ snapshots:
dependencies:
csstype: 3.2.3
+ '@types/[email protected]':
+ optional: true
+
'@types/[email protected]': {}
'@types/[email protected]': {}
@@ -5066,13 +5352,13 @@ snapshots:
dependencies:
query-string: 9.3.1
rou3: 0.6.3
zod: 4.3.6
optionalDependencies:
better-call: 1.3.2([email protected])
react: 19.2.4
@@ -5087,10 +5373,10 @@ snapshots:
dependencies:
'@better-auth/memory-adapter': 1.5.5(@better-auth/[email protected](@better-auth/[email protected])(@better-fetch/[email protected])(@cloudflare/[email protected])([email protected]([email protected]))([email protected])([email protected])([email protected]))(@better-auth/[email protected])
@@ -5109,7 +5395,7 @@ snapshots:
optionalDependencies:
drizzle-kit: 0.31.9
- drizzle-orm: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])([email protected])
+ drizzle-orm: 0.44.7(@cloudflare/[email protected])(@libsql/[email protected])(@opentelemetry/[email protected])([email protected])
mongodb: 7.1.0
react: 19.2.4
react-dom: 19.2.4([email protected])
@@ -5229,6 +5515,14 @@ snapshots:
+
+ dependencies:
+ path-key: 3.1.1
+ shebang-command: 2.0.0
+ which: 2.0.2
+
dependencies:
boolbase: 1.0.0
@@ -5317,6 +5611,10 @@ snapshots:
dependencies:
domelementtype: 2.3.0
+ optionalDependencies:
+ '@types/trusted-types': 2.0.7
+
dependencies:
dom-serializer: 2.0.0
@@ -5332,10 +5630,11 @@ snapshots:
transitivePeerDependencies:
- supports-color
optionalDependencies:
'@cloudflare/workers-types': 4.20260302.0
'@libsql/client': 0.15.15
+ '@opentelemetry/api': 1.9.1
kysely: 0.28.12
@@ -5521,6 +5820,8 @@ snapshots:
node-domexception: 1.0.0
web-streams-polyfill: 3.3.3
+
dependencies:
to-regex-range: 5.0.1
@@ -5643,6 +5944,8 @@ snapshots:
+
@@ -5753,6 +6056,8 @@ snapshots:
lightningcss-win32-arm64-msvc: 1.31.1
lightningcss-win32-x64-msvc: 1.31.1
+
@@ -5905,6 +6210,8 @@ snapshots:
dependencies:
entities: 6.0.1
+
@@ -5927,12 +6234,51 @@ snapshots:
picocolors: 1.1.1
source-map-js: 1.2.1
+ dependencies:
+ '@opentelemetry/api': 1.9.1
+ '@opentelemetry/api-logs': 0.208.0
+ '@opentelemetry/exporter-logs-otlp-http': 0.208.0(@opentelemetry/[email protected])
+ '@opentelemetry/resources': 2.6.1(@opentelemetry/[email protected])
+ '@opentelemetry/sdk-logs': 0.208.0(@opentelemetry/[email protected])
+ '@posthog/core': 1.24.1
+ '@posthog/types': 1.363.6
+ core-js: 3.49.0
+ dompurify: 3.3.3
+ fflate: 0.4.8
+ preact: 10.29.0
+ query-selector-shadow-dom: 1.0.1
+ web-vitals: 5.2.0
+
+ dependencies:
+ '@posthog/core': 1.24.1
+
+
+ dependencies:
+ '@protobufjs/aspromise': 1.1.2
+ '@protobufjs/base64': 1.1.2
+ '@protobufjs/codegen': 2.0.4
+ '@protobufjs/eventemitter': 1.1.0
+ '@protobufjs/fetch': 1.1.0
+ '@protobufjs/float': 1.0.2
+ '@protobufjs/inquire': 1.1.0
+ '@protobufjs/path': 1.1.2
+ '@protobufjs/pool': 1.1.0
+ '@protobufjs/utf8': 1.1.0
+ '@types/node': 22.19.11
+ long: 5.3.2
+
+
dependencies:
decode-uri-component: 0.4.1
@@ -6101,6 +6447,12 @@ snapshots:
'@img/sharp-win32-ia32': 0.34.5
'@img/sharp-win32-x64': 0.34.5
+ dependencies:
+ shebang-regex: 3.0.0
+
+
@@ -6353,6 +6705,8 @@ snapshots:
+
@@ -6375,6 +6729,10 @@ snapshots:
tr46: 0.0.3
webidl-conversions: 3.0.1
+ dependencies:
+ isexe: 2.0.0
+
dependencies:
siginfo: 2.0.0
diff --git a/src/client/components/DefaultCatchBoundary.tsx b/src/client/components/DefaultCatchBoundary.tsx
index 67090c94..b0afd9a8 100644
--- a/src/client/components/DefaultCatchBoundary.tsx
+++ b/src/client/components/DefaultCatchBoundary.tsx
@@ -1,24 +1,49 @@
import { Link, rootRouteId, useMatch, useRouter } from "@tanstack/react-router";
import type { ErrorComponentProps } from "@tanstack/react-router";
+import * as React from "react";
import {
getErrorCode,
getStandardErrorMessage,
} from "@/client/lib/error-messages";
import { AuthConfigErrorCard } from "@/client/components/AuthConfigErrorCard";
+import { captureClientError } from "@/client/lib/posthog";
import { UnauthenticatedErrorCard } from "@/client/components/UnauthenticatedErrorCard";
+function shouldCaptureBoundaryError(
+ errorCode: ReturnType<typeof getErrorCode>,
+) {
+ return (
+ errorCode !== "UNAUTHENTICATED" &&
+ errorCode !== "NOT_FOUND" &&
+ errorCode !== "VALIDATION_ERROR"
+ );
+}
+
export function DefaultCatchBoundary({ error }: ErrorComponentProps) {
const router = useRouter();
const isRoot = useMatch({
strict: false,
select: (state) => state.id === rootRouteId,
});
+ const pathname = router.state.location.pathname;
const message = getStandardErrorMessage(
error,
"Something went wrong. Please try again.",
);
const errorCode = getErrorCode(error);
+
+ React.useEffect(() => {
+ if (!shouldCaptureBoundaryError(errorCode)) {
+ return;
+ }
+
+ captureClientError(error, {
+ errorCode,
+ path: pathname,
+ });
+ }, [error, errorCode, pathname]);
+
const showAuthConfigHelp = errorCode === "AUTH_CONFIG_MISSING";
const showSignInHelp = errorCode === "UNAUTHENTICATED";
diff --git a/src/client/lib/posthog.ts b/src/client/lib/posthog.ts
new file mode 100644
index 00000000..62b85384
--- /dev/null
+++ b/src/client/lib/posthog.ts
@@ -0,0 +1,72 @@
+import { isHostedClientAuthMode } from "@/lib/auth-mode";
+
+// Type-only import: extracts the type at compile time without bundling posthog-js
+// oxlint-disable-next-line typescript/consistent-type-imports -- import() type avoids eagerly bundling posthog-js
+type BrowserPostHogClient = typeof import("posthog-js").default;
+
+let browserPostHogClientPromise: Promise<BrowserPostHogClient | null> | null =
+ null;
+let browserPostHogInitialized = false;
+
+function getBrowserPostHogClient(): Promise<BrowserPostHogClient | null> {
+ if (typeof window === "undefined" || !isHostedClientAuthMode()) {
+ return Promise.resolve(null);
+ }
+
+ if (browserPostHogClientPromise) {
+ return browserPostHogClientPromise;
+ }
+
+ // Dynamic import: lazily loads posthog-js only when first needed, keeping it out of the initial bundle
+ browserPostHogClientPromise = import("posthog-js")
+ .then((module) => {
+ const client = module.default;
+ const apiKey = import.meta.env.POSTHOG_PUBLIC_KEY?.trim();
+
+ if (!apiKey) {
+ return null;
+ }
+
+ if (!browserPostHogInitialized) {
+ client.init(apiKey, {
+ api_host:
+ import.meta.env.POSTHOG_HOST?.trim() || "https://us.i.posthog.com",
+ defaults: "2026-01-30",
+ capture_exceptions: true,
+ });
+ browserPostHogInitialized = true;
+ }
+
+ return client;
+ })
+ .catch((error) => {
+ console.error("posthog client init failed", error);
+ return null;
+ });
+
+ return browserPostHogClientPromise;
+}
+
+export function initPostHog() {
+ void getBrowserPostHogClient();
+}
+
+export function captureClientError(
+ error: unknown,
+ properties: Record<string, string | null | undefined> = {},
+) {
+ void getBrowserPostHogClient().then((client) => {
+ if (!client) {
+ return;
+ }
+
+ try {
+ client.captureException(error, {
+ source: "client",
+ ...properties,
+ });
+ } catch (e) {
+ console.error("posthog capture failed", e);
+ }
+ });
+}
diff --git a/src/env.d.ts b/src/env.d.ts
index 78da687f..1e957f0a 100644
--- a/src/env.d.ts
+++ b/src/env.d.ts
@@ -8,6 +8,8 @@ declare namespace Cloudflare {
AUTH_MODE?: "cloudflare_access" | "local_noauth" | "hosted";
TEAM_DOMAIN?: string;
POLICY_AUD?: string;
+ POSTHOG_PUBLIC_KEY?: string;
+ POSTHOG_HOST?: string;
BETTER_AUTH_SECRET?: string;
BETTER_AUTH_URL?: string;
@@ -18,6 +20,8 @@ declare namespace Cloudflare {
interface ImportMetaEnv {
readonly AUTH_MODE?: "cloudflare_access" | "local_noauth" | "hosted";
+ readonly POSTHOG_PUBLIC_KEY?: string;
+ readonly POSTHOG_HOST?: string;
}
interface ImportMeta {
diff --git a/src/middleware/errorHandling.ts b/src/middleware/errorHandling.ts
index e110ac58..cff99e86 100644
--- a/src/middleware/errorHandling.ts
+++ b/src/middleware/errorHandling.ts
@@ -1,5 +1,16 @@
import { createMiddleware } from "@tanstack/react-start";
+import { getRequest } from "@tanstack/react-start/server";
+import { waitUntil } from "cloudflare:workers";
import { asAppError, toClientError } from "@/server/lib/errors";
+import { captureServerError } from "@/server/lib/posthog";
+
+function shouldCaptureServerError(code: string | null | undefined) {
+ return (
+ code !== "UNAUTHENTICATED" &&
+ code !== "NOT_FOUND" &&
+ code !== "VALIDATION_ERROR"
+ );
+}
export const errorHandlingMiddleware = createMiddleware({
type: "function",
@@ -15,8 +26,18 @@ export const errorHandlingMiddleware = createMiddleware({
const appError = asAppError(error);
- if (appError?.code !== "UNAUTHENTICATED") {
+ if (shouldCaptureServerError(appError?.code)) {
+ const request = getRequest();
+ const url = new URL(request.url);
+
console.error("server.function error:", error);
+ waitUntil(
+ captureServerError(error, {
+ errorCode: appError?.code ?? "INTERNAL_ERROR",
+ method: request.method,
+ path: url.pathname,
+ }),
+ );
}
throw toClientError(error);
diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx
index f1da4d36..c8a17494 100644
--- a/src/routes/__root.tsx
+++ b/src/routes/__root.tsx
@@ -11,8 +11,10 @@ import { TanStackDevtools } from "@tanstack/react-devtools";
import { QueryClientProvider } from "@tanstack/react-query";
import * as React from "react";
import { DefaultCatchBoundary } from "@/client/components/DefaultCatchBoundary";
+import { initPostHog } from "@/client/lib/posthog";
import { NotFound } from "@/client/components/NotFound";
import appCss from "@/client/styles/app.css?url";
+import { isHostedClientAuthMode } from "@/lib/auth-mode";
import { Toaster } from "sonner";
import { queryClient } from "@/client/tanstack-db";
@@ -68,6 +70,20 @@ function AppLayout() {
return <Outlet />;
}
+function PostHogBootstrap() {
+ const isHostedMode = isHostedClientAuthMode();
+
+ React.useEffect(() => {
+ if (!isHostedMode) {
+ return;
+ }
+
+ initPostHog();
+ }, [isHostedMode]);
+
+ return null;
+}
+
function RootDocument({ children }: { children: React.ReactNode }) {
const showDevtools =
import.meta.env.DEV && import.meta.env.VITE_SHOW_DEVTOOLS !== "false";
@@ -81,6 +97,7 @@ function RootDocument({ children }: { children: React.ReactNode }) {
<ClientOnly>
<QueryClientProvider client={queryClient}>
<>
+ <PostHogBootstrap />
{children}
<Toaster position="bottom-right" mobileOffset={{ bottom: 100 }} />
{showDevtools ? (
diff --git a/src/server/lib/posthog.ts b/src/server/lib/posthog.ts
new file mode 100644
index 00000000..dec3568c
--- /dev/null
+++ b/src/server/lib/posthog.ts
@@ -0,0 +1,35 @@
+import { env } from "cloudflare:workers";
+import { PostHog } from "posthog-node";
+import { isHostedServerAuthMode } from "@/server/lib/runtime-env";
+
+export async function captureServerError(
+ error: unknown,
+ properties: Record<string, string | null | undefined> = {},
+) {
+ if (!(await isHostedServerAuthMode())) {
+ return;
+ }
+
+ const apiKey = env.POSTHOG_PUBLIC_KEY?.trim();
+
+ if (!apiKey) {
+ return;
+ }
+
+ const client = new PostHog(apiKey, {
+ host: env.POSTHOG_HOST?.trim() || "https://us.i.posthog.com",
+ flushAt: 1,
+ flushInterval: 0,
+ });
+
+ try {
+ await client.captureExceptionImmediate(error, undefined, {
+ source: "server",
+ ...properties,
+ });
+ } catch (posthogError) {
+ console.error("posthog server capture failed", posthogError);
+ } finally {
+ await client.shutdown();
+ }
+}
diff --git a/vite.config.ts b/vite.config.ts
index 08f9376b..22e4dbb3 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -13,7 +13,7 @@ export default defineConfig(({ mode }) => {
const allowedHosts = env.ALLOWED_HOST ? [env.ALLOWED_HOST] : undefined;
return {
- envPrefix: ["VITE_", "AUTH_MODE"],
+ envPrefix: ["VITE_", "AUTH_MODE", "POSTHOG_PUBLIC_KEY", "POSTHOG_HOST"],
server: {
port,
},