From a9cb5630a21a320d3d3c1afe3781fd289129273e Mon Sep 17 00:00:00 2001
From: Alexander Bilz <mail@alexbilz.com>
Date: Tue, 01 Feb 2022 16:40:51 +0000
Subject: [PATCH] feat: added umami analytics (#298)

---
 layouts/partials/analytics/umami.html   |    6 ++++++
 layouts/partials/head.html              |    6 ++++++
 exampleSite/config/_default/params.toml |    4 ++++
 README.md                               |   13 ++++++++++++-
 4 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/README.md b/README.md
index aa34ab3..aae1562 100644
--- a/README.md
+++ b/README.md
@@ -28,6 +28,7 @@
 - Comments powered by Disqus, Commento or Utteranc.es (optional)
 - SimpleAnalytics (optional)
 - Plausible Analytics (optional)
+- Umami Analytics (optional)
 - KaTex support (optional)
 - Formspree Contact Form (optional)
 - Twitter Cards support
@@ -409,7 +410,7 @@
 
 ### Plausible Analytics
 
-To use Plausible Analytics, include the following section and change the domain to your site's domain. If you self-host Plausible, you can optionally specify the url of your own instance.
+To use Plausible Analytics, include the following section and change the domain to your site's domain. If you self-host Plausible, you can optionally specify the URL of your own instance.
 
 ```toml
 [params.plausibleAnalytics]
@@ -417,6 +418,16 @@
 # serverURL = "https://analytics.example.com"
 ```
 
+### Umami Analytics
+
+To use Umami Analytics, include the following section and change the serverURL to your self-hosted Umami server URL. Additionally, you will need to provide your website ID.
+
+```toml
+[params.umami]
+serverURL = "example.com"
+id = "94db1cb1-74f4-4a40-ad6c-962362670409"
+```
+
 ### Google Site Verification
 
 To use Google Site Verification, add the following line to the `[params]`:
diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml
index 86fa4d2..ed6a32f 100644
--- a/exampleSite/config/_default/params.toml
+++ b/exampleSite/config/_default/params.toml
@@ -38,6 +38,10 @@
 # domain = "example.com"
 # serverURL = "https://analytics.example.com"
 
+[umami]
+# serverURL = "example.com"
+# id = "94db1cb1-74f4-4a40-ad6c-962362670409"
+
 ## Math settings
 [math]
 enable = false  # options: true, false. Enable math support globally, default: false. You can always enable math on per page.
diff --git a/layouts/partials/analytics/umami.html b/layouts/partials/analytics/umami.html
new file mode 100644
index 0000000..2d3c81f
--- /dev/null
+++ b/layouts/partials/analytics/umami.html
@@ -0,0 +1,6 @@
+<script
+  async
+  defer
+  src="https://{{ .Site.Params.umami.serverURL }}/umami.js"
+  data-website-id="{{ .Site.Params.umami.id }}"
+></script>
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 4590e85..b3dd202 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -200,6 +200,12 @@
   {{ if and hugo.IsProduction .Site.Params.plausibleAnalytics .Site.Params.plausibleAnalytics.domain }}
     {{- partial "analytics/plausible" . -}}
 
+
+  {{ end }}
+
+  {{ if and hugo.IsProduction .Site.Params.umami.serverURL .Site.Params.umami.id }}
+    {{- partial "analytics/umami" . -}}
+
   {{ end }}
 
 

--
Gitblit v1.10.0