#4334·grav

[Plugin Submission] Google Tag Manager

Author: sbinfo67Created Sep 27, 2026Updated Sep 27, 2026

Hello,

Please add this plugin to the Grav plugin directory (GPM). There is no Google Tag Manager plugin in GPM yet (the existing tag-manager plugin manages page tags and is unrelated).

What it does: it inserts a Google Tag Manager container in every HTML page, without any change to the theme.

  • Writes Google's snippet into the rendered output (onOutputGenerated): the script at the top of <head>, right after <meta charset>, and the <noscript> iframe right after the opening <body> tag, as Google recommends.
  • Trims, upper-cases and checks the container ID (GTM-XXXXXXX). An empty ID inserts nothing and logs nothing; an invalid one inserts nothing and is logged once.
  • Only changes HTML responses: sitemaps, feeds and JSON output are left untouched, and so are the admin and the API.
  • A page can opt out (google-tag-manager: false) or use another container in its frontmatter.
  • Ships disabled, with an empty ID. Single PHP file, no Composer dependency.

Origin: this is a maintained fork of jaymurphy1997/grav-plugin-gtm-plugin, which was never submitted to GPM. Its author agreed to this submission in jaymurphy1997/grav-plugin-gtm-plugin#1 ("Please feel free to publish your version") and is credited in the README and the license.

Testing: tested on Grav 1.7.53.4, 2.0.26, 2.1.10 and 2.2.1 (PHP 8.3), with Admin2 2.1.24: placement on regular and 404 pages, per-page override, empty and invalid IDs, XML and JSON sitemaps untouched, admin and API untouched, no errors in grav.log. The configuration page renders in English and French and saves correctly in Admin2.

Note: the README is in English; the settings screen is available in English and French.

Thank you!