Skip to content

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

Open
@lsolesen

Description

@lsolesen

What happened?

  • Minimal Mistakes version: 4.26.1
  • Ruby gem or remote theme version:
  • Jekyll version:
  • Git repository URL:
  • Hosted on GitHub Pages (if yes provide URL to site):
  • Operating system:

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions