GTM Injector

Injects a GTM container with a dynamic ID, visual feedback, and advanced debugging for testing purposes.

作者
Johncarter2021
日安装量
0
总安装量
1
评分
0 0 0
版本
1.0.0
创建于
2025-07-08
更新于
2025-07-08
大小
6.4 KB
许可证
MIT
适用于

GTM Injector

A powerful and user-friendly tool for QA testers, marketers, and developers to inject a Google Tag Manager (GTM) container onto any of the specified websites for testing and debugging purposes.

This script follows Google's best practices, including support for Consent Mode v2, and provides advanced features to make your workflow easier.

✨ Key Features

  • Reliable GTM Injection: Injects the GTM container script into the <head> and the <noscript> tag into the <body> correctly.
  • Dynamic GTM ID: Easily change the GTM container ID without editing the code. The script remembers your choice.
  • Visual Feedback: A clean indicator badge appears in the bottom-right corner, confirming that the script is active and showing which GTM container is in use.
  • One-Click Debug Mode: Simply click the indicator badge to reload the page in GTM's Preview/Debug mode.
  • CSP Error Detection: If a site's Content Security Policy (CSP) blocks GTM, the indicator will turn red and a clear error will be logged to the console, helping you diagnose issues instantly.
  • Safe and Efficient: The script only runs on the pre-defined list of websites and checks if GTM is already present to prevent conflicts.

🚀 How to Use

  1. Install the script in Tampermonkey or another user script manager.
  2. Set Your GTM ID (Optional):
    • The script comes with a default GTM ID (GTM-WVX6GFMQ).
    • To change it, click the Tampermonkey extension icon in your browser, and you will see a menu command named "Set UTS GTM ID".
    • Click it, enter your GTM container ID, and the page will reload with the new container.
  3. Verify Injection:
    • Navigate to one of the matched websites (e.g., theguardian.com).
    • Look for the blue "UTS GTM: GTM-XXXXXXX" badge in the bottom-right corner.
  4. Enter Debug Mode:
    • Click the blue badge to instantly reload the page and activate GTM's Preview mode.

⚠️ Troubleshooting

  • If the badge is red, it means the GTM script was blocked by the website's Content Security Policy. Open your browser's Developer Console (F12) for more details.
  • If the script doesn't seem to run, ensure you are on one of the websites listed in the @match rules.

Changelog

  • 1.0.0 (Initial Release):
    • Core GTM injection functionality.
    • Dynamic ID configuration via menu command.
    • Visual indicator with one-click debug mode.
    • CSP error detection.

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址