From dbe21a7fdf0d5556de5b2f2f8bdf4f64228ca241 Mon Sep 17 00:00:00 2001
From: YUJI <mail@yuji.ne.jp>
Date: Tue, 15 Dec 2020 19:38:06 +0000
Subject: [PATCH] Add support of Cloudflare Web Analytics (#492)

---
 exampleSite/config.toml                    |    4 ++++
 layouts/_default/baseof.html               |    4 ++++
 layouts/partials/analytics/cloudflare.html |    4 ++++
 stackbit.yaml                              |    7 +++++++
 4 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/exampleSite/config.toml b/exampleSite/config.toml
index 7020e38..751acf8 100644
--- a/exampleSite/config.toml
+++ b/exampleSite/config.toml
@@ -76,6 +76,10 @@
 [params.goatCounter]
     code = "code"
 
+# If you want to use Cloudflare Web Analytics(https://cloudflare.com) for analytics, add this section
+[params.cloudflare]
+    token = "token"
+
 [taxonomies]
   category = "categories"
   series = "series"
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 1603d5f..8922879 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -139,6 +139,10 @@
     {{ if and .Site.Params.goatCounter .Site.Params.goatCounter.code }}
       {{- partial "analytics/goatcounter" . -}}
     {{ end }}
+
+    {{ if and .Site.Params.cloudflare .Site.Params.cloudflare.token }}
+      {{- partial "analytics/cloudflare" . -}}
+    {{ end }}
   </body>
 
 </html>
diff --git a/layouts/partials/analytics/cloudflare.html b/layouts/partials/analytics/cloudflare.html
new file mode 100644
index 0000000..d8a732f
--- /dev/null
+++ b/layouts/partials/analytics/cloudflare.html
@@ -0,0 +1,4 @@
+<!-- Cloudflare Web Analytics -->
+<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
+        data-cf-beacon='{"token": "{{ $.Site.Params.cloudflare.token }}"}'></script>
+<!-- End Cloudflare Web Analytics -->
diff --git a/stackbit.yaml b/stackbit.yaml
index 65715fe..d7cfbd7 100644
--- a/stackbit.yaml
+++ b/stackbit.yaml
@@ -137,6 +137,13 @@
               - type: string
                 name: code
                 label: URL for Goat Counter
+          - type: object
+            name: cloudflare
+            label:  Cloudflare Web Analytics (optional)
+            fields:
+              - type: string
+                name: token
+                label: token for Cloudflare Web Analytics
       - type: object
         name: languages
         fields:

--
Gitblit v1.10.0