From 93fb14e953a1c0275635093f6d22268236b3f216 Mon Sep 17 00:00:00 2001
From: Yash Mehrotra <yashmehrotra95@gmail.com>
Date: Tue, 11 Feb 2020 14:28:14 +0000
Subject: [PATCH] Add support for Fathom Analytics (#264)

---
 exampleSite/config.toml                |    6 ++++++
 layouts/_default/baseof.html           |    4 ++++
 CONTRIBUTORS.md                        |    1 +
 layouts/partials/analytics/fathom.html |   13 +++++++++++++
 4 files changed, 24 insertions(+), 0 deletions(-)

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index fbfcd3e..8873dc6 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -56,3 +56,4 @@
 - [Anson VanDoren](https://github.com/anson-vandoren)
 - [Michael Lynch](https://github.com/mtlynch)
 - [FIGBERT](https://figbert.com/)
+- [Yash Mehrotra](https://yashmehrotra.com)
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index 2a38e9b..61ed225 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -50,6 +50,12 @@
     # Custom JS
     custom_js = []
 
+# If you want to use fathom(https://usefathom.com) for analytics, add this section
+[params.fathomAnalytics]
+    siteID = "ABCDE"
+    # Default value is cdn.usefathom.com, overwrite this if you are self-hosting
+    serverURL = "analytics.example.com"
+
 [taxonomies]
   category = "categories"
   series = "series"
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 3824e2e..a497e5d 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -108,6 +108,10 @@
 
     {{ template "_internal/google_analytics.html" . }}
 
+    {{ if and .Site.Params.fathomAnalytics .Site.Params.fathomAnalytics.siteID }}
+      {{- partial "analytics/fathom" . -}}
+    {{ end }}
+
   </body>
 
 </html>
diff --git a/layouts/partials/analytics/fathom.html b/layouts/partials/analytics/fathom.html
new file mode 100644
index 0000000..13e7cfc
--- /dev/null
+++ b/layouts/partials/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>

--
Gitblit v1.10.0