How can I embed tracking JS into Discourse

I’m using Fathom Analytics and trying to embed some JS script for site tracking, which looks like this:

<!-- Fathom - simple website analytics - https://github.com/usefathom/fathom -->
<script>
(function(f, a, t, h, o, m){
	a[h]=a[h]||function(){
		(a[h].q=a[h].q||[]).push(arguments)
	};
	o=f.createElement('script'),
	m=f.getElementsByTagName('script')[0];
	o.async=1; o.src=t; o.id='fathom-script';
	m.parentNode.insertBefore(o,m)
})(document, window, '//fathom.example.org/tracker.js', 'fathom');
fathom('set', 'siteId', 'ABCDEF');
fathom('trackPageview');
</script>
<!-- / Fathom -->

I’m adding this to <head> section via the Customize > Theme > Custom CSS/HTML settings.
But when I load the side the fetching of the Fathom tracker.js script fails:


And the console show other failures:

Uncaught (in promise) no-response: no-response :: [{"url":"https://fathom.example.org/tracker.js"}]
    at a.makeRequest (https://discuss.example.org/javascripts/workbox/workbox-strategies.prod.js:1:2145)

It seems like Fathom is messing with the fetching of that JS. How am I supposed to do this?

I’m on 2.6.0.beta1.

Oh, and I should also add that I have seen this:

And have added my Fathom domain to allows ones in the Content Security Policy allowed domains.

2 Likes

Hey @jakubgs

digging out this oldie!

Have you been able to make it work? I am considering fathom to replace google analytics.