Adding GTM using Cupper Theme


I am an amateur developer. I really know HTML and CSS and a little JS. I am trying to add a Google Tag manager container to my website, but can’t figure out how to add it without adding it to every single page manually.

Do I just need to add it to the baseof.html file?. Or is there more I should be doing?

I am using the Cupper Theme.

I have implemented this on a heavily modified inkblotty theme.

Create two partial files called…


{{ if and ($.Site.Params.google_tag_manager) (not (.Site.IsServer)) }}
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="{{ $.Site.Params.google_tag_manager }}"
height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{{ end }}


{{ if and ($.Site.Params.google_tag_manager) (not (.Site.IsServer)) }}
  <!-- Google Tag Manager -->
  <!-- create dataLayer -->
   <!-- OPTIONAL dataLayer -->
    var dataLayer = window.dataLayer = window.dataLayer || [];
      page:'{{ .Title }}',
      categories:'only examples about your dataLayer'
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  })(window,document,'script','dataLayer','{{ $.Site.Params.google_tag_manager }}');</script>
  <!-- End Google Tag Manager -->
{{ end }}

Add the following line to head.html below charset

{{ partial "google_tag_manager.html" . }}

on your config.toml add your GTM ID like the following to your yaml/toml file under [Params]

google_tag_manager = "GTM-XXXXXXX"

Thank you! I will try this and see if it works.