Add Fathom

This commit is contained in:
Lachlan Campbell 2020-06-26 18:09:29 +00:00
parent e868b617a7
commit 9ae0c45f43
3 changed files with 31 additions and 11 deletions

View file

@ -17,6 +17,7 @@
"@next/mdx": "^9.4.4",
"@segment/snippet": "^4.12.0",
"airtable-plus": "^1.0.4",
"fathom-client": "^3.0.0",
"isomorphic-unfetch": "^3.0.0",
"lodash": "^4.17.15",
"next": "^9.4.4",

View file

@ -1,4 +1,5 @@
import * as React from 'react'
import React, { useEffect } from 'react'
import { useRouter } from 'next/router'
import NextApp from 'next/app'
import Head from 'next/head'
@ -6,15 +7,28 @@ import Meta from '@hackclub/meta'
import '@hackclub/theme/fonts/reg-bold.css'
import theme from '../lib/theme'
import { ThemeProvider } from 'theme-ui'
import * as Fathom from 'fathom-client'
export default class App extends NextApp {
render() {
const { Component, pageProps } = this.props
return (
<ThemeProvider theme={theme}>
<Meta as={Head} />
<Component {...pageProps} />
</ThemeProvider>
)
}
const App = ({ Component, pageProps }) => {
const router = useRouter()
useEffect(() => {
Fathom.load('OGIMJEFA', {
includedDomains: ['hackclub.com', 'v3.hackclub.com']
})
const onRouteChangeComplete = () => Fathom.trackPageview()
router.events.on('routeChangeComplete', onRouteChangeComplete)
return () => {
router.events.off('routeChangeComplete', onRouteChangeComplete)
}
}, [])
return (
<ThemeProvider theme={theme}>
<Meta as={Head} />
<Component {...pageProps} />
</ThemeProvider>
)
}
export default App

View file

@ -3396,6 +3396,11 @@ fast-json-stable-stringify@^2.0.0:
resolved "https://registry.yarnpkg.com/fast-json-stable-stringify/-/fast-json-stable-stringify-2.1.0.tgz#874bf69c6f404c2b5d99c481341399fd55892633"
integrity sha512-lhd/wF+Lk98HZoTCtlVraHtfh5XYijIjalXck7saUtuanSDyLMxnHhSXEDJqHxD7msR8D0uCmqlkwjCV8xvwHw==
fathom-client@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/fathom-client/-/fathom-client-3.0.0.tgz#409c047cf1e2fea45b148e28d50fcd635e992893"
integrity sha512-d0oH2SHWCMIVLbbegB7nBIjSvbqbHrZBZxIOWSVAxlJL/roL0Ah9NNb6rTIcKMlA4gov9AjWQGEcZRzlnGc3XQ==
figgy-pudding@^3.5.1:
version "3.5.1"
resolved "https://registry.yarnpkg.com/figgy-pudding/-/figgy-pudding-3.5.1.tgz#862470112901c727a0e495a80744bd5baa1d6790"