From 5853c02b82240a129e92656b4a7005ec7a9e8c5c Mon Sep 17 00:00:00 2001 From: Derrick Reimer Date: Mon, 3 Feb 2020 13:48:45 -0600 Subject: [PATCH] Simplify next example --- README.md | 68 ++++++++++++++++--------------------------------------- 1 file changed, 20 insertions(+), 48 deletions(-) diff --git a/README.md b/README.md index 8e97e29..d71762a 100644 --- a/README.md +++ b/README.md @@ -47,57 +47,29 @@ const onSignUp = () => { Create an `_app.js` file in your `pages` directory, [like this](https://nextjs.org/docs#custom-app): ```jsx -import React from 'react'; -import App from 'next/app'; - -class MyApp extends App { - render() { - const { Component, pageProps } = this.props; - return ; - } -} - -export default MyApp; -``` +import React, { useEffect } from 'react'; +import Router from 'next/router'; +import * as Fathom from 'fathom-client'; -Then, add a wrapper component with an effect to load Fathom on page load: - -```diff -- import React from 'react' -+ import React, { useEffect } from 'react' -+ import * as Fathom from 'fathom-client' -+ import Router from 'next/router' - import App from 'next/app' - -+ Router.events.on('routeChangeComplete', () => { -+ Fathom.trackPageview(); -+ }); - -+ function Layout(props) { -+ useEffect(() => { -+ if (process.env.NODE_ENV === 'production') { -+ Fathom.load(); -+ Fathom.setSiteId(''); -+ Fathom.trackPageview(); -+ } -+ }, []); -+ -+ return
; -+ } - - class MyApp extends App { - render() { - const { Component, pageProps } = this.props -- return -+ return ( -+ -+ -+ -+ ) +// Record a pageview when route changes +Router.events.on('routeChangeComplete', () => { + Fathom.trackPageview(); +}); + +function App({ Component, pageProps }) { + // Initialize Fathom when the app loads + useEffect(() => { + if (process.env.NODE_ENV === 'production') { + Fathom.load(); + Fathom.setSiteId('ZFEWBXJZ'); + Fathom.trackPageview(); } - } + }, []); + + return ; +} - export default MyApp +export default App; ``` ## Releasing