These are the advanced options we offer with our embed script. Our standard script installation (pasting a single line of code into your site) works great for most customers.
By default, our script is deferred, meaning our script loads once your HTML has finished loading. That means our script doesn’t affect your site load time or speed in any way (fast sites == better search engine rankings).You can also swap out defer with async or just load it without either, but we don’t advise this. Instead, this is how our code should be most commonly used:
By default, we collect data on every visitor to your website, regardless of them having DNT turned on or not. That’s because Fathom is privacy-focused analytics, so nothing personal or identifiable is ever “tracked.” Plus, DNT is deprecated and no longer recommended by any browser.That said, if you would like to honor DNT then update your code to include data-honor-dnt="true":
By default, we collect a page view every time a visitor to your website loads a page with our script on it. If you don’t want that functionality, you can turn it off by using data-auto="false":
If there’s a canonical URL in place, we use it instead of the current URL. This is what most customers want, and it’s why it’s the default. If you want to use the current URL, even if there’s canonical (ignoring the canonical), then use data-canonical="false":
If there’s no Fathom integration for your specific javascript system, you can use our generic SPA mode. Most applications use HTML5 History API, so the following code will typically work as-is. This code checks if the History API is available, and if it’s not, it falls back to listening to hash changes:
Note: this code will still collect data about the initial load. See Disable automatic tracking above if you don’t want this.If you want to explicitly say, “We are using only HTML5 History API” or “We only use hash-based routing,” you can use one of the following snippets:
The typical use case for using this would be for someone handling routing manually themselves. Perhaps they have their own SPA / AJAX page loading or want more control over the data they send to Fathom.
Copy
Ask AI
fathom.trackPageview();
In addition to this, you can also go more complex and set your own parameters (when using this method, the canonical will not be used, as this becomes the source of truth):
You do not have to send both of these properties. If you send just the referrer, the URL will be established using the default method (canonical or current URL).
Events are useful for collecting data on elements that visitors can interact with on your site, such as button clicks, form submissions, etc.
Copy
Ask AI
// Required: Event Name (string), descriptive name used to identify the event data in your dashboard// Optional: Value (integer), the value is in cents. The below example equals $1.00fathom.trackEvent('Your Event Name Here' { _value: 100});