On this page
What this issue is
A Custom HTML tag in Google Tag Manager (GTM) lets you paste your own HTML and JavaScript, such as a third-party pixel, a chat widget or a small tracking script. If that code has a mistake, the browser stops running it and writes an error to the console (the developer log built into the browser).
Why it costs you leads or sales
If the script is a conversion pixel, the ad platform never hears about the lead or sale. Reports undercount, and bidding that learns from conversions gets less data. If the script is a widget, such as chat or a booking button, visitors lose that way to contact you.
The damage is easy to miss because nothing looks broken to visitors and GTM shows green. It often starts after a site change, a library update or an edit to the tag, and can run for weeks.
- Visitor submits formTrigger conditions match
- GTM fires Custom HTML tagPreview shows Tag Fired
- Script runsUncaught error in console
- Conversion hit sentNever leaves the browser
- Ad platform reportConversion missing
The tag fires, but the script fails inside it, so nothing reaches the ad platform.
GTM reports the tag as fired, but the script inside errors out and no hit is sent.
How to check if your site has it
Open the page and the console
Load the page where the tag should run. Press F12 (or Cmd+Option+J on Mac in Chrome) and open the Console tab.
Trigger the event
Reload, then do the action that fires the tag, such as submitting the form. Look for red messages such as Uncaught SyntaxError, ReferenceError or TypeError.
Open the stack trace
Click the error line. Scripts injected by GTM usually show as gtm.js or as VM and a number. Note the message and line number.
Match it to a tag in GTM PreviewGoogle Tag Manager
Start Preview in GTM, load the page and check which Custom HTML tags fired at that moment. Compare their timing with when the error appears. Disabling one tag at a time in a workspace is a reliable way to find the guilty one.
Check the network tab
Open Network and filter for the platform (for example facebook.com/tr or google-analytics.com). If the expected request never appears, the script is not running.
| Error message | Usual cause | Typical fix |
|---|---|---|
| Uncaught SyntaxError: Unexpected token | Typo, missing bracket or smart quotes | Fix the syntax; retype quotes as straight quotes |
| Uncaught ReferenceError: fbq is not defined | Library not loaded yet or blocked | Load the base code first (tag sequencing) or check consent |
| Uncaught TypeError: Cannot read properties of undefined | Variable or object is empty | Check the variable value and add a guard |
| Unexpected token '<' | HTML pasted as JavaScript, or a script URL returned a page | Put JavaScript inside <script> tags; check the URL |
| Blocked by CSP | Content Security Policy forbids the script | Allow the domain in your CSP header |
How to fix it
Copy the code out and read itGoogle Tag Manager
Open the tag in GTM and paste its code into a code editor. Look for missing brackets, smart quotes and leftover placeholders such as YOUR_ID.
Fix the exact line in the error
Use the message and line number from the console. Correct the syntax or the name of the function or variable.
Guard against missing values
Wrap code that depends on other objects in a check, so it stops quietly instead of throwing an error.
Fix the order of loadingGoogle Tag Manager
If the error says something is not defined, make sure the setup tag fires first. Use Advanced Settings > Tag Sequencing > Fire a tag before, or move the trigger to a later event such as Window Loaded.
Prefer a built-in template where one existsGoogle Tag Manager
For GA4, Google Ads and others, use the official tag types rather than pasted code. They handle errors and consent for you.
Test, then publishGoogle Tag Manager
Check in Preview mode with the console open, then click Submit and Publish with a clear version name.
<script>
(function () {
try {
if (typeof window.fbq !== 'function') { return; } // base pixel not loaded
var value = parseFloat({{DLV - value}});
if (isNaN(value)) { value = 0; }
window.fbq('track', 'Lead', { value: value, currency: 'USD' });
} catch (e) {
console.warn('Lead tag error', e);
}
})();
</script>Debug in Preview
Click Preview, open your site, and check the Tags Fired list with the browser console open next to it.
Edit the tag
Go to Tags, open the Custom HTML tag, correct the code and save.
Check for plugin conflicts
If the error mentions jQuery or a plugin script, deactivate optimisation or caching plugins that combine or delay JavaScript, then retest.
Exclude GTM from delay settings
In your performance plugin, exclude the GTM script and the libraries your tag needs from delay or defer options.
Check order of scripts
Make sure the pixel or library your tag uses is not blocked by Customer privacy settings or an app, and that you are not using theme objects that only exist on some pages.
Use the right page
On checkout and order status pages, scripts in GTM may be limited. Use Shopify's customer events (pixels) there instead.
Check the GTM install
Confirm the GTM snippet is in Project settings > Custom code and the site was published after the change.
Check your Content Security Policy
If the console says a script was blocked by CSP, add the needed domains to the script-src directive in your response headers.
How to confirm it's fixed
- Reload the page with the console open: no red error from the tag
- Trigger the event in GTM Preview and see the tag fire once
- Network tab shows the expected request to the ad or analytics platform
- The event appears in the platform's own test view (for example GA4 DebugView or Meta Test Events)
- The version is published and the live site (not only Preview) shows the same result
How to prevent it happening again
- Use built-in tag templates instead of pasted code where possible
- Add guards (typeof checks and try/catch) to every Custom HTML script
- Test with the console open before every publish, not only in Preview
- Write a clear version name and note for every GTM publish
- Retest after theme changes, plugin updates and consent banner changes
- Keep a list of which Custom HTML tags depend on which libraries
Day 1
Someone edits a Custom HTML tag and introduces a typo. Preview shows the tag as fired.
Day 2
The version is published. The console shows a SyntaxError, but nobody is looking.
Day 10
Ad reports show fewer conversions than the CRM.
Day 12
The error is found in the console and fixed.
How FunnelGuard handles this
FunnelGuard detects this today. A robot visitor runs your real customer journeys on a schedule and records the browser console errors it sees along the way. A JavaScript error that appears on a step of your funnel is flagged, so you do not rely on someone opening the console by chance.
FunnelGuard also checks the tracking hits sent to platforms such as GA4, Google Ads and Meta, so a missing hit alongside a console error points to the broken script. A failure is re-checked from a second region before one alert goes out, with a screenshot and a likely cause. The console error is a signal to investigate, so you still open the tag in GTM to fix it. The Free plan covers 1 site and 2 journeys with daily checks and needs no card, and paid plans have a 3-day free trial.
Questions people ask
Why is my GTM Custom HTML tag firing but not working?
GTM only confirms it injected your code into the page. If the code then throws a JavaScript error, nothing happens. Open the browser console, find the red error and fix the line it points to.
How do I see JavaScript errors from Google Tag Manager?
Open the page, press F12 and go to the Console tab, then trigger the event that fires your tag. Errors from injected scripts often show as gtm.js or VM lines. GTM Preview mode helps you match the error to a specific tag.
Can one broken Custom HTML tag stop my other GTM tags?
Usually a JavaScript error only stops that one script, and other tags still run. It can block others if they depend on it through tag sequencing or on something it was meant to set up. Wrapping your code in try/catch limits the damage.
What does 'fbq is not defined' mean in Google Tag Manager?
It means your code called the Meta Pixel function before the base pixel code had loaded, or the base code was blocked. Make the base pixel tag fire first with tag sequencing, and check that consent settings are not blocking it.
Should I use Custom HTML tags or built-in GTM tag templates?
Use built-in templates for GA4, Google Ads and other supported platforms whenever you can. They are maintained, handle consent settings and are less likely to break. Keep Custom HTML for scripts that have no template.
Why does my tag work in Preview mode but not on the live site?
Common reasons are that the workspace was never published, a cache or performance plugin delays or removes the script, consent settings block it for real visitors, or a CSP header rejects it. Check the console on the live site, not only in Preview.
How can I catch GTM script errors automatically?
A scheduled synthetic check can run your key journeys and record console errors and missing tracking hits. FunnelGuard does this and sends an alert with a screenshot and a likely cause after a second-region re-check.
Related issues
- TRK-112Tag sequencing broken (setup tag fails, main tag skipped)Fix guide
- TRK-113Variables returning undefined (dataLayer key renamed)Fix guide
- TRK-103Workspace changes never published (tag in preview only)Fix guide
- TRK-116Tag firing in preview but blocked by consent settings in liveFix guide
- TRK-102GTM container published version changed unexpectedlyFix guide
- TRK-105GTM snippet placed in footer, firing lateFix guide