-
Notifications
You must be signed in to change notification settings - Fork 12
feat(frontend): set up Umami for events data collection #651
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 18 commits
723048c
42b3632
f3ca1f3
6636891
5e858a5
3d3c708
6b8d0d3
c862f9b
f842ba3
8ac94d7
000474b
017cdbd
597a662
8eabe6d
53d8e34
70206de
c967e30
554bdd1
f50c200
21fe3c0
cf1f792
824cdfc
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import { createContext, useCallback, useContext } from 'react' | ||
| import type { ReactNode } from 'react' | ||
| import { useLocation } from 'react-router' | ||
| import { TOOLS } from '@shared/types' | ||
|
|
||
| type TrackFn = ( | ||
| eventName: string, | ||
| eventData?: Record<string, string | number | boolean | null>, | ||
| ) => void | ||
|
|
||
| const TrackContext = createContext<TrackFn>(() => {}) | ||
|
|
||
| export function TelemetryProvider({ children }: { children: ReactNode }) { | ||
| const { pathname } = useLocation() | ||
| const tool = TOOLS.find((t) => pathname.startsWith(`/${t}`)) | ||
|
|
||
| const track = useCallback<TrackFn>( | ||
| (eventName, eventData) => { | ||
| window.umami?.track(eventName, tool ? { tool, ...eventData } : eventData) | ||
| }, | ||
| [tool], | ||
| ) | ||
| return <TrackContext.Provider value={track}>{children}</TrackContext.Provider> | ||
| } | ||
|
|
||
| export function useTrackEvent(): TrackFn { | ||
| return useContext(TrackContext) | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,7 +11,9 @@ import { | |
| type MetaFunction, | ||
| } from 'react-router' | ||
| import { Header, Footer } from '@/components' | ||
| import { UMAMI_HOST, UMAMI_WEBSITE_ID } from '@shared/defines' | ||
| import faviconSvg from '~/assets/images/favicon.svg?url' | ||
| import { TelemetryProvider } from '~/lib/analytics' | ||
| import { UIProvider } from '~/stores/uiStore' | ||
| import stylesheet from '~/tailwind.css?url' | ||
| import { XCircle } from './components/icons.js' | ||
|
|
@@ -25,12 +27,21 @@ export default function App() { | |
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <Meta /> | ||
| <Links /> | ||
| {UMAMI_HOST && UMAMI_WEBSITE_ID && ( | ||
| <script | ||
| defer | ||
| src={`${UMAMI_HOST}/script.js`} | ||
| data-website-id={UMAMI_WEBSITE_ID} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I noticed. web mon sets
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When we set up these vars in GitHub (CI), they'll end up setting for both staging/previews and production.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right, then we need to specify |
||
| /> | ||
| )} | ||
|
Comment on lines
+36
to
+43
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: with this script injection here, do you think we should do any checks to make sure the URLs aren't malformed? |
||
| </head> | ||
| <body className="h-screen bg-interface-bg-main flex flex-col"> | ||
| <UIProvider> | ||
| <Header /> | ||
| <main className="flex-grow flex flex-col"> | ||
| <Outlet /> | ||
| <TelemetryProvider> | ||
| <Outlet /> | ||
| </TelemetryProvider> | ||
| </main> | ||
| <Footer /> | ||
| </UIProvider> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| services: | ||
| umami-db: | ||
| image: postgres:15-alpine | ||
| environment: | ||
| POSTGRES_DB: umami | ||
| POSTGRES_USER: umami | ||
| POSTGRES_PASSWORD: umami_local_password | ||
| volumes: | ||
| - umami-db-data:/var/lib/postgresql/data | ||
| healthcheck: | ||
| test: ['CMD-SHELL', 'pg_isready -U umami'] | ||
| interval: 5s | ||
| timeout: 5s | ||
| retries: 5 | ||
|
|
||
| umami: | ||
| image: ghcr.io/umami-software/umami:postgresql-latest | ||
| ports: | ||
| - '8082:3000' | ||
| environment: | ||
| DATABASE_URL: postgresql://umami:umami_local_password@umami-db:5432/umami | ||
| APP_SECRET: local_dev_secret | ||
| depends_on: | ||
| umami-db: | ||
| condition: service_healthy | ||
|
|
||
| volumes: | ||
| umami-db-data: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| { | ||
| "name": "localenv-analytics", | ||
| "version": "1.0.0", | ||
| "private": true, | ||
| "scripts": { | ||
| "start": "docker compose up -d", | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| "stop": "docker compose down" | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,7 +16,9 @@ | |
| "lint": "eslint . --fix --cache --cache-location 'node_modules/.cache/eslintcache'", | ||
| "lint:check": "eslint . --cache --cache-location 'node_modules/.cache/eslintcache'", | ||
| "typecheck": "pnpm -r typecheck", | ||
| "test": "pnpm -r test" | ||
| "test": "pnpm -r test", | ||
| "analytics:start": "pnpm --filter localenv-analytics start", | ||
| "analytics:stop": "pnpm --filter localenv-analytics stop" | ||
|
||
| }, | ||
| "devDependencies": { | ||
| "@eslint/js": "^9.39.4", | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could be a later add, but thinking keeping the events in a separate file with a const map of event names as more events get added