Skip to content

Commit

Permalink
chore: Update PostHog
Browse files Browse the repository at this point in the history
  • Loading branch information
areknawo committed Jun 3, 2024
1 parent a873ce5 commit 78377ae
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 12 deletions.
1 change: 1 addition & 0 deletions apps/backend/app/src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
});
};
Expand Down
1 change: 1 addition & 0 deletions apps/web/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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}}"
};
</script>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
30 changes: 23 additions & 7 deletions apps/web/src/layout/secured-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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 }));
Expand All @@ -40,6 +55,7 @@ const SecuredLayout: ParentComponent = (props) => {

return (
<AuthenticatedUserDataProvider>
<Analytics />
<AppearanceProvider>
<ExtensionsProvider>
<ContentDataProvider>
Expand Down
1 change: 1 addition & 0 deletions apps/web/src/typings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}
Expand Down
1 change: 1 addition & 0 deletions packages/backend/src/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
});

Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 78377ae

Please sign in to comment.