Lesson 10 of 11
Custom HTML Tag
① Connect your GTM container
Paste your container ID to load it into this page. It only ever runs here.
Advanced: use a specific environment
Sometimes a vendor gives you a snippet and no GTM template. Custom HTML is the escape hatch: a tag whose body is raw HTML or JavaScript that GTM injects into the page. It's powerful, and the reason it's a last resort, because anything you can write here can also break the page or leak data.
Custom HTML runs in GTM's sandbox with real rules. document.write is ignored after the page has loaded. Scripts you inject aren't deduplicated for you, so add an id guard (a flag on window) so a re-fired tag doesn't inject the same pixel twice. And prefer a native tag or a Community Template whenever one exists.
Build a Custom HTML tag that injects a simple tracking pixel into the slot below.
Goal
Inject a tracking pixel with a Custom HTML tag, with an id guard so it fires once.
Build it in GTM
Create the Custom HTML tag
- Go to Tags → New and choose Custom HTML.
- Paste your pixel with an id guard, for example:
<script>if(!window.__htPixel){window.__htPixel=1;var i=new Image();i.src='https://example.com/p.gif';}</script> - Leave Support document.write unchecked, it won't work after load.
Trigger it and name it
Fire it on the trigger that fits (often All Pages, or a specific event), name it clearly likeCustom HTML - Vendor Pixeland Save.Prefer a template where one exists
Before you ship Custom HTML, check the Community Template Gallery. A vetted template is sandboxed, reviewed and easier to maintain than raw script.
Debug in Tag Assistant
Copy this lesson's live URL and paste it into GTM Preview, that is the page Tag Assistant connects to. It has the clickable elements, so this page stays clean for reading.
- In your GTM, click Preview.
- Paste the live URL above and click Connect.
- Interact with the live page and watch your tag fire in Tag Assistant.
What you should expect to see
Verify your container
Built it? Export your container, Admin → Export Container, choose your workspace, then drop the JSON here to check it against this lesson.
Drop your container .json here
or browse · checked in your browser, nothing is uploaded