如何在 Discourse 中嵌入跟踪 JS

我正在使用 Fathom Analytics,并尝试嵌入一段用于网站追踪的 JS 脚本,代码如下:

<!-- Fathom - 简单的网站分析工具 - 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 -->

我通过“自定义 > 主题 > 自定义 CSS/HTML”设置将此脚本添加到 <head> 部分。
但当我加载网站时,Fathom 的 tracker.js 脚本获取失败:


控制台还显示了其他错误:

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)

看起来 Fathom 干扰了该 JS 脚本的获取。我该如何解决这个问题?

我使用的版本是 2.6.0.beta1

哦,我还应该补充一点,我已经看到了以下内容:

并且已将我的 Fathom 域名添加到内容安全策略(Content Security Policy)的允许域名列表中。

2 个赞

@jakubgs

把这篇旧文翻出来了!

你成功让它运行起来了吗?我正在考虑用 Fathom 替换 Google Analytics。