mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add Plausible Analytics integration with AppConfig support
This commit is contained in:
13 files changed
+191
-2
No files matched your search
+7
-2
@@ -15,6 +15,7 @@ import { AppProvider } from '@/components/AppProvider';
|
||||
import { AppConfig } from '@/contexts/AppContext';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
import { SentryProvider } from '@/components/SentryProvider';
|
||||
import { PlausibleProvider } from '@/components/PlausibleProvider';
|
||||
import { AISettingsProvider } from '@/components/AISettingsProvider';
|
||||
import { GitSettingsProvider } from '@/components/GitSettingsProvider';
|
||||
import { DeploySettingsProvider } from '@/components/DeploySettingsProvider';
|
||||
@@ -87,6 +88,8 @@ const defaultConfig: AppConfig = {
|
||||
fsPathTemplates: "/templates",
|
||||
sentryDsn: import.meta.env.VITE_SENTRY_DSN || "",
|
||||
sentryEnabled: true,
|
||||
plausibleDomain: import.meta.env.VITE_PLAUSIBLE_DOMAIN || "",
|
||||
plausibleEndpoint: import.meta.env.VITE_PLAUSIBLE_ENDPOINT || "",
|
||||
};
|
||||
|
||||
// Initialize filesystem adapter
|
||||
@@ -131,7 +134,8 @@ export function App() {
|
||||
<UnheadProvider head={head}>
|
||||
<QueryClientProvider client={queryClient}>
|
||||
<AppProvider storageKey="nostr:app-config" defaultConfig={defaultConfig}>
|
||||
<SentryProvider>
|
||||
<PlausibleProvider>
|
||||
<SentryProvider>
|
||||
<FSProvider fs={fs}>
|
||||
<ConsoleErrorProvider>
|
||||
<FSCleanupHandler />
|
||||
@@ -162,7 +166,8 @@ export function App() {
|
||||
</NostrLoginProvider>
|
||||
</ConsoleErrorProvider>
|
||||
</FSProvider>
|
||||
</SentryProvider>
|
||||
</SentryProvider>
|
||||
</PlausibleProvider>
|
||||
</AppProvider>
|
||||
</QueryClientProvider>
|
||||
</UnheadProvider>
|
||||
|
||||
@@ -60,6 +60,8 @@ const AppConfigSchema = z.object({
|
||||
sentryDsn: z.string(),
|
||||
sentryEnabled: z.boolean(),
|
||||
systemPrompt: z.string(),
|
||||
plausibleDomain: z.string(),
|
||||
plausibleEndpoint: z.string(),
|
||||
}) satisfies z.ZodType<AppConfig>;
|
||||
|
||||
export function AppProvider(props: AppProviderProps) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { ReactNode, useEffect, useRef } from 'react';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
interface PlausibleProviderProps {
|
||||
children: ReactNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactively initializes Plausible Analytics from AppConfig.
|
||||
* Plausible's `init()` can only be called once, so we guard with a ref.
|
||||
*/
|
||||
export function PlausibleProvider({ children }: PlausibleProviderProps) {
|
||||
const { config } = useAppContext();
|
||||
const initializedRef = useRef(false);
|
||||
|
||||
useEffect(() => {
|
||||
if (initializedRef.current || !config.plausibleDomain) return;
|
||||
initializedRef.current = true;
|
||||
|
||||
import('@plausible-analytics/tracker').then(({ init }) => {
|
||||
init({
|
||||
domain: config.plausibleDomain,
|
||||
...(config.plausibleEndpoint && { endpoint: config.plausibleEndpoint }),
|
||||
});
|
||||
}).catch(console.error);
|
||||
}, [config.plausibleDomain, config.plausibleEndpoint]);
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
||||
@@ -45,6 +45,8 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -87,6 +89,8 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -130,6 +134,8 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
render(
|
||||
@@ -176,6 +182,8 @@ describe('SentryProvider', () => {
|
||||
fsPathTmp: '/tmp',
|
||||
fsPathPlugins: '/plugins',
|
||||
fsPathTemplates: '/templates',
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
render(
|
||||
|
||||
@@ -68,6 +68,10 @@ export interface AppConfig {
|
||||
sentryEnabled: boolean;
|
||||
/** System prompt EJS template */
|
||||
systemPrompt?: string;
|
||||
/** Plausible Analytics domain (empty string = disabled). */
|
||||
plausibleDomain: string;
|
||||
/** Plausible Analytics API endpoint (empty string = use default). */
|
||||
plausibleEndpoint: string;
|
||||
}
|
||||
|
||||
export interface AppContextType {
|
||||
|
||||
@@ -80,6 +80,8 @@ describe('useGenerateProjectInfo', () => {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
mockUseAppContext.mockReturnValue({
|
||||
config,
|
||||
@@ -242,6 +244,8 @@ describe('useGenerateProjectInfo', () => {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
mockUseAppContext.mockReturnValue({
|
||||
config,
|
||||
|
||||
@@ -54,6 +54,8 @@ function createWrapper(corsProxy: string) {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
return createElement(
|
||||
|
||||
@@ -58,6 +58,8 @@ const testConfig: AppConfig = {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
describe('SessionManager', () => {
|
||||
|
||||
@@ -45,6 +45,8 @@ const testConfig: AppConfig = {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
describe('makeSystemPrompt', () => {
|
||||
|
||||
@@ -65,6 +65,8 @@ export function TestApp({ children }: TestAppProps) {
|
||||
fsPathTemplates: '/templates',
|
||||
sentryDsn: '',
|
||||
sentryEnabled: false,
|
||||
plausibleDomain: '',
|
||||
plausibleEndpoint: '',
|
||||
};
|
||||
|
||||
// Initialize LightningFS for testing
|
||||
|
||||
Reference in new issue
Block a user