This project is not covered by Drupal’s security advisory policy.

GTM Snippet Loader lets site builders add trusted Google Tag Manager or tag manager loader snippets to a Drupal site without editing theme files. It provides a simple configuration screen for adding head and body snippets, with options to exclude admin pages and specific paths.

This module is useful for Drupal site owners, marketers, and developers who need to install a GTM-style tracking snippet while keeping the configuration managed inside Drupal.

Features

  • Add a trusted snippet to the document head.
  • Add optional body-open markup for noscript or fallback tag manager markup.
  • Exclude Drupal administration routes.
  • Exclude specific paths using configurable path patterns.
  • Use automatic response injection or theme-controlled placement.
  • Manage snippets through Drupal configuration.
  • Supports configuration export and deployment workflows.

Use this module when you need to add a Google Tag Manager snippet, server-side GTM loader, or similar trusted tag manager script to a Drupal site and want that snippet managed through Drupal configuration instead of hardcoded theme templates.

Post-Installation

After installing the module, go to:

/admin/config/system/gtm-snippet-loader

From the configuration page, add the trusted head snippet and, if needed, the body-open snippet. You can also configure whether the snippet should be excluded from administration routes and define path patterns where the snippet should not appear.

For most sites, the automatic injection mode is the simplest option. For stricter control over placement, themes can render the provided variables in their page templates.

Because this module allows trusted users to inject JavaScript and HTML into site pages, access to the configuration permission should only be granted to fully trusted administrators.

Additional Requirements

This module has no dependencies beyond Drupal core.

A Google Tag Manager container, server-side GTM endpoint, or other trusted tag manager snippet is required if you want to load an external tag manager.

  • Config Split - useful for enabling or changing snippets per environment.
  • Config Ignore - useful when snippet configuration should vary outside normal deployment workflows.

Similar projects

  • Google Tag - provides broader Google tag and container management functionality.
  • GoogleTagManager - provides Google Tag Manager integration for Drupal.

GTM Snippet Loader is intentionally smaller and more direct. It focuses on loading trusted snippets with configurable exclusions, rather than managing a full Google tag integration workflow.

Supporting this Module

Issues, feature requests, and patches are welcome in the Drupal.org issue queue.

Community Documentation

Community documentation, walkthroughs, and examples can be added here as they become available.

Project information

Releases