---
title: "Fathom Analytics · Nuxt Scripts"
description: "Use Fathom Analytics in your Nuxt app."
canonical_url: "https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics"
meta:
  "og:description": "Use Fathom Analytics in your Nuxt app."
  "og:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Fathom%2BAnalytics%2Cdescription_Use%2BFathom%2BAnalytics%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Analytics%2Cp_Ii9zY3JpcHRzL3YwL2FuYWx5dGljcy9mYXRob20tYW5hbHl0aWNzIg%2Cs_VfQPuuCddTq1THDk.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "Fathom Analytics · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/d/c_Docs%2Ctitle_Fathom%2BAnalytics%2Cdescription_Use%2BFathom%2BAnalytics%2Bin%2Byour%2BNuxt%2Bapp.%2Cheadline_Analytics%2Cp_Ii9zY3JpcHRzL3YwL2FuYWx5dGljcy9mYXRob20tYW5hbHl0aWNzIg%2Cs_VfQPuuCddTq1THDk.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Analytics**

# **Fathom Analytics**

[Copy for LLMs](https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics.md)

[**Fathom Analytics**](https://usefathom.com/) is a great privacy analytics solution for your Nuxt app. It doesn't gather personal data from your visitors, yet provides detailed insights into how your site is used.

## Loading Globally

The simplest way to load Fathom Analytics globally in your Nuxt App is to use your Nuxt config, providing your site ID as a string.

```ts
export default defineNuxtConfig({
  scripts: {
    registry: {
      fathomAnalytics: {
        site: 'YOUR_TOKEN_ID'
      }
    }
  }
})
```

## Composable `**useScriptFathomAnalytics**`

The `**useScriptFathomAnalytics**` composable lets you have fine-grain control over when and how Fathom Analytics is loaded on your site.

```ts
useScriptFathomAnalytics(options)
```

## Defaults

- **Trigger**: Script will load when Nuxt is hydrated.

## Options

```ts
export const FathomAnalyticsOptions = object({
  /**
   * The Fathom Analytics site ID.
   */
  site: string(),
  /**
   * The Fathom Analytics tracking mode.
   */
  spa: optional(union([literal('auto'), literal('history'), literal('hash')])),
  /**
   * Automatically track page views.
   */
  auto: optional(boolean()),
  /**
   * Enable canonical URL tracking.
   */
  canonical: optional(boolean()),
  /**
   * Honor Do Not Track requests.
   */
  honorDnt: optional(boolean()),
})
```

Additionally like all registry scripts you can provide extra configuration:

- `**scriptInput**` - HTML attributes to add to the script tag.
- `**scriptOptions**` - See Script Options. Bundling is not supported, `**bundle: true**` will not do anything.

## Return values

The Fathom Analytics composable injects a `**window.fathom**` object into the global scope.

```ts
export interface FathomAnalyticsApi {
  beacon: (ctx: { url: string, referrer?: string }) => void
  blockTrackingForMe: () => void
  enableTrackingForMe: () => void
  isTrackingEnabled: () => boolean
  send: (type: string, data: unknown) => void
  setSite: (siteId: string) => void
  sideId: string
  trackPageview: (ctx?: { url: string, referrer?: string }) => void
  trackGoal: (goalId: string, cents: number) => void
  trackEvent: (eventName: string, value: { _value: number }) => void
}
```

You can access the `**fathom**` object as a proxy directly or await the `**$script**` promise to access the object. It's recommended to use the proxy for any void functions.

```ts
const { proxy } = useScriptFathomAnalytics()
function trackMyGoal() {
  proxy.trackGoal('MY_GOAL_ID', 100)
}
```

## Example

Loading Fathom Analytics through the `**app.vue**` when Nuxt is ready.

app.vue

```vue
<script setup>
useScriptFathomAnalytics({
  site: 'YOUR_SITE_ID',
  scriptOptions: {
    trigger: 'onNuxtReady'
  }
})
</script>
```

[Edit this page](https://github.com/nuxt/scripts/edit/0.x/docs/content/analytics/fathom-analytics.md)

[Markdown For LLMs](https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics.md)

[**Databuddy Analytics** Use Databuddy Analytics in your Nuxt app.](https://scripts.nuxt.com/scripts/v0/analytics/databuddy-analytics) [**Google Analytics** Use Google Analytics in your Nuxt app.](https://scripts.nuxt.com/scripts/v0/analytics/google-analytics)

**On this page **

- [Loading Globally](#loading-globally)
- [Composable useScriptFathomAnalytics](#composable-usescriptfathomanalytics)
- [Defaults](#defaults)
- [Options](#options)
- [Return values](#return-values)
- [Example](#example)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics#webpage","@type":"WebPage","description":"Use Fathom Analytics in your Nuxt app.","name":"Fathom Analytics","url":"https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics","breadcrumb":{"@id":"https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Scripts","item":"https://scripts.nuxt.com/scripts","position":2},{"@type":"ListItem","name":"V0","item":"https://scripts.nuxt.com/scripts/v0","position":3},{"@type":"ListItem","name":"Analytics","item":"https://scripts.nuxt.com/scripts/v0/analytics","position":4},{"@type":"ListItem","name":"Fathom Analytics","item":"https://scripts.nuxt.com/scripts/v0/analytics/fathom-analytics","position":5}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
