Heap analytics (#500)

* add heap

* remove hotjar

* prettier formatting conflicting with es lint

* stop weird prettier/eslint conflict
This commit is contained in:
mantikoros 2022-06-14 11:54:58 -05:00 committed by GitHub
parent 92b368f11e
commit 0ecff1b581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 19 additions and 14 deletions

View File

@ -18,4 +18,5 @@ export const DEV_CONFIG: EnvConfig = {
sellbet: 'https://sellbet-w3txbmd3ba-uc.a.run.app', sellbet: 'https://sellbet-w3txbmd3ba-uc.a.run.app',
createmarket: 'https://createmarket-w3txbmd3ba-uc.a.run.app', createmarket: 'https://createmarket-w3txbmd3ba-uc.a.run.app',
}, },
heapId: '1877426215',
} }

View File

@ -8,6 +8,7 @@ export type EnvConfig = {
domain: string domain: string
firebaseConfig: FirebaseConfig firebaseConfig: FirebaseConfig
functionEndpoints: Record<V2CloudFunction, string> functionEndpoints: Record<V2CloudFunction, string>
heapId?: string
// Access controls // Access controls
adminEmails: string[] adminEmails: string[]
@ -34,6 +35,7 @@ type FirebaseConfig = {
export const PROD_CONFIG: EnvConfig = { export const PROD_CONFIG: EnvConfig = {
domain: 'manifold.markets', domain: 'manifold.markets',
heapId: '29268260',
firebaseConfig: { firebaseConfig: {
apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw', apiKey: 'AIzaSyDp3J57vLeAZCzxLD-vcPaGIkAmBoGOSYw',
authDomain: 'mantic-markets.firebaseapp.com', authDomain: 'mantic-markets.firebaseapp.com',

View File

@ -13,6 +13,7 @@ import {
userDocRef, userDocRef,
} from 'web/lib/firebase/users' } from 'web/lib/firebase/users'
import { useStateCheckEquality } from './use-state-check-equality' import { useStateCheckEquality } from './use-state-check-equality'
import { identifyUser } from 'web/lib/service/analytics'
export const useUser = () => { export const useUser = () => {
const [user, setUser] = useStateCheckEquality<User | null | undefined>( const [user, setUser] = useStateCheckEquality<User | null | undefined>(
@ -24,7 +25,10 @@ export const useUser = () => {
const userId = user?.id const userId = user?.id
useEffect(() => { useEffect(() => {
if (userId) return listenForUser(userId, setUser) if (userId) {
identifyUser(userId)
return listenForUser(userId, setUser)
}
}, [userId, setUser]) }, [userId, setUser])
return user return user

View 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)
}

View File

@ -5,6 +5,7 @@ import Head from 'next/head'
import Script from 'next/script' import Script from 'next/script'
import { usePreserveScroll } from 'web/hooks/use-preserve-scroll' import { usePreserveScroll } from 'web/hooks/use-preserve-scroll'
import { QueryClient, QueryClientProvider } from 'react-query' import { QueryClient, QueryClientProvider } from 'react-query'
import { ENV_CONFIG } from 'common/envs/constants'
function firstLine(msg: string) { function firstLine(msg: string) {
return msg.replace(/\r?\n.*/s, '') return msg.replace(/\r?\n.*/s, '')
@ -39,19 +40,12 @@ function MyApp({ Component, pageProps }: AppProps) {
gtag('config', 'G-SSFK1Q138D'); gtag('config', 'G-SSFK1Q138D');
`} `}
</Script> </Script>
{/* Hotjar Tracking Code for https://manifold.markets */} {ENV_CONFIG.heapId && (
<Script id="hotjar"> <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])};
(function(h,o,t,j,a,r){ heap.load("${ENV_CONFIG.heapId}");`}
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> </Script>
)}
<Head> <Head>
<title>Manifold Markets A market for every question</title> <title>Manifold Markets A market for every question</title>