Skip to content

Commit

Permalink
fix: fix Google Analytics script
Browse files Browse the repository at this point in the history
Verifying domain on Google Search Console via Google Analytics, the
script must be put in the <head> section
  • Loading branch information
junyussh committed Mar 4, 2020
1 parent 7f32a4f commit f09b85c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
16 changes: 16 additions & 0 deletions layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,19 @@
<script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->` | safeHTML }}

<!-- Analytics -->
{{- if .Site.GoogleAnalytics -}}
<!-- {{ template "_internal/google_analytics_async.html" . }}-->
<script>
(function (i, s, o, g, r, a, m) {
i['GoogleAnalyticsObject'] = r; i[r] = i[r] || function () {
(i[r].q = i[r].q || []).push(arguments)
}, i[r].l = 1 * new Date(); a = s.createElement(o),
m = s.getElementsByTagName(o)[0]; a.async = 1; a.src = g; m.parentNode.insertBefore(a, m)
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');

ga('create', '{{ .Site.GoogleAnalytics }}', 'auto');
ga('send', 'pageview');
</script>
{{- end -}}
4 changes: 0 additions & 4 deletions layouts/partials/scripts.html
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,6 @@
{{- end }}
{{- end }}

<!-- Analytics -->
{{- if and (not .Site.IsServer) .Site.GoogleAnalytics -}}
{{ template "_internal/google_analytics_async.html" . }}
{{- end -}}

{{- with .Site.Params.baiduAnalytics -}}
<script id="baidu_analytics">
Expand Down

0 comments on commit f09b85c

Please sign in to comment.