mmistakes / minimal-mistakes

:triangular_ruler: Jekyll theme for building a personal site, blog, project documentation, or portfolio.
https://mmistakes.github.io/minimal-mistakes/
MIT License
12.05k stars 24.98k forks source link

Provide a way to add Google Tag Manager without hacking default.html #4855

Open lsolesen opened 1 month ago

lsolesen commented 1 month ago

What happened?

Expected behavior

Enable a way to include Google Tag Manager without having to hack default.html.

Right now you need to:

---
---

<!doctype html>
{% include copyright.html %}
<html lang="{{ site.locale | slice: 0,2 | default: "en" }}" class="no-js">
  <head>
{% if jekyll.environment == 'production' %}
{% comment %}
<script async src="https://www.googleoptimize.com/optimize.js?id=OPT-T4ZK4CX"></script>
{% endcomment %}
<!-- Google Tag Manager -->
<script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
  new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
  j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
  'https://www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
  })(window,document,'script','dataLayer','GTM-XXX');</script>
  <!-- End Google Tag Manager -->
{% endif %}
    {% include head.html %}
    {% include head/custom.html %}
  </head>

  <body class="layout--{{ page.layout | default: layout.layout }}{% if page.classes or layout.classes %}{{ page.classes | default: layout.classes | join: ' ' | prepend: ' ' }}{% endif %}">
{% if jekyll.environment == 'production' %}
<!-- Google Tag Manager (noscript) -->
<noscript><iframe src="https://www.googletagmanager.com/ns.html?id=GTM-XXXX"
  height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
<!-- End Google Tag Manager (noscript) -->
{% endif %}
    {% include_cached skip-links.html %}
    {% include_cached masthead.html %}

    <div class="initial-content">
      {{ content }}
      {% include after-content.html %}
    </div>

    {% if site.search == true %}
      <div class="search-content">
        {% include_cached search/search_form.html %}
      </div>
    {% endif %}

    <div id="footer" class="page__footer">
      <footer>
        {% include footer/custom.html %}
        {% include_cached footer.html %}
      </footer>
    </div>

    {% include scripts.html %}

  </body>
</html>

Would be nice to be able to add Tag Manager without having to modify default.html, if possible.

Steps to reproduce the behavior

See above example.

Other

See above example.

iBug commented 1 month ago

There's {% include head/custom.html %} so you can always override that file instead of default.html.