Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(analytics): update Google analytics.js to gtag.js #349

Merged
merged 1 commit into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions exampleSite/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -975,9 +975,6 @@ enableEmoji = true
# whether to anonymize IP
# 是否匿名化用户 IP
anonymizeIP = true
# whether to use cookie
# 是否使用 cookie
cookie = false
# Fathom Analytics
[params.analytics.fathom]
id = ""
Expand Down
2 changes: 0 additions & 2 deletions exampleSite/content/posts/theme-documentation-basics.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -596,8 +596,6 @@ Please open the code block below to view the complete sample configuration :(far
id = ""
# whether to anonymize IP
anonymizeIP = true
# whether to use cookie
cookie = false
# Fathom Analytics
[params.analytics.fathom]
id = ""
Expand Down
2 changes: 0 additions & 2 deletions exampleSite/content/posts/theme-documentation-basics.fr.md
Original file line number Diff line number Diff line change
Expand Up @@ -601,8 +601,6 @@ Please open the code block below to view the complete sample configuration :(far
id = ""
# whether to anonymize IP
anonymizeIP = true
# whether to use cookie
cookie = false
# Fathom Analytics
[params.analytics.fathom]
id = ""
Expand Down
2 changes: 0 additions & 2 deletions exampleSite/content/posts/theme-documentation-basics.zh-cn.md
Original file line number Diff line number Diff line change
Expand Up @@ -599,8 +599,6 @@ hugo
id = ""
# 是否匿名化用户 IP
anonymizeIP = true
# 是否使用 cookie
cookie = false
# Fathom Analytics
[params.analytics.fathom]
id = ""
Expand Down
2 changes: 1 addition & 1 deletion layouts/_default/baseof.html
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{{- .Scratch.Set "version" "0.2.7" -}}
{{- $version := "0.2.X" -}}

{{- /* LoveIt theme version detection */ -}}
Expand All @@ -10,7 +11,6 @@
{{- end -}}

{{- $params := .Params | merge .Site.Params.page -}}
{{- .Scratch.Set "version" "0.2.6" -}}

{{- if eq hugo.Environment "production" -}}
{{- .Scratch.Set "cdn" .Site.Params.cdn -}}
Expand Down
10 changes: 4 additions & 6 deletions layouts/partials/plugin/analytics.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,16 @@
{{- /* Google Analytics */ -}}
{{- with .google.id -}}
<script type="text/javascript">
window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)};ga.l=+new Date;
ga('create', '{{ . }}', {{- if $.google.cookie }}'auto'{{ else }}{ 'storage': 'none' }{{ end }});
{{- if $.google.anonymizeIP }}ga('set', 'anonymizeIp', true);{{ end -}}
ga('send', 'pageview');
window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments);}gtag('js', new Date());
gtag('config', '{{ . }}'{{ if $.google.anonymizeIP }}, { 'anonymize_ip': true }{{ end }});
</script>
{{- dict "source" "https://www.google-analytics.com/analytics.js" "async" true | partial "plugin/script.html" -}}
{{- printf "https://www.googletagmanager.com/gtag/js?id=%s" . | dict "async" true "source" | partial "plugin/script.html" -}}
{{- end -}}

{{- /* Fathom Analytics */ -}}
{{- with .fathom.id -}}
<script type="text/javascript">
window.fathom=window.fathom||function(){(fathom.q=fathom.q||[]).push(arguments)};
window.fathom=window.fathom||function(){(fathom.q=fathom.q||[]).push(arguments);};
fathom('set', 'siteId', '{{ . }}');
fathom('trackPageview');
</script>
Expand Down