From b84efff11943dc926d5e04892c215d5533dc4bc0 Mon Sep 17 00:00:00 2001
From: Marc-Niclas Harm <dev@codehat.de>
Date: Sun, 30 Jan 2022 16:16:27 +0000
Subject: [PATCH] feat: Added Plausible Analytics (#296)
---
layouts/partials/analytics/plausible.html | 1 +
layouts/partials/head.html | 3 +++
exampleSite/config/_default/params.toml | 4 ++++
README.md | 11 +++++++++++
4 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/README.md b/README.md
index e05bd5e..aa34ab3 100644
--- a/README.md
+++ b/README.md
@@ -27,6 +27,7 @@
- Google Analytics (optional)
- Comments powered by Disqus, Commento or Utteranc.es (optional)
- SimpleAnalytics (optional)
+- Plausible Analytics (optional)
- KaTex support (optional)
- Formspree Contact Form (optional)
- Twitter Cards support
@@ -406,6 +407,16 @@
# customurl = "https://analytics.example.com"
```
+### 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.
+
+```toml
+[params.plausibleAnalytics]
+domain = "example.com"
+# serverURL = "https://analytics.example.com"
+```
+
### 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 e131c32..86fa4d2 100644
--- a/exampleSite/config/_default/params.toml
+++ b/exampleSite/config/_default/params.toml
@@ -34,6 +34,10 @@
# enable = true
# customurl = "https://analytics.example.com"
+[plausibleAnalytics]
+# domain = "example.com"
+# serverURL = "https://analytics.example.com"
+
## 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/plausible.html b/layouts/partials/analytics/plausible.html
new file mode 100644
index 0000000..25eeb53
--- /dev/null
+++ b/layouts/partials/analytics/plausible.html
@@ -0,0 +1 @@
+<script async defer data-domain="{{ .Site.Params.plausibleAnalytics.domain }}" src="{{ .Site.Params.plausibleAnalytics.serverURL | default "https://plausible.io" }}/js/plausible.js"></script>
\ No newline at end of file
diff --git a/layouts/partials/head.html b/layouts/partials/head.html
index 42581d7..3356be1 100644
--- a/layouts/partials/head.html
+++ b/layouts/partials/head.html
@@ -197,6 +197,9 @@
{{- end -}}
+ {{ if and hugo.IsProduction .Site.Params.plausibleAnalytics .Site.Params.plausibleAnalytics.domain }}
+ {{- partial "analytics/plausible" . -}}
+ {{ end }}
<!-- Twitter Cards -->
{{ template "_internal/twitter_cards.html" . }}
--
Gitblit v1.10.0