From 34ac982a4bf9558ad0734ec49a09c3b1cd6ef6ed Mon Sep 17 00:00:00 2001
From: Rhys Perry <rhysperry111@gmail.com>
Date: Tue, 11 Aug 2020 19:02:49 +0000
Subject: [PATCH] Add support for plausible analytics (#382)

---
 exampleSite/config.toml                   |    6 ++++++
 layouts/_default/baseof.html              |    4 ++++
 layouts/partials/analytics/plausible.html |    1 +
 stackbit.yaml                             |   10 ++++++++++
 CONTRIBUTORS.md                           |    1 +
 5 files changed, 22 insertions(+), 0 deletions(-)

diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md
index d51156b..b992ca2 100644
--- a/CONTRIBUTORS.md
+++ b/CONTRIBUTORS.md
@@ -71,3 +71,4 @@
 - [Endormi](https://endormi.io)
 - [Rajiv Ranjan Singh](https://iamrajiv.github.io/)
 - [Pakhomov Alexander](https://github.com/PakhomovAlexander)
+- [Rhys Perry](https://rhysperry.com)
diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index d2e54a2..c95ec45 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -60,6 +60,12 @@
     siteID = "ABCDE"
     # Default value is cdn.usefathom.com, overwrite this if you are self-hosting
     serverURL = "analytics.example.com"
+    
+# If you want to use plausible(https://plausible.io) for analytics, add this section
+[params.plausibleAnalytics]
+    domain = "example.com"
+    # Default value is plausible.io, overwrite this if you are self-hosting or using a custom domain
+    serverURL = "analytics.example.com"
 
 [taxonomies]
   category = "categories"
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 825fccd..389275d 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -127,6 +127,10 @@
       {{- partial "analytics/fathom" . -}}
     {{ end }}
 
+    {{ if and .Site.Params.plausibleAnalytics .Site.Params.plausibleAnalytics.domain }}
+      {{- partial "analytics/plausible" . -}}
+    {{ end }}
+
   </body>
 
 </html>
diff --git a/layouts/partials/analytics/plausible.html b/layouts/partials/analytics/plausible.html
new file mode 100644
index 0000000..d36ba4b
--- /dev/null
+++ b/layouts/partials/analytics/plausible.html
@@ -0,0 +1 @@
+<script async defer data-domain=”{{ .Site.Params.plausibleAnalytics.domain }}” src=”https://{{ .Site.Params.plausibleAnalytics.serverURL | default "plausible.io" }}/js/index.js”></script> 
diff --git a/stackbit.yaml b/stackbit.yaml
index dd3592f..1050376 100644
--- a/stackbit.yaml
+++ b/stackbit.yaml
@@ -114,6 +114,16 @@
               - type: string
                 name: serverURL
                 label: URL for Fathom Analytics
+          - type: object
+            name: plausibleAnalytics
+            label: Plausible Analytics (optional)
+            fields:
+              - type: string
+                name: domain
+                label: Website domain for Plausible Analytics
+              - type: string
+                name: serverURL
+                label: URL for Plausible Analytics
       - type: object
         name: languages
         fields:

--
Gitblit v1.10.0