Skip to content
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

chore: add desktop app analytics #978

Merged
merged 1 commit into from
Dec 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions web/containers/Providers/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import { Toaster } from 'react-hot-toast'

import { TooltipProvider } from '@janhq/uikit'

import { PostHogProvider } from 'posthog-js/react'

import EventListenerWrapper from '@/containers/Providers/EventListener'
import JotaiWrapper from '@/containers/Providers/Jotai'
import ThemeWrapper from '@/containers/Providers/Theme'
Expand All @@ -18,6 +20,8 @@ import {
setupBaseExtensions,
} from '@/services/extensionService'

import { instance } from '@/utils/posthog'

import { extensionManager } from '@/extension'

const Providers = (props: PropsWithChildren) => {
Expand Down Expand Up @@ -63,18 +67,20 @@ const Providers = (props: PropsWithChildren) => {
}, [setupCore])

return (
<JotaiWrapper>
<ThemeWrapper>
{setupCore && activated && (
<FeatureToggleWrapper>
<EventListenerWrapper>
<TooltipProvider>{children}</TooltipProvider>
</EventListenerWrapper>
<Toaster position="top-right" />
</FeatureToggleWrapper>
)}
</ThemeWrapper>
</JotaiWrapper>
<PostHogProvider client={instance}>
<JotaiWrapper>
<ThemeWrapper>
{setupCore && activated && (
<FeatureToggleWrapper>
<EventListenerWrapper>
<TooltipProvider>{children}</TooltipProvider>
</EventListenerWrapper>
<Toaster position="top-right" />
</FeatureToggleWrapper>
)}
</ThemeWrapper>
</JotaiWrapper>
</PostHogProvider>
)
}

Expand Down
6 changes: 6 additions & 0 deletions web/next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ const nextConfig = {
'https://cdn.jsdelivr.net/npm/@janhq/plugin-catalog@latest/dist/index.js'
),
VERSION: JSON.stringify(packageJson.version),
ANALYTICS_ID:
process.env.ANALYTICS_ID ??
JSON.stringify('phc_cJ95zWbMwdef6nVasPCoSNOvV8lUcL5IykIYOoyGXVm'),
ANALYTICS_HOST:
process.env.ANALYTICS_HOST ??
JSON.stringify('https://app.posthog.com'),
}),
]
return config
Expand Down
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"next": "14.0.1",
"next-themes": "^0.2.1",
"postcss": "8.4.31",
"posthog-js": "^1.95.1",
"react": "18.2.0",
"react-dom": "18.2.0",
"react-hook-form": "^7.47.0",
Expand Down
2 changes: 2 additions & 0 deletions web/types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ export {}
declare global {
declare const PLUGIN_CATALOG: string
declare const VERSION: string
declare const ANALYTICS_ID: string
declare const ANALYTICS_HOST: string
interface Core {
api: APIFunctions
events: EventEmitter
Expand Down
15 changes: 15 additions & 0 deletions web/utils/posthog.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import posthog, { Properties } from 'posthog-js'

posthog.init(ANALYTICS_ID, {
api_host: ANALYTICS_HOST,
})

export const instance = posthog

// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const trackEvent = (name: string, properties?: Properties) => {
posthog.capture(name, properties)
}

export enum AnalyticsEvent {
}
Loading