Fathom Analytics: Privacy-Focused Website Analytics
Tags: webdev, javascript, analytics, privacy
Published: 2020-09-23 16:49:21

## The Rise of Privacy
Stop stealing your users personal information. Recently, there has been a growing trend of people starting to take their privacy more serious. They realize that they are being tracked across the entire web of internet. Imagine someone following you all day watching every little thing you do without you knowing. They watch you while you are working, reading, and playing. Tools such as Google Analytics make it easier for you to have more insight on your website but this comes at the expense of invading your user's privacy. Countries are adding laws where website need to be more transparent on their tracking or will be fined. Great news is there are tools that are privacy oriented to help keep your visitors' privacy intact while still collecting valuable metrics.

## Introducing Fathom Analytics

![Fathom Introduction](https://dev-to-uploads.s3.amazonaws.com/i/3s705iosu752netbgou6.png)

I have been using [Fathom Analytics](https://usefathom.com/ref/45XEAJ) for my blog and side projects for the past couple months. It has been a great tool to collect metrics without invading my visitors' privacy.

Some great benefits using Fathom:
- You don't need to display cookie notices as they do not use cookies, nor track invasive data.
- No personal information is collected from my visitors. Privacy is their number one focus.
- Ability to use a custom domain for tracking to prevent ad-blockers from blocking the script from loading.
- Extremely light-weight script to keep load time minimal.
- Add unlimited websites to my account.
- Add monitoring for uptime on my websites with multiple forms of notification.
- The dashboard is simple and easy to use. It displays everything I need with a clean chart and tables.
- Ability to share dashboard to others protected by a password.
- Their support has always been quick to respond and always helpful.
- They also pledge 2% of their revenues to green initiatives.

### Usage

Using Fathom is extremely simple. All you need to do is add a new site in your Fathom settings. This will generate a `Site ID` and provide you with fathom script to be added to your HTML.
```html
<!-- Fathom - beautiful, simple website analytics -->
<script src="https://cdn.usefathom.com/script.js" site="SITE_ID" defer></script>
<!-- / Fathom -->
```

They also have JavaScript package [fathom-client](https://github.com/derrickreimer/fathom-client) to make it easy to add it to your JavaScript Frameworks. I use the client inside my Next.js projects.

Example Use in Next.js:
```js
import { useEffect } from 'react'
import { useRouter } from 'next/router'
import * as Fathom from 'fathom-client'

export default function App({ Component, pageProps }) {
  const router = useRouter()

  useEffect(() => {
    // Initialize Fathom when the app loads
    Fathom.load('SITE_ID', {
      includedDomains: ['YOUR_SITE_URL']
    })

    function onRouteChangeComplete() {
      Fathom.trackPageview()
    }
    // Record a pageview when route changes
    router.events.on('routeChangeComplete', onRouteChangeComplete)

    // Unassign event listener
    return () => {
      router.events.off('routeChangeComplete', onRouteChangeComplete)
    }
  }, [])

  return <Component {...pageProps} />
}
```

## Be a part of the growing privacy movement

Be a part of the growing movement of improving privacy. I know privacy is important for me. Ditch the invasive tracking tools such as Google Analytics. Switch to something that still gives you metrics awhile still providing privacy. Try [Fathom Analytics](https://usefathom.com/ref/45XEAJ)!

---
- Follow me on [Twitter](https://twitter.com/CodeByCorey) for random posts about tech, programming, and working from home.