Heap analytics (#500)
* add heap * remove hotjar * prettier formatting conflicting with es lint * stop weird prettier/eslint conflict
This commit is contained in:
parent
92b368f11e
commit
0ecff1b581
|
@ -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',
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ export type EnvConfig = {
|
|||
domain: string
|
||||
firebaseConfig: FirebaseConfig
|
||||
functionEndpoints: Record<V2CloudFunction, string>
|
||||
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',
|
||||
|
|
|
@ -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<User | null | undefined>(
|
||||
|
@ -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
|
||||
|
|
4
web/lib/service/analytics.ts
Normal file
4
web/lib/service/analytics.ts
Normal file
|
@ -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)
|
||||
}
|
|
@ -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');
|
||||
`}
|
||||
</Script>
|
||||
{/* Hotjar Tracking Code for https://manifold.markets */}
|
||||
<Script id="hotjar">
|
||||
{`
|
||||
(function(h,o,t,j,a,r){
|
||||
h.hj=h.hj||function(){(h.hj.q=h.hj.q||[]).push(arguments)};
|
||||
h._hjSettings={hjid:2968940,hjsv:6};
|
||||
a=o.getElementsByTagName('head')[0];
|
||||
r=o.createElement('script');r.async=1;
|
||||
r.src=t+h._hjSettings.hjid+j+h._hjSettings.hjsv;
|
||||
a.appendChild(r);
|
||||
})(window,document,'https://static.hotjar.com/c/hotjar-','.js?sv=');
|
||||
`}
|
||||
</Script>
|
||||
{ENV_CONFIG.heapId && (
|
||||
<Script id="heap-analytics">
|
||||
{`window.heap=window.heap||[],heap.load=function(e,t){window.heap.appid=e,window.heap.config=t=t||{};var r=document.createElement("script");r.type="text/javascript",r.async=!0,r.src="https://cdn.heapanalytics.com/js/heap-"+e+".js";var a=document.getElementsByTagName("script")[0];a.parentNode.insertBefore(r,a);for(var n=function(e){return function(){heap.push([e].concat(Array.prototype.slice.call(arguments,0)))}},p=["addEventProperties","addUserProperties","clearEventProperties","identify","resetIdentity","removeEventProperty","setEventProperties","track","unsetEventProperty"],o=0;o<p.length;o++)heap[p[o]]=n(p[o])};
|
||||
heap.load("${ENV_CONFIG.heapId}");`}
|
||||
</Script>
|
||||
)}
|
||||
<Head>
|
||||
<title>Manifold Markets — A market for every question</title>
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user