Skip to content

Commit

Permalink
feat(analytics): update Google analytics.js to gtag.js (#349)
Browse files Browse the repository at this point in the history
  • Loading branch information
dillonzq authored May 12, 2020
1 parent 2ab3d97 commit 83869e0
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 16 deletions.
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

0 comments on commit 83869e0

Please sign in to comment.