From 963dc43f0ff1de6ad97ab0fa69058fc299899b89 Mon Sep 17 00:00:00 2001 From: Viktar Patotski Date: Wed, 10 Feb 2021 20:34:44 +0100 Subject: [PATCH] Add abbility to use Google Tag Manager for analytics (#514) * Add ability to embed custom code to * add myself to CONTRIBUTORS.md * implement dedicated template for Google Tag Manager * move google tag manager to bottom of the body tag --- CONTRIBUTORS.md | 1 + exampleSite/config.toml | 4 ++++ layouts/_default/baseof.html | 4 ++++ layouts/partials/analytics/googletagmanager.html | 9 +++++++++ 4 files changed, 18 insertions(+) create mode 100644 layouts/partials/analytics/googletagmanager.html diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 9a53e14..8c9faa5 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -94,3 +94,4 @@ - [Alex Miranda](https://ammiranda.com) - [Alphonse Mariya](https://github.com/alfunx) - [Ziwei Pan](https://github.com/PanZiwei/) +- [Viktar Patotski](https://github.com/xp-vit) diff --git a/exampleSite/config.toml b/exampleSite/config.toml index fb1c55f..7b05b4e 100644 --- a/exampleSite/config.toml +++ b/exampleSite/config.toml @@ -87,6 +87,10 @@ disqusShortname = "yourdiscussshortname" # For cloud-hosting, use provided URL, e.g. example.matomo.cloud serverURL = "analytics.example.com" +# If you want to use Google Tag Manager(https://analytics.google.com/) for analytics, add this section +[params.googleTagManager] + id = "gid" + # If you want to implement a Content-Security-Policy, add this section [params.csp] childsrc = ["'self'"] diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 9bb1a56..bf31a81 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -147,6 +147,10 @@ {{ if and .Site.Params.matomo .Site.Params.matomo.serverURL }} {{- partial "analytics/matomo" . -}} {{ end }} + + {{ if and .Site.Params.googleTagManager .Site.Params.googleTagManager.id }} + {{- partial "analytics/googletagmanager" . -}} + {{ end }} diff --git a/layouts/partials/analytics/googletagmanager.html b/layouts/partials/analytics/googletagmanager.html new file mode 100644 index 0000000..2d2581d --- /dev/null +++ b/layouts/partials/analytics/googletagmanager.html @@ -0,0 +1,9 @@ + + +