diff --git a/packages/server/lib/controllers/environment.controller.ts b/packages/server/lib/controllers/environment.controller.ts index 2088c92a16..2c0876e85b 100644 --- a/packages/server/lib/controllers/environment.controller.ts +++ b/packages/server/lib/controllers/environment.controller.ts @@ -22,12 +22,13 @@ export interface EnvironmentAndAccount { webhook_settings: ExternalWebhook | null; host: string; uuid: string; + name: string; email: string; slack_notifications_channel: string | null; } class EnvironmentController { - async getEnvironment(_: Request, res: Response>, next: NextFunction) { + async getEnvironment(_: Request, res: Response<{ environmentAndAccount: EnvironmentAndAccount }, Required>, next: NextFunction) { try { const { environment, account, user } = res.locals; @@ -74,10 +75,11 @@ class EnvironmentController { res.status(200).send({ environmentAndAccount: { environment, - env_variables: environmentVariables, + env_variables: environmentVariables || [], webhook_settings: webhookSettings, host: baseUrl, uuid: account.uuid, + name: account.name, email: user.email, slack_notifications_channel } diff --git a/packages/server/lib/controllers/v1/getEnvJs.ts b/packages/server/lib/controllers/v1/getEnvJs.ts index 7b436b3fa1..daa6a1562c 100644 --- a/packages/server/lib/controllers/v1/getEnvJs.ts +++ b/packages/server/lib/controllers/v1/getEnvJs.ts @@ -10,8 +10,9 @@ export const getEnvJs = asyncWrapper((_, res) => { connectUrl: connectUrl, publicSentryKey: process.env['PUBLIC_SENTRY_KEY'] || '', publicPosthogKey: process.env['PUBLIC_POSTHOG_KEY'] || '', - publicPosthogPost: process.env['PUBLIC_POSTHOG_HOST'] || '', + publicPosthogHost: process.env['PUBLIC_POSTHOG_HOST'] || '', publicLogoDevKey: process.env['PUBLIC_LOGODEV_KEY'] || '', + publicKoalaKey: process.env['PUBLIC_KOALA_KEY'] || '', isCloud, features: { logs: envs.NANGO_LOGS_ENABLED, diff --git a/packages/types/lib/web/env.ts b/packages/types/lib/web/env.ts index 08284c9517..23ee29bb4e 100644 --- a/packages/types/lib/web/env.ts +++ b/packages/types/lib/web/env.ts @@ -4,8 +4,9 @@ export interface WindowEnv { connectUrl: string; publicSentryKey: string; publicPosthogKey: string; - publicPosthogPost: string; + publicPosthogHost: string; publicLogoDevKey: string; + publicKoalaKey: string; isCloud: boolean; features: { logs: boolean; diff --git a/packages/webapp/src/App.tsx b/packages/webapp/src/App.tsx index 2101444963..22e86d4106 100644 --- a/packages/webapp/src/App.tsx +++ b/packages/webapp/src/App.tsx @@ -35,6 +35,7 @@ import { TeamSettings } from './pages/Team/Settings'; import { UserSettings } from './pages/User/Settings'; import { Root } from './pages/Root'; import { globalEnv } from './utils/env'; +import { Helmet } from 'react-helmet'; const theme = createTheme({ fontFamily: 'Inter' @@ -52,6 +53,17 @@ const App = () => { return ( + {globalEnv.publicKoalaKey && ( + + )} + { const { meta, error, loading: loadingMeta } = useMeta(); @@ -18,6 +19,7 @@ export const PrivateRoute: React.FC = () => { const setBaseUrl = useStore((state) => state.setBaseUrl); const setDebugMode = useStore((state) => state.setDebugMode); const setEnv = useStore((state) => state.setEnv); + const { environmentAndAccount } = useEnvironment(env); useEffect(() => { if (!meta || error) { @@ -64,10 +66,11 @@ export const PrivateRoute: React.FC = () => { }, [meta, loadingMeta, env, error, setEnv]); useEffect(() => { - if (user) { + if (user && environmentAndAccount) { identify(user); + window.ko?.identify(user.email, { name: user.name, $account: { group_id: user.accountId, name: environmentAndAccount.name } }); } - }, [user, identify]); + }, [user, environmentAndAccount, identify]); if (loadingMeta || !ready || loadingUser) { return null; diff --git a/packages/webapp/src/env.d.ts b/packages/webapp/src/env.d.ts index d1bb9c14aa..8ccdb5b96d 100644 --- a/packages/webapp/src/env.d.ts +++ b/packages/webapp/src/env.d.ts @@ -21,6 +21,10 @@ declare global { interface Window { _env: WindowEnv; + // koala + ko?: { identify: (str: string, ...args: any[]) => void; reset: () => void }; + + // Youtube YT: { Player: Player; }; diff --git a/packages/webapp/src/utils/user.tsx b/packages/webapp/src/utils/user.tsx index 6f8d4293ef..b8bff552b5 100644 --- a/packages/webapp/src/utils/user.tsx +++ b/packages/webapp/src/utils/user.tsx @@ -36,6 +36,8 @@ export function useSignout() { await mutate(key, undefined, { revalidate: false }); } + window.ko?.reset(); + // force a full reload to ensure all state is cleared window.location.href = '/signin'; };