From a5d0b9a3ebc09467c67ea0964e2c41052787dc8b Mon Sep 17 00:00:00 2001 From: codedge <codedge@users.noreply.github.com> Date: Tue, 21 Apr 2020 17:37:05 +0200 Subject: [PATCH] Add fathom analytics (#200) Co-authored-by: Dillon <dillonzq@outlook.com> --- README.md | 1 + exampleSite/config.toml | 5 +++++ layouts/partials/assets.html | 6 +++++- layouts/partials/plugin/analytics/fathom.html | 13 +++++++++++++ 4 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 layouts/partials/plugin/analytics/fathom.html diff --git a/README.md b/README.md index 6d9b8c46..fc14b3a6 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,7 @@ I hope you will LoveIt ❤️! * Optimized for **performance**: 99/100 on mobile and 100/100 on desktop in [Google PageSpeed Insights](https://developers.google.com/speed/pagespeed/insights) * Optimized SEO performance with a correct **SEO SCHEMA** based on JSON-LD * [**Google Analytics**](https://analytics.google.com/analytics) supported +* [**Fathom Analytics**](https://usefathom.com/) supported * Search engine **verification** supported (Google, Bind, Yandex and Baidu) * **CDN** for third-party libraries supported * Automatically converted images with **Lazy Load** by [lazysizes](https://github.com/aFarkas/lazysizes) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index f5163d6c..6fd3bdce 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -782,6 +782,11 @@ enableEmoji = true yandex = "" pinterest = "" baidu = "" + [params.fathomAnalytics] + # siteID = "ABC123" + # If you're self hosting use this for your tracker + # serverURL = "https://example.com" + # CSS and JS Files CDN # CSS 和 JS 文件的 CDN 设置 [params.cdn] diff --git a/layouts/partials/assets.html b/layouts/partials/assets.html index be676a9d..d8952a0b 100644 --- a/layouts/partials/assets.html +++ b/layouts/partials/assets.html @@ -264,4 +264,8 @@ {{- /* Google analytics async */ -}} {{- if eq hugo.Environment "production" | and .Site.GoogleAnalytics -}} {{- template "_internal/google_analytics_async.html" . -}} -{{- end -}} + + {{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }} + {{- partial "plugin/analytics/fathom" . -}} + {{ end }} +{{- end -}} \ No newline at end of file diff --git a/layouts/partials/plugin/analytics/fathom.html b/layouts/partials/plugin/analytics/fathom.html new file mode 100644 index 00000000..89210b9a --- /dev/null +++ b/layouts/partials/plugin/analytics/fathom.html @@ -0,0 +1,13 @@ +<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, '//{{ .Site.Params.fathomAnalytics.serverURL | default "cdn.usefathom.com" }}/tracker.js', 'fathom'); + fathom('set', 'siteId', '{{ .Site.Params.fathomAnalytics.siteID }}'); + fathom('trackPageview'); +</script> \ No newline at end of file