Fathom Analytics Integrations
Overview
Fathom Analytics is designed to integrate seamlessly with popular platforms and tools while maintaining its privacy-first philosophy. Unlike complex analytics platforms that require extensive setup, Fathom keeps integrations simple: a lightweight script and optional API access for custom workflows.
This guide covers native integrations, custom implementations, and best practices for connecting Fathom Analytics to your tech stack.
CMS & Website Builder Integrations
WordPress
Official Plugin:
- Install the Fathom Analytics plugin from WordPress.org
- Navigate to Settings > Fathom Analytics
- Enter your Site ID (found in Fathom dashboard)
- Save settings
Manual Installation:
<!-- Add to header.php before </head> -->
<?php if (!is_user_logged_in()) : ?>
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
<?php endif; ?>
// Track purchases in functions.php
add_action('woocommerce_thankyou', 'fathom_track_purchase');
function fathom_track_purchase($order_id) {
$order = wc_get_order($order_id);
$total = $order->get_total();
$cents = round($total * 100);
?>
<script>
if (window.fathom) {
fathom.trackGoal('PURCHASE', <?php echo $cents; ?>);
}
</script>
<?php
}
Ghost
Native Integration:
- Go to Settings > Code Injection
- Add to Site Header:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Member Signups:
<!-- Add to members signup page -->
<script>
document.addEventListener('DOMContentLoaded', function() {
// Listen for successful signup
const signupForm = document.querySelector('.gh-signup-form');
if (signupForm) {
signupForm.addEventListener('submit', function() {
fathom.trackGoal('SIGNUP01', 0);
});
}
});
</script>
Webflow
Setup:
- Go to Project Settings > Custom Code
- Add to Head Code:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Form Tracking:
<!-- Add to page with form -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const form = document.querySelector('form');
if (form) {
form.addEventListener('submit', function() {
fathom.trackGoal('FORMSUBM', 0);
});
}
});
</script>
Squarespace
Installation:
- Go to Settings > Advanced > Code Injection
- Add to Header:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Button Click Tracking:
<!-- Settings > Advanced > Code Injection > Footer -->
<script>
document.addEventListener('DOMContentLoaded', function() {
const buttons = document.querySelectorAll('.sqs-block-button-element');
buttons.forEach(function(button) {
button.addEventListener('click', function() {
fathom.trackGoal('BTNCLICK', 0);
});
});
});
</script>
Shopify
Theme Installation:
- Go to Online Store > Themes > Edit Code
- Open theme.liquid
- Add before
</head>:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Purchase Tracking: Create a new file: Snippets > fathom-purchase.liquid
{% if first_time_accessed %}
<script>
if (window.fathom) {
var total = {{ checkout.total_price | divided_by: 100.0 }};
var cents = Math.round(total * 100);
fathom.trackGoal('PURCHASE', cents);
}
</script>
{% endif %}
Add to Settings > Checkout > Order Status Page:
{% render 'fathom-purchase' %}
Wix
Installation:
- Go to Settings > Custom Code
- Add to Head:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Wix Stores Purchase Tracking:
// Add to page code
$w.onReady(function () {
$w('#thankYouPage').onReady(() => {
if (window.fathom) {
fathom.trackGoal('PURCHASE', 0);
}
});
});
Framework Integrations
React
Installation:
npm install fathom-client
Setup with React Router:
// App.js
import { useEffect } from 'react';
import { useLocation } from 'react-router-dom';
import * as Fathom from 'fathom-client';
function App() {
const location = useLocation();
useEffect(() => {
Fathom.load('ABCDEFGH', {
includedDomains: ['yourdomain.com'],
});
}, []);
useEffect(() => {
Fathom.trackPageview();
}, [location]);
return <div>...</div>;
}
Tracking Goals:
import * as Fathom from 'fathom-client';
function SignupButton() {
const handleSignup = () => {
// Perform signup...
// Track goal
Fathom.trackGoal('SIGNUP01', 0);
};
return <button onClick={handleSignup}>Sign Up</button>;
}
Next.js
Installation:
npm install fathom-client
Setup in _app.js:
// pages/_app.js
import { useEffect } from 'react';
import { useRouter } from 'next/router';
import * as Fathom from 'fathom-client';
function MyApp({ Component, pageProps }) {
const router = useRouter();
useEffect(() => {
// Initialize Fathom
Fathom.load('ABCDEFGH', {
includedDomains: ['yourdomain.com'],
});
// Track pageviews on route change
function onRouteChangeComplete() {
Fathom.trackPageview();
}
router.events.on('routeChangeComplete', onRouteChangeComplete);
return () => {
router.events.off('routeChangeComplete', onRouteChangeComplete);
};
}, [router.events]);
return <Component {...pageProps} />;
}
export default MyApp;
App Directory (Next.js 13+):
// app/layout.js
'use client';
import { useEffect } from 'react';
import { usePathname } from 'next/navigation';
import * as Fathom from 'fathom-client';
export default function RootLayout({ children }) {
const pathname = usePathname();
useEffect(() => {
Fathom.load('ABCDEFGH');
}, []);
useEffect(() => {
Fathom.trackPageview();
}, [pathname]);
return (
<html lang="en">
<body>{children}</body>
</html>
);
}
Vue.js
Installation:
npm install fathom-client
Vue 3 Setup:
// main.js
import { createApp } from 'vue';
import App from './App.vue';
import router from './router';
import * as Fathom from 'fathom-client';
// Initialize Fathom
Fathom.load('ABCDEFGH', {
includedDomains: ['yourdomain.com'],
});
// Track pageviews on route change
router.afterEach(() => {
Fathom.trackPageview();
});
createApp(App).use(router).mount('#app');
Tracking in Components:
<template>
<button @click="handleClick">Track Event</button>
</template>
<script>
import * as Fathom from 'fathom-client';
export default {
methods: {
handleClick() {
Fathom.trackGoal('BTNCLICK', 0);
}
}
}
</script>
Angular
Installation:
npm install fathom-client
Setup in app.component.ts:
import { Component, OnInit } from '@angular/core';
import { Router, NavigationEnd } from '@angular/router';
import { filter } from 'rxjs/operators';
import * as Fathom from 'fathom-client';
@Component({
selector: 'app-root',
templateUrl: './app.component.html'
})
export class AppComponent implements OnInit {
constructor(private router: Router) {}
ngOnInit() {
// Initialize Fathom
Fathom.load('ABCDEFGH', {
includedDomains: ['yourdomain.com']
});
// Track pageviews on navigation
this.router.events.pipe(
filter(event => event instanceof NavigationEnd)
).subscribe(() => {
Fathom.trackPageview();
});
}
}
Gatsby
Installation:
npm install gatsby-plugin-fathom
gatsby-config.js:
module.exports = {
plugins: [
{
resolve: 'gatsby-plugin-fathom',
options: {
siteId: 'ABCDEFGH',
// Optional settings
includedDomains: ['yourdomain.com'],
},
},
],
};
Tracking Goals:
import { trackGoal } from 'fathom-client';
function NewsletterSignup() {
const handleSubmit = () => {
trackGoal('SIGNUP01', 0);
};
return <form onSubmit={handleSubmit}>...</form>;
}
Tag Manager Integrations
Google Tag Manager
Base Fathom Script Tag:
- Create new Custom HTML tag
- Name: "Fathom Analytics - Base Script"
- HTML:
<script>
(function() {
var script = document.createElement('script');
script.src = 'https://cdn.usefathom.com/script.js';
script.setAttribute('data-site', 'ABCDEFGH');
script.defer = true;
document.head.appendChild(script);
})();
</script>
- Trigger: All Pages
Goal Tracking Tag:
- Create new Custom HTML tag
- Name: "Fathom - Track Goal"
- HTML:
<script>
window.fathom = window.fathom || function() {
(window.fathom.q = window.fathom.q || []).push(arguments)
};
fathom('trackGoal', '{{Goal ID Variable}}', {{Revenue Variable}});
</script>
- Set up variables for Goal ID and Revenue
- Create trigger for specific events
Example: Form Submission Tracking:
- Create form submit trigger
- Create variables:
- Goal ID:
FORMSUBM - Revenue:
0
- Goal ID:
- Apply trigger to goal tracking tag
Segment
JavaScript Source Integration:
analytics.ready(function() {
// Initialize Fathom when Segment loads
var script = document.createElement('script');
script.src = 'https://cdn.usefathom.com/script.js';
script.setAttribute('data-site', 'ABCDEFGH');
script.defer = true;
document.head.appendChild(script);
});
// Track Segment events as Fathom goals
analytics.track('Signup', {}, function() {
if (window.fathom) {
fathom.trackGoal('SIGNUP01', 0);
}
});
Server-Side Integration: Use Fathom's Events API to send server-side Segment events.
API Integration
Events API
Endpoint:
POST https://cdn.usefathom.com/api/event
Authentication: No authentication required for event tracking (uses Site ID).
Request Format:
curl -X POST https://cdn.usefathom.com/api/event \
-H 'Content-Type: application/json' \
-d '{
"site": "ABCDEFGH",
"name": "pageview",
"url": "https://yourdomain.com/page"
}'
Track Goal via API:
curl -X POST https://cdn.usefathom.com/api/event \
-H 'Content-Type: application/json' \
-d '{
"site": "ABCDEFGH",
"name": "goal",
"goal": "SIGNUP01",
"value": 0
}'
Node.js API Integration
const fetch = require('node-fetch');
async function trackFathomGoal(siteId, goalId, value = 0) {
try {
const response = await fetch('https://cdn.usefathom.com/api/event', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
site: siteId,
name: 'goal',
goal: goalId,
value: value,
}),
});
return response.ok;
} catch (error) {
console.error('Fathom tracking failed:', error);
return false;
}
}
// Usage
await trackFathomGoal('ABCDEFGH', 'PURCHASE', 9999);
Python API Integration
import requests
def track_fathom_goal(site_id, goal_id, value=0):
try:
response = requests.post(
'https://cdn.usefathom.com/api/event',
json={
'site': site_id,
'name': 'goal',
'goal': goal_id,
'value': value
}
)
return response.status_code == 200
except Exception as e:
print(f'Fathom tracking failed: {e}')
return False
# Usage
track_fathom_goal('ABCDEFGH', 'PURCHASE', 9999)
Email & Marketing Integrations
Email Campaigns
Track Email Link Clicks:
<!-- Add UTM parameters to links -->
<a href="https://yourdomain.com/landing?utm_source=email&utm_medium=newsletter&utm_campaign=launch">
View Offer
</a>
Fathom automatically tracks referrer sources including UTM parameters.
ConvertKit
Track form signups:
// Add to thank you page or success callback
if (window.fathom) {
fathom.trackGoal('EMAILSUB', 0);
}
Mailchimp
Embed tracking on landing pages:
<!-- Mailchimp hosted landing page -->
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
<script>
// Track successful signup
document.querySelector('#mc-embedded-subscribe-form').addEventListener('submit', function() {
if (window.fathom) {
fathom.trackGoal('MAILSUB1', 0);
}
});
</script>
Payment & Ecommerce Integrations
Stripe
Track Successful Payments:
// Client-side after Stripe redirect
const urlParams = new URLSearchParams(window.location.search);
const sessionId = urlParams.get('session_id');
if (sessionId && window.fathom) {
// Fetch session details from your backend
fetch(`/api/checkout-session?session_id=${sessionId}`)
.then(res => res.json())
.then(data => {
const cents = Math.round(data.amount_total / 100);
fathom.trackGoal('PURCHASE', cents);
});
}
Server-Side Webhook:
// Node.js - Stripe webhook handler
app.post('/webhook', express.raw({type: 'application/json'}), (req, res) => {
const event = req.body;
if (event.type === 'checkout.session.completed') {
const session = event.data.object;
// Track via Fathom API
trackFathomGoal('ABCDEFGH', 'PURCHASE', session.amount_total);
}
res.json({received: true});
});
Gumroad
Product Purchase Tracking:
<!-- Add to product thank you page -->
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
<script>
// Gumroad provides sale data in URL
const urlParams = new URLSearchParams(window.location.search);
if (urlParams.has('sale_id') && window.fathom) {
fathom.trackGoal('PURCHASE', 0);
}
</script>
Custom Integrations
Zapier
Setup:
- Use Webhooks by Zapier
- Configure POST to Fathom Events API
- Map data to Fathom event structure
Zap Configuration:
- Trigger: Your app event (e.g., new form submission)
- Action: Webhooks POST
- URL:
https://cdn.usefathom.com/api/event - Payload:
{
"site": "ABCDEFGH",
"name": "goal",
"goal": "ZAPGOAL1",
"value": 0
}
Make (Integromat)
HTTP Module:
- Add HTTP module
- Method: POST
- URL:
https://cdn.usefathom.com/api/event - Body:
{
"site": "{{site_id}}",
"name": "goal",
"goal": "{{goal_id}}",
"value": {{value}}
}
Best Practices
Performance Optimization
Use defer attribute:
<script src="https://cdn.usefathom.com/script.js" data-site="ABCDEFGH" defer></script>
Custom domain for speed and reliability:
<script src="https://stats.yourdomain.com/script.js" data-site="ABCDEFGH" defer></script>
Privacy Compliance
Exclude internal traffic:
<script src="https://cdn.usefathom.com/script.js"
data-site="ABCDEFGH"
data-excluded-domains="localhost,staging.yourdomain.com"
defer></script>
Honor Do Not Track (optional):
<script src="https://cdn.usefathom.com/script.js"
data-site="ABCDEFGH"
data-honor-dnt="true"
defer></script>
Error Handling
function trackGoal(goalId, value = 0) {
if (typeof window !== 'undefined' && window.fathom) {
try {
window.fathom.trackGoal(goalId, value);
} catch (error) {
console.error('Goal tracking failed:', error);
}
}
}
Testing Integrations
- Use excluded domains for development
- Create separate test site for staging
- Monitor network requests in DevTools
- Verify goals in Fathom dashboard
- Test on multiple devices and browsers
Additional Resources: