fathom-client
Advanced tools
Comparing version 2.0.2 to 2.0.3
{ | ||
"name": "fathom-client", | ||
"version": "2.0.2", | ||
"version": "2.0.3", | ||
"description": "A simple wrapper around the Fathom Analytics library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -50,53 +50,25 @@ # Fathom Client [![CircleCI](https://circleci.com/gh/unstacked/fathom-client.svg?style=svg)](https://circleci.com/gh/unstacked/fathom-client) | ||
```jsx | ||
import React from 'react'; | ||
import App from 'next/app'; | ||
import React, { useEffect } from 'react'; | ||
import Router from 'next/router'; | ||
import * as Fathom from 'fathom-client'; | ||
class MyApp extends App { | ||
render() { | ||
const { Component, pageProps } = this.props; | ||
return <Component {...pageProps} />; | ||
} | ||
} | ||
// Record a pageview when route changes | ||
Router.events.on('routeChangeComplete', () => { | ||
Fathom.trackPageview(); | ||
}); | ||
export default MyApp; | ||
``` | ||
function App({ Component, pageProps }) { | ||
// Initialize Fathom when the app loads | ||
useEffect(() => { | ||
if (process.env.NODE_ENV === 'production') { | ||
Fathom.load(); | ||
Fathom.setSiteId('ZFEWBXJZ'); | ||
Fathom.trackPageview(); | ||
} | ||
}, []); | ||
Then, add a wrapper component with an effect to load Fathom on page load: | ||
return <Component {...pageProps} />; | ||
} | ||
```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('<your-site-id>'); | ||
+ Fathom.trackPageview(); | ||
+ } | ||
+ }, []); | ||
+ | ||
+ return <div {...props} />; | ||
+ } | ||
class MyApp extends App { | ||
render() { | ||
const { Component, pageProps } = this.props | ||
- return <Component {...pageProps} /> | ||
+ return ( | ||
+ <Layout> | ||
+ <Component {...pageProps}></Component> | ||
+ </Layout> | ||
+ ) | ||
} | ||
} | ||
export default MyApp | ||
export default App; | ||
``` | ||
@@ -103,0 +75,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
7561
82