diff --git a/common/envs/dev.ts b/common/envs/dev.ts index 151de075..4afb4dac 100644 --- a/common/envs/dev.ts +++ b/common/envs/dev.ts @@ -18,4 +18,5 @@ export const DEV_CONFIG: EnvConfig = { sellbet: 'https://sellbet-w3txbmd3ba-uc.a.run.app', createmarket: 'https://createmarket-w3txbmd3ba-uc.a.run.app', }, + heapId: '1877426215', } diff --git a/common/envs/prod.ts b/common/envs/prod.ts index 4352af64..1c36b29d 100644 --- a/common/envs/prod.ts +++ b/common/envs/prod.ts @@ -8,6 +8,7 @@ export type EnvConfig = { domain: string firebaseConfig: FirebaseConfig functionEndpoints: Record + heapId?: string // Access controls adminEmails: string[] @@ -34,6 +35,7 @@ type FirebaseConfig = { export const PROD_CONFIG: EnvConfig = { domain: 'manifold.markets', + heapId: '29268260', firebaseConfig: { apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', authDomain: 'mantic-markets.firebaseapp.com', diff --git a/web/hooks/use-user.ts b/web/hooks/use-user.ts index b57a0256..4605da3c 100644 --- a/web/hooks/use-user.ts +++ b/web/hooks/use-user.ts @@ -13,6 +13,7 @@ import { userDocRef, } from 'web/lib/firebase/users' import { useStateCheckEquality } from './use-state-check-equality' +import { identifyUser } from 'web/lib/service/analytics' export const useUser = () => { const [user, setUser] = useStateCheckEquality( @@ -24,7 +25,10 @@ export const useUser = () => { const userId = user?.id useEffect(() => { - if (userId) return listenForUser(userId, setUser) + if (userId) { + identifyUser(userId) + return listenForUser(userId, setUser) + } }, [userId, setUser]) return user diff --git a/web/lib/service/analytics.ts b/web/lib/service/analytics.ts new file mode 100644 index 00000000..b55dcb7e --- /dev/null +++ b/web/lib/service/analytics.ts @@ -0,0 +1,4 @@ +export function identifyUser(userId: string) { + const w = window as any // needed to stop weird prettier/eslint conflict + w?.heap?.identify(userId) +} diff --git a/web/pages/_app.tsx b/web/pages/_app.tsx index a833c933..730f93c9 100644 --- a/web/pages/_app.tsx +++ b/web/pages/_app.tsx @@ -5,6 +5,7 @@ import Head from 'next/head' import Script from 'next/script' import { usePreserveScroll } from 'web/hooks/use-preserve-scroll' import { QueryClient, QueryClientProvider } from 'react-query' +import { ENV_CONFIG } from 'common/envs/constants' function firstLine(msg: string) { return msg.replace(/\r?\n.*/s, '') @@ -39,19 +40,12 @@ function MyApp({ Component, pageProps }: AppProps) { gtag('config', 'G-SSFK1Q138D'); `} - {/* Hotjar Tracking Code for https://manifold.markets */} - + {ENV_CONFIG.heapId && ( + + )} Manifold Markets — A market for every question