diff --git a/.env.example b/.env.example new file mode 100644 index 0000000..c130e40 --- /dev/null +++ b/.env.example @@ -0,0 +1,2 @@ +VITE_SENTRY_DSN= +VITE_POSTHOG_KEY= diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index a41e989..f32a121 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -36,6 +36,9 @@ jobs: run: pnpm install - name: Build run: pnpm build + env: + VITE_SENTRY_DSN: ${{ secrets.SENTRY_DSN }} + VITE_POSTHOG_KEY: ${{ secrets.POSTHOG_KEY }} - name: Archive Release uses: thedoctor0/zip-release@0.7.6 with: diff --git a/package.json b/package.json index 710ef94..b510b94 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "lucide-react": "^0.334.0", + "posthog-js": "^1.161.3", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hook-form": "^7.51.2", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a081534..ea1712a 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -62,6 +62,9 @@ importers: lucide-react: specifier: ^0.334.0 version: 0.334.0(react@18.2.0) + posthog-js: + specifier: ^1.161.3 + version: 1.161.3 react: specifier: ^18.2.0 version: 18.2.0 @@ -1781,6 +1784,9 @@ packages: fastq@1.17.1: resolution: {integrity: sha512-sRVD3lWVIXWg6By68ZN7vho9a1pQcN/WBFaAAsDDFzlJjvoGx0P8z7V1t72grFJfJhu3YPZBuu25f7Kaw2jN1w==} + fflate@0.4.8: + resolution: {integrity: sha512-FJqqoDBR00Mdj9ppamLa/Y7vxm+PRmNWA67N846RvsoYVMKB4q3y/de5PA7gUmRMYK/8CMz2GDZQmCRN1wBcWA==} + file-entry-cache@6.0.1: resolution: {integrity: sha512-7Gps/XWymbLk2QLYK4NzpMOrYjMhdIxXuIvy2QBsLE6ljuodKvdkWs/cpyJJ3CVIVpH0Oi1Hvg1ovbMzLdFBBg==} engines: {node: ^10.12.0 || >=12.0.0} @@ -2365,6 +2371,12 @@ packages: resolution: {integrity: sha512-Wglpdk03BSfXkHoQa3b/oulrotAkwrlLDRSOb9D0bN86FdRyE9lppSp33aHNPgBa0JKCoB+drFLZkQoRRYae5A==} engines: {node: ^10 || ^12 || >=14} + posthog-js@1.161.3: + resolution: {integrity: sha512-TQ77jtLemkUJUyJAPrwGay6tLqcAmXEM1IJgXOx5Tr4UohiTx8JTznzrCuh/SdwPIrbcSM1r2YPwb72XwTC3wg==} + + preact@10.23.2: + resolution: {integrity: sha512-kKYfePf9rzKnxOAKDpsWhg/ysrHPqT+yQ7UW4JjdnqjFIeNUnNcEJvhuA8fDenxAGWzUqtd51DfVg7xp/8T9NA==} + prelude-ls@1.2.1: resolution: {integrity: sha512-vkcDPrRZo1QZLbn5RLGPpg/WmIQ65qoWWhcGKf/b5eplkkarX0m9z8ppCat4mlOqUsWpyNuYgO3VRyrYHSzX5g==} engines: {node: '>= 0.8.0'} @@ -2774,6 +2786,9 @@ packages: terser: optional: true + web-vitals@4.2.3: + resolution: {integrity: sha512-/CFAm1mNxSmOj6i0Co+iGFJ58OS4NRGVP+AWS/l509uIK5a1bSoIVaHz/ZumpHTfHSZBpgrJ+wjfpAOrTHok5Q==} + webidl-conversions@3.0.1: resolution: {integrity: sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==} @@ -4695,6 +4710,8 @@ snapshots: dependencies: reusify: 1.0.4 + fflate@0.4.8: {} + file-entry-cache@6.0.1: dependencies: flat-cache: 3.2.0 @@ -5245,6 +5262,14 @@ snapshots: picocolors: 1.0.0 source-map-js: 1.2.0 + posthog-js@1.161.3: + dependencies: + fflate: 0.4.8 + preact: 10.23.2 + web-vitals: 4.2.3 + + preact@10.23.2: {} + prelude-ls@1.2.1: {} prettier-linter-helpers@1.0.0: @@ -5709,6 +5734,8 @@ snapshots: '@types/node': 20.12.4 fsevents: 2.3.3 + web-vitals@4.2.3: {} + webidl-conversions@3.0.1: {} webpack-sources@3.2.3: {} diff --git a/src/main.tsx b/src/main.tsx index 1d04eca..c529546 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,6 +1,8 @@ import * as Sentry from '@sentry/react' import { QueryClient, QueryClientProvider } from '@tanstack/react-query' import { RouterProvider, createRouter } from '@tanstack/react-router' +import { PostHogConfig } from 'posthog-js' +import { PostHogProvider } from 'posthog-js/react' import { StrictMode } from 'react' import ReactDOM from 'react-dom/client' @@ -52,18 +54,28 @@ Sentry.init({ profilesSampleRate: 1.0, }) +const postHogConfig = { + apiKey: import.meta.env.VITE_POSTHOG_KEY as string, + options: { + person_profiles: 'identified_only', + capture_pageview: false, + } as PostHogConfig, +} + const rootElement = document.getElementById('root')! if (!rootElement.innerHTML) { const root = ReactDOM.createRoot(rootElement) root.render( - - - - - - - + + + + + + + + + , ) } diff --git a/src/routes/__root.tsx b/src/routes/__root.tsx index 67fe6c1..b121e27 100644 --- a/src/routes/__root.tsx +++ b/src/routes/__root.tsx @@ -1,6 +1,7 @@ import * as Sentry from '@sentry/react' import { useQueryClient } from '@tanstack/react-query' import { createRootRoute, Outlet } from '@tanstack/react-router' +import posthog from 'posthog-js' import { useEffect } from 'react' import { BottomBar } from '@/components/bottom-bar' @@ -22,6 +23,9 @@ import { cn, errorToast } from '@/lib/utils' export const Route = createRootRoute({ component: Root, + beforeLoad: (route) => { + posthog.capture('$pageview', { path: route.location.pathname }) + }, }) interface CardinalEvent {