diff --git a/apps/backend/app/src/app.ts b/apps/backend/app/src/app.ts index f29c4512..65f8f347 100644 --- a/apps/backend/app/src/app.ts +++ b/apps/backend/app/src/app.ts @@ -18,6 +18,7 @@ const appService = createPlugin(async (fastify) => { PUBLIC_API_URL: fastify.config.PUBLIC_API_URL, PUBLIC_COLLAB_URL: fastify.config.PUBLIC_COLLAB_URL, PUBLIC_ASSETS_URL: fastify.config.PUBLIC_ASSETS_URL, + PUBLIC_POSTHOG_TOKEN: fastify.config.PUBLIC_POSTHOG_TOKEN, PUBLIC_DISABLE_ANALYTICS: fastify.config.PUBLIC_DISABLE_ANALYTICS }); }; diff --git a/apps/web/index.html b/apps/web/index.html index d6025c3e..0df69445 100644 --- a/apps/web/index.html +++ b/apps/web/index.html @@ -39,6 +39,7 @@ PUBLIC_APP_URL: "{{PUBLIC_APP_URL}}", PUBLIC_ASSETS_URL: "{{PUBLIC_ASSETS_URL}}", PUBLIC_COLLAB_URL: "{{PUBLIC_COLLAB_URL}}", + PUBLIC_POSTHOG_TOKEN: "{{PUBLIC_POSTHOG_TOKEN}}", PUBLIC_DISABLE_ANALYTICS: "{{PUBLIC_DISABLE_ANALYTICS}}" }; diff --git a/apps/web/package.json b/apps/web/package.json index b52d5574..8ed773f8 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -59,7 +59,7 @@ "monaco-editor": "^0.45.0", "nanoevents": "^9.0.0", "nanoid": "^5.0.5", - "posthog-js": "^1.126.0", + "posthog-js": "^1.136.2", "prettier": "^3.2.5", "seamless-scroll-polyfill": "^2.3.4", "solid-js": "^1.8.14", diff --git a/apps/web/src/layout/secured-layout.tsx b/apps/web/src/layout/secured-layout.tsx index 00c74742..2003c8d4 100644 --- a/apps/web/src/layout/secured-layout.tsx +++ b/apps/web/src/layout/secured-layout.tsx @@ -4,7 +4,7 @@ import { SidebarMenu } from "./sidebar-menu"; import { BottomMenu } from "./bottom-menu"; import { SidePanelRight } from "./side-panel-right"; import { WalkthroughProvider } from "./walkthrough"; -import { ParentComponent, Show, createEffect } from "solid-js"; +import { Component, ParentComponent, Show, createEffect } from "solid-js"; import { useLocation } from "@solidjs/router"; import { mdiFullscreenExit } from "@mdi/js"; import clsx from "clsx"; @@ -16,22 +16,37 @@ import { CommandPaletteProvider, ContentDataProvider, useLocalStorage, - useHostConfig + useHostConfig, + useAuthenticatedUserData } from "#context"; import { IconButton, Tooltip } from "#components/primitives"; import { SubscriptionBanner } from "#ee"; -const SecuredLayout: ParentComponent = (props) => { - const { storage, setStorage } = useLocalStorage(); +const Analytics: Component = () => { + const { profile, workspace } = useAuthenticatedUserData(); const hostConfig = useHostConfig(); - const location = useLocation(); if (import.meta.env.PROD && hostConfig.analytics) { - posthog.init("phc_m9JcBa51gXCkGdLFtqeMZXFfJkuSTg8C9iDMun0sZgg", { - api_host: "https://app.posthog.com" + posthog.init(window.env.PUBLIC_POSTHOG_TOKEN, { + ui_host: "https://app.posthog.com", + api_host: "https://posthog.vrite.io" + }); + posthog.identify(profile()!.id, { + email: profile()!.email, + username: profile()!.username + }); + posthog.group("workspace", workspace()!.id, { + name: workspace()!.name }); } + return <>; +}; +const SecuredLayout: ParentComponent = (props) => { + const { storage, setStorage } = useLocalStorage(); + const hostConfig = useHostConfig(); + const location = useLocation(); + createEffect(() => { if (location.pathname !== "/editor") { setStorage((storage) => ({ ...storage, zenMode: false })); @@ -40,6 +55,7 @@ const SecuredLayout: ParentComponent = (props) => { return ( + diff --git a/apps/web/src/typings.d.ts b/apps/web/src/typings.d.ts index e0cb3176..d86ad556 100644 --- a/apps/web/src/typings.d.ts +++ b/apps/web/src/typings.d.ts @@ -3,6 +3,7 @@ interface PublicEnv { PUBLIC_API_URL: string; PUBLIC_COLLAB_URL: string; PUBLIC_ASSETS_URL: string; + PUBLIC_POSTHOG_TOKEN: string; PUBLIC_DISABLE_ANALYTICS: boolean; } interface ImportMetaEnv extends PublicEnv {} diff --git a/packages/backend/src/env.ts b/packages/backend/src/env.ts index b0993c9b..75c1f84e 100644 --- a/packages/backend/src/env.ts +++ b/packages/backend/src/env.ts @@ -57,6 +57,7 @@ const envSchema = z.object({ PUBLIC_COLLAB_URL: z.string(), PUBLIC_APP_URL: z.string(), PUBLIC_ASSETS_URL: z.string(), + PUBLIC_POSTHOG_TOKEN: z.string().optional(), PUBLIC_DISABLE_ANALYTICS: z.boolean().optional().default(false) }); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index fbd4bbce..7ed2e0e9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -650,8 +650,8 @@ importers: specifier: ^5.0.5 version: 5.0.5 posthog-js: - specifier: ^1.126.0 - version: 1.126.0 + specifier: ^1.136.2 + version: 1.136.2 prettier: specifier: ^3.2.5 version: 3.2.5 @@ -14705,8 +14705,8 @@ packages: picocolors: 1.0.0 source-map-js: 1.0.2 - /posthog-js@1.126.0: - resolution: {integrity: sha512-8qCdPE9RZkyXI3kKCnkXWxK0jn2mLZg6g5a6KezDPqH7mHTG66v7ANU31hcwzQGV5F5UW1GXw0xL0PaC3HkA6g==} + /posthog-js@1.136.2: + resolution: {integrity: sha512-9oTUB/JDayzV+hB4f7u+ZNUbfnkGHLxyZw+FOE59pCgmbWHcJxhpGbu2Xlyv027/iHIjQbn1mtm2wJmBI2BuqA==} dependencies: fflate: 0.4.8 preact: 10.19.6