From c97b8d8817c232243e9cb08fc85ca0e4efaed749 Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Wed, 1 Nov 2023 12:06:11 -0700 Subject: [PATCH 01/10] demonstration of plausible with goals and custom props --- .../dashboard/_components/ProtocolUploader.tsx | 7 +++++++ .../_components/OnboardSteps/Documentation.tsx | 17 +++++++++++++---- app/layout.tsx | 11 +++++++++++ package.json | 1 + pnpm-lock.yaml | 15 +++++++++++++++ 5 files changed, 47 insertions(+), 4 deletions(-) diff --git a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx index 9c51d867..991f7e43 100644 --- a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx +++ b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx @@ -4,6 +4,7 @@ import { ChevronDown, ChevronUp } from 'lucide-react'; import type { FileWithPath } from 'react-dropzone'; import { generateReactHelpers } from '@uploadthing/react/hooks'; import { useState, useCallback } from 'react'; +import { usePlausible } from 'next-plausible'; import { importProtocol } from '../_actions/importProtocol'; import { Button } from '~/components/ui/Button'; @@ -35,6 +36,7 @@ export default function ProtocolUploader({ progress: true, error: 'dsfsdf', }); + const plausible = usePlausible(); const utils = api.useUtils(); @@ -66,6 +68,11 @@ export default function ProtocolUploader({ } await utils.protocol.get.lastUploaded.refetch(); + plausible('ProtocolImported', { + props: { + installationID: '123', + }, + }); setDialogContent({ title: 'Protocol import', diff --git a/app/(onboard)/_components/OnboardSteps/Documentation.tsx b/app/(onboard)/_components/OnboardSteps/Documentation.tsx index d7317e29..d46ae8b3 100644 --- a/app/(onboard)/_components/OnboardSteps/Documentation.tsx +++ b/app/(onboard)/_components/OnboardSteps/Documentation.tsx @@ -2,8 +2,15 @@ import { Card, CardContent, CardHeader, CardTitle } from '~/components/ui/card'; import { FileText, MonitorPlay } from 'lucide-react'; import { setAppConfigured } from '~/app/_actions'; import SubmitButton from '~/components/ui/SubmitButton'; +import { usePlausible } from 'next-plausible'; function Documentation() { + const plausible = usePlausible(); + const handleAppConfigured = async () => { + await setAppConfigured(); + + plausible('AppSetup', { props: { installationID: '123' } }); + }; return (
@@ -44,10 +51,12 @@ function Documentation() {
-
- - Go to the dashboard! - + +
diff --git a/app/layout.tsx b/app/layout.tsx index 87473e04..e305bc5d 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,6 +6,7 @@ import { getServerSession } from '~/utils/auth'; import { api } from '~/trpc/server'; import { Toaster } from '~/components/ui/toaster'; import { revalidatePath, revalidateTag } from 'next/cache'; +import PlausibleProvider from 'next-plausible'; export const metadata = { title: 'Network Canvas Fresco', @@ -27,6 +28,16 @@ async function RootLayout({ children }: { children: React.ReactNode }) { return ( + + + Date: Thu, 2 Nov 2023 13:01:18 -0700 Subject: [PATCH 02/10] add installationid field and use for plausible --- .../dashboard/_components/ProtocolUploader.tsx | 4 +++- app/(onboard)/_components/OnboardSteps/Documentation.tsx | 8 +++++++- prisma/schema.prisma | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx index 991f7e43..8f9c6109 100644 --- a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx +++ b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx @@ -40,6 +40,8 @@ export default function ProtocolUploader({ const utils = api.useUtils(); + const appSettings = api.appSettings.get.useQuery(); + const handleUploadComplete = async ( res: UploadFileResponse[] | undefined, ) => { @@ -70,7 +72,7 @@ export default function ProtocolUploader({ await utils.protocol.get.lastUploaded.refetch(); plausible('ProtocolImported', { props: { - installationID: '123', + installationID: appSettings?.data?.installationId, }, }); diff --git a/app/(onboard)/_components/OnboardSteps/Documentation.tsx b/app/(onboard)/_components/OnboardSteps/Documentation.tsx index d46ae8b3..86068978 100644 --- a/app/(onboard)/_components/OnboardSteps/Documentation.tsx +++ b/app/(onboard)/_components/OnboardSteps/Documentation.tsx @@ -3,14 +3,20 @@ import { FileText, MonitorPlay } from 'lucide-react'; import { setAppConfigured } from '~/app/_actions'; import SubmitButton from '~/components/ui/SubmitButton'; import { usePlausible } from 'next-plausible'; +import { api } from '~/trpc/client'; function Documentation() { + const appSettings = api.appSettings.get.useQuery(); + const plausible = usePlausible(); const handleAppConfigured = async () => { await setAppConfigured(); - plausible('AppSetup', { props: { installationID: '123' } }); + plausible('AppSetup', { + props: { installationID: appSettings?.data?.installationId }, + }); }; + return (
diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 5ab52397..8c6f8a1e 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -95,6 +95,7 @@ model AppSettings { configured Boolean @default(false) initializedAt DateTime @default(now()) allowAnonymousRecruitment Boolean @default(false) + installationId String @unique @default(cuid()) @@id([configured, initializedAt]) } From 5cafdcdfe74fe7f5d32214c8831d1a2f98c12497 Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Thu, 2 Nov 2023 13:21:09 -0700 Subject: [PATCH 03/10] disable automatic pageview tracking --- app/layout.tsx | 1 + 1 file changed, 1 insertion(+) diff --git a/app/layout.tsx b/app/layout.tsx index e305bc5d..8cad44b6 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -36,6 +36,7 @@ async function RootLayout({ children }: { children: React.ReactNode }) { trackLocalhost={true} enabled={true} taggedEvents={true} + manualPageviews={true} /> From 1101ea38e97eee22705fbdda2c6dbe0fc2af4317 Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Fri, 3 Nov 2023 10:37:40 -0700 Subject: [PATCH 04/10] implement ability for researchers to disaBle analytics --- app/(dashboard)/dashboard/page.tsx | 2 + .../_components/OnboardSteps/Analytics.tsx | 33 +++++++++++++++ app/(onboard)/_components/Sidebar.tsx | 1 + app/(onboard)/setup/page.tsx | 11 +++++ .../AnalyticsSwitch/AnalyticsSwitch.tsx | 11 +++++ components/AnalyticsSwitch/Switch.tsx | 42 +++++++++++++++++++ components/AnalyticsSwitch/action.ts | 7 ++++ prisma/schema.prisma | 3 +- server/routers/appSettings.ts | 17 ++++++++ 9 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 app/(onboard)/_components/OnboardSteps/Analytics.tsx create mode 100644 components/AnalyticsSwitch/AnalyticsSwitch.tsx create mode 100644 components/AnalyticsSwitch/Switch.tsx create mode 100644 components/AnalyticsSwitch/action.ts diff --git a/app/(dashboard)/dashboard/page.tsx b/app/(dashboard)/dashboard/page.tsx index fcd06fd1..30753738 100644 --- a/app/(dashboard)/dashboard/page.tsx +++ b/app/(dashboard)/dashboard/page.tsx @@ -2,6 +2,7 @@ import ResetButton from './_components/ResetButton'; import AnonymousRecruitmentSwitch from '~/components/AnonymousRecruitmentSwitch/AnonymousRecruitmentSwitch'; import Link from 'next/link'; import { Button } from '~/components/ui/Button'; +import AnalyticsSwitch from '~/components/AnalyticsSwitch/AnalyticsSwitch'; function Home() { return ( @@ -14,6 +15,7 @@ function Home() { + ); diff --git a/app/(onboard)/_components/OnboardSteps/Analytics.tsx b/app/(onboard)/_components/OnboardSteps/Analytics.tsx new file mode 100644 index 00000000..abb2bb1d --- /dev/null +++ b/app/(onboard)/_components/OnboardSteps/Analytics.tsx @@ -0,0 +1,33 @@ +'use client'; +import { Button } from '~/components/ui/Button'; +import { useOnboardingContext } from '../OnboardingProvider'; + +function Analytics() { + const { currentStep, setCurrentStep } = useOnboardingContext(); + + const handleNextStep = () => { + setCurrentStep(currentStep + 1).catch(() => {}); + }; + + return ( +
+
+

Analytics

+

+ By default, the app is configured to allow collection of analytics. + This includes number of protocols uploaded, number of interviews + conducted, and number of interviews completed. No personally + identifiable information, interview data, or protocol data is + collected. Analytics collection can be disabled from the dashboard. +

+
+
+
+ +
+
+
+ ); +} + +export default Analytics; diff --git a/app/(onboard)/_components/Sidebar.tsx b/app/(onboard)/_components/Sidebar.tsx index ca6479a1..e930627e 100644 --- a/app/(onboard)/_components/Sidebar.tsx +++ b/app/(onboard)/_components/Sidebar.tsx @@ -8,6 +8,7 @@ const stepLabels = [ 'Create Account', 'Upload Protocol', 'Configure Participation', + 'Analytics', 'Documentation', ]; diff --git a/app/(onboard)/setup/page.tsx b/app/(onboard)/setup/page.tsx index 6103b7cf..420d2b75 100644 --- a/app/(onboard)/setup/page.tsx +++ b/app/(onboard)/setup/page.tsx @@ -34,6 +34,12 @@ const ManageParticipants = dynamic( loading: () => , }, ); +const Analytics = dynamic( + () => import('../_components/OnboardSteps/Analytics'), + { + loading: () => , + }, +); const Documentation = dynamic( () => import('../_components/OnboardSteps/Documentation'), { @@ -104,6 +110,11 @@ function Page() { )} {currentStep === 4 && ( + + + + )} + {currentStep === 5 && ( diff --git a/components/AnalyticsSwitch/AnalyticsSwitch.tsx b/components/AnalyticsSwitch/AnalyticsSwitch.tsx new file mode 100644 index 00000000..0c91f596 --- /dev/null +++ b/components/AnalyticsSwitch/AnalyticsSwitch.tsx @@ -0,0 +1,11 @@ +import { api } from '~/trpc/server'; +import Switch from './Switch'; +import 'server-only'; + +const AnalyticsSwitch = async () => { + const appSettings = await api.appSettings.get.query(); + + return ; +}; + +export default AnalyticsSwitch; diff --git a/components/AnalyticsSwitch/Switch.tsx b/components/AnalyticsSwitch/Switch.tsx new file mode 100644 index 00000000..e379c93f --- /dev/null +++ b/components/AnalyticsSwitch/Switch.tsx @@ -0,0 +1,42 @@ +'use client'; + +import { Switch as SwitchUI } from '~/components/ui/switch'; +import { setAnalytics } from './action'; +import { useOptimistic, useTransition } from 'react'; + +const Switch = ({ allowAnalytics }: { allowAnalytics: boolean }) => { + const [, startTransition] = useTransition(); + const [optimisticAllowAnalytics, setOptimisticAllowAnalytics] = useOptimistic( + allowAnalytics, + (state: boolean, newState: boolean) => newState, + ); + + return ( +
+
+
+

Allow Analytics Reporting

+

+ Information collected includes: number of protocols uploaded, number + of interviews conducted, number of participants recruited, and + number of participants who completed the interview. No personally + identifiable information, interview data, or protocol data is + collected. +

+
+ { + startTransition(async () => { + setOptimisticAllowAnalytics(value); + await setAnalytics(value); + }); + }} + /> +
+
+ ); +}; + +export default Switch; diff --git a/components/AnalyticsSwitch/action.ts b/components/AnalyticsSwitch/action.ts new file mode 100644 index 00000000..8b58fc27 --- /dev/null +++ b/components/AnalyticsSwitch/action.ts @@ -0,0 +1,7 @@ +'use server'; + +import { api } from '~/trpc/server'; + +export async function setAnalytics(state: boolean) { + await api.appSettings.updateAnalytics.mutate(state); +} diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 8c6f8a1e..29686d5a 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -96,6 +96,5 @@ model AppSettings { initializedAt DateTime @default(now()) allowAnonymousRecruitment Boolean @default(false) installationId String @unique @default(cuid()) - - @@id([configured, initializedAt]) + allowAnalytics Boolean @default(true) } diff --git a/server/routers/appSettings.ts b/server/routers/appSettings.ts index ad1cbc71..7c8a829f 100644 --- a/server/routers/appSettings.ts +++ b/server/routers/appSettings.ts @@ -54,6 +54,23 @@ export const appSettingsRouter = router({ revalidateTag('appSettings.get'); + return { error: null, appSettings: updatedappSettings }; + } catch (error) { + return { error: 'Failed to update appSettings', appSettings: null }; + } + }), + updateAnalytics: protectedProcedure + .input(z.boolean()) + .mutation(async ({ input }) => { + try { + const updatedappSettings = await prisma.appSettings.updateMany({ + data: { + allowAnalytics: input, + }, + }); + + revalidateTag('appSettings.get'); + return { error: null, appSettings: updatedappSettings }; } catch (error) { return { error: 'Failed to update appSettings', appSettings: null }; From 507b08230dd76ad1a72d870d98d24735c959dacb Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Fri, 3 Nov 2023 11:13:50 -0700 Subject: [PATCH 05/10] wip add analytics switch to onboarding flow --- app/(onboard)/_components/OnboardSteps/Analytics.tsx | 8 ++++---- components/AnalyticsSwitch/Switch.tsx | 11 +++++------ 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/app/(onboard)/_components/OnboardSteps/Analytics.tsx b/app/(onboard)/_components/OnboardSteps/Analytics.tsx index abb2bb1d..61a282a3 100644 --- a/app/(onboard)/_components/OnboardSteps/Analytics.tsx +++ b/app/(onboard)/_components/OnboardSteps/Analytics.tsx @@ -1,6 +1,7 @@ 'use client'; import { Button } from '~/components/ui/Button'; import { useOnboardingContext } from '../OnboardingProvider'; +import AnalyticsSwitch from '~/components/AnalyticsSwitch/Switch'; function Analytics() { const { currentStep, setCurrentStep } = useOnboardingContext(); @@ -15,13 +16,12 @@ function Analytics() {

Analytics

By default, the app is configured to allow collection of analytics. - This includes number of protocols uploaded, number of interviews - conducted, and number of interviews completed. No personally - identifiable information, interview data, or protocol data is - collected. Analytics collection can be disabled from the dashboard. + Analytics collection can be disabled here or in the app settings on + the dashboard.

+
diff --git a/components/AnalyticsSwitch/Switch.tsx b/components/AnalyticsSwitch/Switch.tsx index e379c93f..6f7829e4 100644 --- a/components/AnalyticsSwitch/Switch.tsx +++ b/components/AnalyticsSwitch/Switch.tsx @@ -15,13 +15,12 @@ const Switch = ({ allowAnalytics }: { allowAnalytics: boolean }) => {
-

Allow Analytics Reporting

+

Allow Analytics

- Information collected includes: number of protocols uploaded, number - of interviews conducted, number of participants recruited, and - number of participants who completed the interview. No personally - identifiable information, interview data, or protocol data is - collected. + Information collected includes the number of protocols uploaded, + interviews conducted, participants recruited, and participants who + completed the interview. No personally identifiable information, + interview data, or protocol data is collected.

Date: Fri, 3 Nov 2023 12:04:15 -0700 Subject: [PATCH 06/10] working set analytics from onboard uses refetch to ensure ui reflects current data. this is causing an issue with the steps routing as it reroutes to step 2 when it revalidates --- .../_components/OnboardSteps/Analytics.tsx | 8 +++++++- components/AnalyticsSwitch/Switch.tsx | 13 ++++++++++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/(onboard)/_components/OnboardSteps/Analytics.tsx b/app/(onboard)/_components/OnboardSteps/Analytics.tsx index 61a282a3..740904c1 100644 --- a/app/(onboard)/_components/OnboardSteps/Analytics.tsx +++ b/app/(onboard)/_components/OnboardSteps/Analytics.tsx @@ -2,6 +2,7 @@ import { Button } from '~/components/ui/Button'; import { useOnboardingContext } from '../OnboardingProvider'; import AnalyticsSwitch from '~/components/AnalyticsSwitch/Switch'; +import { api } from '~/trpc/client'; function Analytics() { const { currentStep, setCurrentStep } = useOnboardingContext(); @@ -10,6 +11,11 @@ function Analytics() { setCurrentStep(currentStep + 1).catch(() => {}); }; + const appSettings = api.appSettings.get.useQuery(undefined, { + onError(error) { + throw new Error(error.message); + }, + }); return (
@@ -21,7 +27,7 @@ function Analytics() {

- +
diff --git a/components/AnalyticsSwitch/Switch.tsx b/components/AnalyticsSwitch/Switch.tsx index 6f7829e4..5c833112 100644 --- a/components/AnalyticsSwitch/Switch.tsx +++ b/components/AnalyticsSwitch/Switch.tsx @@ -3,6 +3,7 @@ import { Switch as SwitchUI } from '~/components/ui/switch'; import { setAnalytics } from './action'; import { useOptimistic, useTransition } from 'react'; +import { api } from '~/trpc/client'; const Switch = ({ allowAnalytics }: { allowAnalytics: boolean }) => { const [, startTransition] = useTransition(); @@ -10,6 +11,7 @@ const Switch = ({ allowAnalytics }: { allowAnalytics: boolean }) => { allowAnalytics, (state: boolean, newState: boolean) => newState, ); + const utils = api.useUtils(); return (
@@ -29,7 +31,16 @@ const Switch = ({ allowAnalytics }: { allowAnalytics: boolean }) => { onCheckedChange={(value) => { startTransition(async () => { setOptimisticAllowAnalytics(value); - await setAnalytics(value); + + try { + await setAnalytics(value); + await utils.appSettings.get.refetch(); + } catch (error) { + if (error instanceof Error) { + throw new Error(error.message); + } + throw new Error('Something went wrong'); + } }); }} /> From aa4bf5e98744435fb747fb1d4cdf26dfc848722e Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Fri, 3 Nov 2023 12:47:51 -0700 Subject: [PATCH 07/10] fix issue where onboard was redirecting to step 2 --- .../_components/OnboardSteps/Documentation.tsx | 10 ++++------ app/layout.tsx | 2 -- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/app/(onboard)/_components/OnboardSteps/Documentation.tsx b/app/(onboard)/_components/OnboardSteps/Documentation.tsx index 86068978..6d87b467 100644 --- a/app/(onboard)/_components/OnboardSteps/Documentation.tsx +++ b/app/(onboard)/_components/OnboardSteps/Documentation.tsx @@ -57,12 +57,10 @@ function Documentation() {
-
- + + + Go to the dashboard! +
diff --git a/app/layout.tsx b/app/layout.tsx index 8cad44b6..f19f9b92 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -30,8 +30,6 @@ async function RootLayout({ children }: { children: React.ReactNode }) { Date: Fri, 3 Nov 2023 14:17:51 -0700 Subject: [PATCH 08/10] enabled is false if setting is disabled also adds commented out props for when we switch to selfhosted --- app/layout.tsx | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/layout.tsx b/app/layout.tsx index f19f9b92..d45353b5 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -7,6 +7,7 @@ import { api } from '~/trpc/server'; import { Toaster } from '~/components/ui/toaster'; import { revalidatePath, revalidateTag } from 'next/cache'; import PlausibleProvider from 'next-plausible'; +import { env } from '~/env.mjs'; export const metadata = { title: 'Network Canvas Fresco', @@ -31,10 +32,14 @@ async function RootLayout({ children }: { children: React.ReactNode }) { From 255e821d3c43b7e4e4678ce14e5856c522c222eb Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Mon, 6 Nov 2023 09:49:12 -0800 Subject: [PATCH 09/10] custom useAnalytics hook, move plausibleprovider to proviers --- .../_components/ProtocolUploader.tsx | 13 ++++-------- .../OnboardSteps/Documentation.tsx | 8 +++---- app/layout.tsx | 15 ------------- hooks/useAnalytics.ts | 13 ++++++++++++ providers/Providers.tsx | 21 +++++++++++++++++-- 5 files changed, 39 insertions(+), 31 deletions(-) create mode 100644 hooks/useAnalytics.ts diff --git a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx index 8f9c6109..db49eeb9 100644 --- a/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx +++ b/app/(dashboard)/dashboard/_components/ProtocolUploader.tsx @@ -4,8 +4,6 @@ import { ChevronDown, ChevronUp } from 'lucide-react'; import type { FileWithPath } from 'react-dropzone'; import { generateReactHelpers } from '@uploadthing/react/hooks'; import { useState, useCallback } from 'react'; -import { usePlausible } from 'next-plausible'; - import { importProtocol } from '../_actions/importProtocol'; import { Button } from '~/components/ui/Button'; @@ -22,6 +20,7 @@ import type { UploadFileResponse } from 'uploadthing/client'; import { Collapsible, CollapsibleContent } from '~/components/ui/collapsible'; import ActiveProtocolSwitch from '~/app/(dashboard)/dashboard/_components/ActiveProtocolSwitch'; import { api } from '~/trpc/client'; +import { useAnalytics } from '~/hooks/useAnalytics'; export default function ProtocolUploader({ onUploaded, @@ -36,11 +35,10 @@ export default function ProtocolUploader({ progress: true, error: 'dsfsdf', }); - const plausible = usePlausible(); const utils = api.useUtils(); - const appSettings = api.appSettings.get.useQuery(); + const trackEvent = useAnalytics(); const handleUploadComplete = async ( res: UploadFileResponse[] | undefined, @@ -70,11 +68,8 @@ export default function ProtocolUploader({ } await utils.protocol.get.lastUploaded.refetch(); - plausible('ProtocolImported', { - props: { - installationID: appSettings?.data?.installationId, - }, - }); + + trackEvent('ProtocolImported', appSettings?.data?.installationId); setDialogContent({ title: 'Protocol import', diff --git a/app/(onboard)/_components/OnboardSteps/Documentation.tsx b/app/(onboard)/_components/OnboardSteps/Documentation.tsx index 6d87b467..43f480b9 100644 --- a/app/(onboard)/_components/OnboardSteps/Documentation.tsx +++ b/app/(onboard)/_components/OnboardSteps/Documentation.tsx @@ -2,19 +2,17 @@ import { Card, CardContent, CardHeader, CardTitle } from '~/components/ui/card'; import { FileText, MonitorPlay } from 'lucide-react'; import { setAppConfigured } from '~/app/_actions'; import SubmitButton from '~/components/ui/SubmitButton'; -import { usePlausible } from 'next-plausible'; import { api } from '~/trpc/client'; +import { useAnalytics } from '~/hooks/useAnalytics'; function Documentation() { const appSettings = api.appSettings.get.useQuery(); + const trackEvent = useAnalytics(); - const plausible = usePlausible(); const handleAppConfigured = async () => { await setAppConfigured(); - plausible('AppSetup', { - props: { installationID: appSettings?.data?.installationId }, - }); + trackEvent('AppSetup', appSettings?.data?.installationId); }; return ( diff --git a/app/layout.tsx b/app/layout.tsx index d45353b5..87473e04 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -6,8 +6,6 @@ import { getServerSession } from '~/utils/auth'; import { api } from '~/trpc/server'; import { Toaster } from '~/components/ui/toaster'; import { revalidatePath, revalidateTag } from 'next/cache'; -import PlausibleProvider from 'next-plausible'; -import { env } from '~/env.mjs'; export const metadata = { title: 'Network Canvas Fresco', @@ -29,19 +27,6 @@ async function RootLayout({ children }: { children: React.ReactNode }) { return ( - - - { + installationId + ? plausible(eventName, { props: { installationId } }) + : plausible(eventName); + }; + + return trackEvent; +} diff --git a/providers/Providers.tsx b/providers/Providers.tsx index 23243794..001c72ec 100644 --- a/providers/Providers.tsx +++ b/providers/Providers.tsx @@ -4,18 +4,35 @@ import { TRPCReactProvider } from '~/trpc/client'; import { SessionProvider } from '~/providers/SessionProvider'; import type { Session } from 'lucia'; import { headers } from 'next/headers'; +import PlausibleProvider from 'next-plausible'; +import { env } from 'process'; +import { api } from '~/trpc/server'; -export default function Providers({ +export default async function Providers({ children, initialSession, }: { children: React.ReactNode; initialSession: Session | null; -}): ReactElement { +}): Promise { + const appSettings = await api.appSettings.get.query(); + return ( {children} + ); } From 9f718b7660894c389be0e593cbe87bd142074b4a Mon Sep 17 00:00:00 2001 From: Caden Buckhalt Date: Mon, 6 Nov 2023 13:19:31 -0800 Subject: [PATCH 10/10] switch to self hosted --- providers/Providers.tsx | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/providers/Providers.tsx b/providers/Providers.tsx index 001c72ec..d51281fe 100644 --- a/providers/Providers.tsx +++ b/providers/Providers.tsx @@ -29,9 +29,8 @@ export default async function Providers({ enabled={appSettings?.allowAnalytics} // for production, add env.NODE_ENV === 'production' to disable tracking in dev //enabled={appSettings?.allowAnalytics && env.NODE_ENV === 'production'} - // Uncomment the following lines to use self hosted - // selfHosted={true} - // customDomain="https://analytics.networkcanvas.com" + selfHosted={true} + customDomain="https://analytics.networkcanvas.dev" /> );