From 43330579bd4490f214133100bddb6c06031a8908 Mon Sep 17 00:00:00 2001 From: Sped0n Date: Fri, 3 Nov 2023 14:25:20 +0800 Subject: [PATCH] feat(seo.html): add meta tags for site verification codes (Google, Bing, Yandex, Pinterest, Baidu, So, Sogou) to improve SEO and site ownership verification feat(analytics.html): create partial to include analytics scripts for various analytics services (Google Analytics, Fathom Analytics, Baidu Analytics, Umami Analytics, Plausible Analytics, Cloudflare Analytics, Splitbee Analytics) to track website traffic and user behavior --- exampleSite/config/_default/params.toml | 49 +++++++++++++++ layouts/_default/baseof.html | 3 + layouts/partials/head/seo.html | 21 +++++++ layouts/partials/plugin/analytics.html | 84 +++++++++++++++++++++++++ 4 files changed, 157 insertions(+) create mode 100644 layouts/partials/plugin/analytics.html diff --git a/exampleSite/config/_default/params.toml b/exampleSite/config/_default/params.toml index c050aee..5d28278 100644 --- a/exampleSite/config/_default/params.toml +++ b/exampleSite/config/_default/params.toml @@ -4,3 +4,52 @@ description = "Bridget is a minimal Hugo theme designed for photographers / visu # * if you want to build the js and css from scratch, set this to false and run `npm install` and `npm run build` # * tldr: set this to false if you want to edit the js and css bundled = false + +# Site verification code for Google/Bing/Yandex/Pinterest/Baidu +[verification] +google = "" +bing = "" +yandex = "" +pinterest = "" +baidu = "" +so = "" +sogou = "" + +# Analytics config +[analytics] +enable = false +# Google Analytics +[analytics.google] +id = "" +# whether to anonymize IP +anonymizeIP = true +# Fathom Analytics +[analytics.fathom] +id = "" +# server url for your tracker if you're self hosting +server = "" +# Baidu Analytics +[analytics.baidu] +id = "" +# Umami Analytics +[analytics.umami] +data_website_id = "" +src = "" +data_host_url = "" +data_domains = "" +# Plausible Analytics +[analytics.plausible] +data_domain = "" +src = "" +# Cloudflare Analytics +[analytics.cloudflare] +token = "" +# Splitbee Analytics +[analytics.splitbee] +enable = false +# no cookie mode +No_cookie = true +# respect the do not track setting of the browser +Do_not_track = true +# token(optional), more info on https://splitbee.io/docs/embed-the-script +data_token = "" diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 2dade46..19f9ec4 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -13,5 +13,8 @@ {{- block "main" . -}} {{- end -}} +
+ {{- partial "plugin/analytics.html" . -}} +
diff --git a/layouts/partials/head/seo.html b/layouts/partials/head/seo.html index e69de29..f49d864 100644 --- a/layouts/partials/head/seo.html +++ b/layouts/partials/head/seo.html @@ -0,0 +1,21 @@ +{{- with site.Params.verification.google -}} + +{{- end -}} +{{- with site.Params.verification.bing -}} + +{{- end -}} +{{- with site.Params.verification.yandex -}} + +{{- end -}} +{{- with site.Params.verification.pinterest -}} + +{{- end -}} +{{- with site.Params.verification.baidu -}} + +{{- end -}} +{{- with site.Params.verification.sogou -}} + +{{- end -}} +{{- with site.Params.verification.so -}} + +{{- end -}} diff --git a/layouts/partials/plugin/analytics.html b/layouts/partials/plugin/analytics.html new file mode 100644 index 0000000..ef18f45 --- /dev/null +++ b/layouts/partials/plugin/analytics.html @@ -0,0 +1,84 @@ +{{- $analytics := site.Params.analytics -}} + +{{- if $analytics.enable -}} + {{- /* Google Analytics */ -}} + {{- with $analytics.google.id -}} + {{- printf "https://www.googletagmanager.com/gtag/js?id=%v" . | dict "Async" true "Source" | partial "plugin/script.html" -}} + {{- end -}} + + {{- /* Fathom Analytics */ -}} + {{- with $analytics.fathom.id -}} + {{- dict "Source" ($analytics.fathom.server | default "cdn.usefathom.com" | printf "https://%v/tracker.js") "Async" true "Attr" "id=fathom-script" | partial "plugin/script.html" -}} + {{- end -}} + + {{- /* Baidu Analytics */ -}} + {{- with $analytics.baidu.id -}} + + {{- end -}} + + {{- /* Umami Analytics */ -}} + {{- with $analytics.umami.data_website_id -}} + + {{- end -}} + + {{- /* Plausible Analytics */ -}} + {{- with $analytics.plausible.data_domain -}} + + {{- end -}} + + {{- /* Cloudflare Analytics */ -}} + {{- with $analytics.cloudflare.token -}} + + {{- end -}} + + {{- /* Splitbee Analytics */ -}} + {{- if $analytics.splitbee.enable -}} + {{- $attr := "" -}} + {{- if $analytics.splitbee.Do_not_track -}} + {{- $attr = printf `%v data-respect-dnt` $attr -}} + {{- end -}} + {{- if $analytics.splitbee.No_cookie -}} + {{- $attr = printf `%v data-no-cookie` $attr -}} + {{- end -}} + {{- with $analytics.splitbee.data_token -}} + {{- $attr = printf `%v data-token="%v"` $attr . -}} + {{- end -}} + + {{- end -}} + +{{- end -}}