Add Fathom Analytics to your Obsidian Publish site

Today I figured out how to embed the tracking code for Fathom Analytics into an Obsidian Publish website. It's easy.

  1. Create a file in the root of your Obsidian Vault called publish.js - You'll need to use an editor like VS Code for this as Obsidian won't handle it.
  2. Add this code to that file, replacing <your-site-code> with your actual site code.
var fathomSnippet = document.createElement('script');
fathomSnippet.defer = true;
fathomSnippet.setAttribute('data-site', '<your-site-code>');
fathomSnippet.src = 'https://cdn.usefathom.com/script.js';
document.head.appendChild(fathomSnippet);
  1. Use Obsidian to publish the publish.js file just like any other file.

That's it!