-
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
Open
DarianM
wants to merge
22
commits into
main
Choose a base branch
from
analytics
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
723048c
set up analytics
DarianM 42b3632
forgot to add banner
DarianM f3ca1f3
move provider to root
DarianM 6636891
remove it
DarianM 5e858a5
port closer to localenv ports
DarianM 3d3c708
rename
DarianM 6b8d0d3
build time const
DarianM c862f9b
add track event tool card click
DarianM f842ba3
format
DarianM 8ac94d7
nit rename
DarianM 000474b
use loadEveFile instead
DarianM 017cdbd
keep card click event clean
DarianM 597a662
nit rename
DarianM 8eabe6d
handler tool from provider directly
DarianM 53d8e34
rename to analytics
DarianM 70206de
make sure we've right metadata types only
DarianM c967e30
of course it works
DarianM 554bdd1
add scripts
DarianM f50c200
add data-domains script tag
DarianM 21fe3c0
update vscode tasks to include analytics
DarianM cf1f792
change commands name
DarianM 824cdfc
change data-domains atr
DarianM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| import { createContext, useCallback, useContext } from 'react' | ||
| import type { ReactNode } from 'react' | ||
| import type { Tool } from '@shared/types' | ||
|
|
||
| type TrackFn = (eventName: string, eventData?: Record<string, unknown>) => void | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| const TrackContext = createContext<TrackFn>(() => {}) | ||
|
|
||
| export function TrackProvider({ | ||
| tool, | ||
| children, | ||
| }: { | ||
| tool: Tool | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| children: ReactNode | ||
| }) { | ||
| const track = useCallback( | ||
| (eventName: string, eventData?: Record<string, unknown>) => { | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| window.umami?.track(eventName, { tool, ...eventData }) | ||
| }, | ||
| [tool], | ||
| ) | ||
| return <TrackContext.Provider value={track}>{children}</TrackContext.Provider> | ||
| } | ||
|
|
||
| export function useTrack(): TrackFn { | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return useContext(TrackContext) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,9 +6,11 @@ import { | |
| Scripts, | ||
| ScrollRestoration, | ||
| useRouteError, | ||
| useLoaderData, | ||
| isRouteErrorResponse, | ||
| type LinksFunction, | ||
| type MetaFunction, | ||
| type LoaderFunctionArgs, | ||
| } from 'react-router' | ||
| import { Header, Footer } from '@/components' | ||
| import faviconSvg from '~/assets/images/favicon.svg?url' | ||
|
|
@@ -17,14 +19,32 @@ import stylesheet from '~/tailwind.css?url' | |
| import { XCircle } from './components/icons.js' | ||
| import { Button } from './components/index.js' | ||
|
|
||
| export async function loader({ context }: LoaderFunctionArgs) { | ||
| const { env } = context.cloudflare | ||
| return { | ||
| CONFIG_UMAMI_HOST: env.UMAMI_HOST || '', | ||
| CONFIG_UMAMI_WEBSITE_ID: env.UMAMI_WEBSITE_ID || '', | ||
| } | ||
| } | ||
|
|
||
| export default function App() { | ||
| const { CONFIG_UMAMI_HOST, CONFIG_UMAMI_WEBSITE_ID } = | ||
| useLoaderData<typeof loader>() | ||
|
|
||
| return ( | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charSet="utf-8" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <Meta /> | ||
| <Links /> | ||
| {CONFIG_UMAMI_HOST && CONFIG_UMAMI_WEBSITE_ID && ( | ||
| <script | ||
| defer | ||
| src={`${CONFIG_UMAMI_HOST}/script.js`} | ||
| data-website-id={CONFIG_UMAMI_WEBSITE_ID} | ||
| /> | ||
| )} | ||
|
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> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
| - '3001:3000' | ||
sidvishnoi marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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: | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.