mirror of
https://github.com/dillonzq/LoveIt.git
synced 2025-03-13 11:18:15 +01:00
feat(analytics): update Google Analytics (#946)
This commit is contained in:
parent
a8be674413
commit
c4baf9ee7d
5 changed files with 71 additions and 54 deletions
|
@ -725,12 +725,15 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
|
||||
# {{< version 0.2.0 >}} Analytics config
|
||||
[params.analytics]
|
||||
enable = false
|
||||
# {{< version 0.3.1 deleted >}}
|
||||
enable = true
|
||||
# Google Analytics
|
||||
[params.analytics.google]
|
||||
id = ""
|
||||
# whether to anonymize IP
|
||||
# {{< version 0.3.1 deleted >}} whether to anonymize IP
|
||||
anonymizeIP = true
|
||||
# {{< version 0.3.1 >}} whether to respect the browser’s “do not track” setting
|
||||
respectDoNotTrack = false
|
||||
# Fathom Analytics
|
||||
[params.analytics.fathom]
|
||||
id = ""
|
||||
|
@ -810,7 +813,7 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
|
||||
# {{< link "https://gohugo.io/about/hugo-and-gdpr/" "Privacy config" >}}
|
||||
[privacy]
|
||||
# {{< version 0.2.0 deleted >}} privacy of the Google Analytics (replaced by params.analytics.google)
|
||||
# {{< version 0.3.1 changed >}} privacy of the Google Analytics (can also be configured in params.analytics.google)
|
||||
[privacy.googleAnalytics]
|
||||
# ...
|
||||
[privacy.twitter]
|
||||
|
|
|
@ -727,12 +727,15 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
|
||||
# {{< version 0.2.0 >}} 网站分析配置
|
||||
[params.analytics]
|
||||
enable = false
|
||||
# {{< version 0.3.1 deleted >}}
|
||||
enable = true
|
||||
# Google Analytics
|
||||
[params.analytics.google]
|
||||
id = ""
|
||||
# 是否匿名化用户 IP
|
||||
# {{< version 0.3.1 deleted >}} 是否匿名化用户 IP
|
||||
anonymizeIP = true
|
||||
# {{< version 0.3.1 >}} 是否遵循浏览器的 “Do Not Track” 设置
|
||||
respectDoNotTrack = false
|
||||
# Fathom Analytics
|
||||
[params.analytics.fathom]
|
||||
id = ""
|
||||
|
@ -812,7 +815,7 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
|
||||
# {{< link "https://gohugo.io/about/hugo-and-gdpr/" "隐私信息配置" >}}
|
||||
[privacy]
|
||||
# {{< version 0.2.0 deleted >}} Google Analytics 相关隐私 (被 params.analytics.google 替代)
|
||||
# {{< version 0.3.1 changed >}} Google Analytics 相关隐私设置 (也能在 params.analytics.google 配置)
|
||||
[privacy.googleAnalytics]
|
||||
# ...
|
||||
[privacy.twitter]
|
||||
|
|
|
@ -658,13 +658,12 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
# Analytics config
|
||||
# 网站分析配置
|
||||
[params.analytics]
|
||||
enable = false
|
||||
# Google Analytics
|
||||
[params.analytics.google]
|
||||
id = ""
|
||||
# whether to anonymize IP
|
||||
# 是否匿名化用户 IP
|
||||
anonymizeIP = true
|
||||
# whether to respect the browser’s “do not track” setting
|
||||
# 是否遵循浏览器的 “Do Not Track” 设置
|
||||
respectDoNotTrack = false
|
||||
# Fathom Analytics
|
||||
[params.analytics.fathom]
|
||||
id = ""
|
||||
|
@ -760,11 +759,11 @@ ignoreErrors = ["error-remote-getjson", "error-missing-instagram-accesstoken"]
|
|||
# posts = ":year/:month/:filename"
|
||||
posts = ":filename"
|
||||
|
||||
# Privacy config (https://gohugo.io/about/hugo-and-gdpr/)
|
||||
# 隐私信息配置 (https://gohugo.io/about/hugo-and-gdpr/)
|
||||
# Privacy config (https://gohugo.io/configuration/privacy/)
|
||||
# 隐私信息配置 (https://gohugo.io/configuration/privacy/)
|
||||
[privacy]
|
||||
# privacy of the Google Analytics (replaced by params.analytics.google)
|
||||
# Google Analytics 相关隐私 (被 params.analytics.google 替代)
|
||||
# privacy of the Google Analytics (can also be configured in params.analytics.google)
|
||||
# Google Analytics 相关隐私设置 (也能在 params.analytics.google 配置)
|
||||
[privacy.googleAnalytics]
|
||||
# ...
|
||||
[privacy.twitter]
|
||||
|
|
|
@ -578,13 +578,12 @@
|
|||
# Analytics config
|
||||
# 网站分析配置
|
||||
[params.analytics]
|
||||
enable = false
|
||||
# Google Analytics
|
||||
[params.analytics.google]
|
||||
id = ""
|
||||
# whether to anonymize IP
|
||||
# 是否匿名化用户 IP
|
||||
anonymizeIP = true
|
||||
# whether to respect the browser’s “do not track” setting
|
||||
# 是否遵循浏览器的 “Do Not Track” 设置
|
||||
respectDoNotTrack = false
|
||||
# Fathom Analytics
|
||||
[params.analytics.fathom]
|
||||
id = ""
|
||||
|
|
|
@ -1,32 +1,46 @@
|
|||
{{- $analytics := .Scratch.Get "analytics" | default dict -}}
|
||||
|
||||
{{- if $analytics.enable -}}
|
||||
{{- /* Google Analytics */ -}}
|
||||
{{- with $analytics.google.id -}}
|
||||
{{- /* Google Analytics */ -}}
|
||||
{{- $google := $analytics.google.id | default site.Config.Services.GoogleAnalytics.ID -}}
|
||||
{{- with $google -}}
|
||||
{{- if strings.HasPrefix (lower .) "ua-" -}}
|
||||
{{- warnf "Google Analytics 4 (GA4) replaced Google Universal Analytics (UA) effective 1 July 2023. See https://support.google.com/analytics/answer/11583528. Create a GA4 property and data stream, then replace the Google Analytics ID in your site configuration with the new value." -}}
|
||||
{{- else -}}
|
||||
{{- $respectDoNotTrack := $analytics.google.respectDoNotTrack | default site.Config.Privacy.GoogleAnalytics.RespectDoNotTrack -}}
|
||||
<script>
|
||||
window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());
|
||||
gtag('config', '{{ . }}'{{ if $analytics.google.anonymizeIP }}, { 'anonymize_ip': true }{{ end }});
|
||||
var doNotTrack = false;
|
||||
if ({{ $respectDoNotTrack }}) {
|
||||
var dnt = (navigator.doNotTrack || window.doNotTrack || navigator.msDoNotTrack);
|
||||
var doNotTrack = (dnt == "1" || dnt == "yes");
|
||||
}
|
||||
if (!doNotTrack) {
|
||||
window.dataLayer = window.dataLayer || [];
|
||||
function gtag(){dataLayer.push(arguments);}
|
||||
gtag('js', new Date());
|
||||
gtag('config', '{{ . }}');
|
||||
}
|
||||
</script>
|
||||
{{- printf "https://www.googletagmanager.com/gtag/js?id=%v" . | dict "Async" true "Source" | partial "plugin/script.html" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Fathom Analytics */ -}}
|
||||
{{- with $analytics.fathom.id -}}
|
||||
{{- /* Fathom Analytics */ -}}
|
||||
{{- with $analytics.fathom.id -}}
|
||||
<script>
|
||||
window.fathom=window.fathom||function(){(fathom.q=fathom.q||[]).push(arguments);};
|
||||
fathom('set', 'siteId', '{{ . }}');
|
||||
fathom('trackPageview');
|
||||
</script>
|
||||
{{- 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 -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Plausible Analytics */ -}}
|
||||
{{- with $analytics.plausible.dataDomain -}}
|
||||
{{- /* Plausible Analytics */ -}}
|
||||
{{- with $analytics.plausible.dataDomain -}}
|
||||
{{- dict "Source" "https://plausible.io/js/plausible.js" "Async" true "Defer" true "Attr" ($analytics.plausible.dataDomain | printf `data-domain="%v"`) | partial "plugin/script.html" -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Yandex Metrica */ -}}
|
||||
{{- with $analytics.yandexMetrica.id -}}
|
||||
{{- /* Yandex Metrica */ -}}
|
||||
{{- with $analytics.yandexMetrica.id -}}
|
||||
<script>
|
||||
(function(m,e,t,r,i,k,a){m[i]=m[i]||function(){(m[i].a=m[i].a||[]).push(arguments)};
|
||||
m[i].l=1*new Date();k=e.createElement(t),a=e.getElementsByTagName(t)[0],k.async=1,k.src=r,a.parentNode.insertBefore(k,a)})
|
||||
|
@ -39,5 +53,4 @@
|
|||
});
|
||||
</script>
|
||||
<noscript><div><img src="https://mc.yandex.ru/watch/{{ . }}" style="position:absolute; left:-9999px;" alt="" /></div></noscript>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
|
Loading…
Add table
Reference in a new issue