Skip to content

Commit 963dc43

Browse files
authored
Add abbility to use Google Tag Manager for analytics (luizdepra#514)
* Add ability to embed custom code to <head> * add myself to CONTRIBUTORS.md * implement dedicated template for Google Tag Manager * move google tag manager to bottom of the body tag
1 parent c4afd5f commit 963dc43

File tree

4 files changed

+18
-0
lines changed

4 files changed

+18
-0
lines changed

CONTRIBUTORS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,3 +94,4 @@
9494
- [Alex Miranda](https://ammiranda.com)
9595
- [Alphonse Mariya](https://github.com/alfunx)
9696
- [Ziwei Pan](https://github.com/PanZiwei/)
97+
- [Viktar Patotski](https://github.com/xp-vit)

exampleSite/config.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ disqusShortname = "yourdiscussshortname"
8787
# For cloud-hosting, use provided URL, e.g. example.matomo.cloud
8888
serverURL = "analytics.example.com"
8989

90+
# If you want to use Google Tag Manager(https://analytics.google.com/) for analytics, add this section
91+
[params.googleTagManager]
92+
id = "gid"
93+
9094
# If you want to implement a Content-Security-Policy, add this section
9195
[params.csp]
9296
childsrc = ["'self'"]

layouts/_default/baseof.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,10 @@
147147
{{ if and .Site.Params.matomo .Site.Params.matomo.serverURL }}
148148
{{- partial "analytics/matomo" . -}}
149149
{{ end }}
150+
151+
{{ if and .Site.Params.googleTagManager .Site.Params.googleTagManager.id }}
152+
{{- partial "analytics/googletagmanager" . -}}
153+
{{ end }}
150154
</body>
151155

152156
</html>
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<!-- Global site tag (gtag.js) - Google Analytics -->
2+
<script async src="https://www.googletagmanager.com/gtag/js?id={{ $.Site.Params.googleTagManager.id }}"></script>
3+
<script>
4+
window.dataLayer = window.dataLayer || [];
5+
function gtag(){dataLayer.push(arguments);}
6+
gtag('js', new Date());
7+
8+
gtag('config', '{{ $.Site.Params.googleTagManager.id }}');
9+
</script>

0 commit comments

Comments
 (0)