Analytics and Tracking

Custom HTML Tag

A Google Tag Manager tag that inserts any HTML or JavaScript you paste into it, for scripts that have no ready-made template.

Quick facts: Custom HTML Tag

Category
Analytics and Tracking
Level
Advanced
Affects
Site speed, consent compliance, data security, tracking accuracy
Where to see it
Google Tag Manager tag list, Tag Manager preview mode, browser developer tools, PageSpeed Insights
In this article4
  1. How a custom HTML tag works
  2. Why it matters
  3. Common mistakes
  4. How to act on it

A custom HTML tag is a Google Tag Manager tag type that places whatever HTML or JavaScript you paste into it onto the page, so you can run code for which Tag Manager has no ready-made template. It is the most flexible tag in Tag Manager and, for exactly that reason, the one most likely to cause problems.

How a custom HTML tag works

Most tags in Tag Manager are built from templates. You choose “Google Analytics: GA4 Event” or a vendor’s template, fill in a few fields, and Tag Manager writes the code for you. A custom HTML tag skips that step. The code you paste, usually a script supplied by a software vendor, is inserted into the page whenever the tag’s trigger fires.

Because it runs directly in the page, that code can do anything the site’s own code can do: read cookies, read form fields, change content and load further scripts from other domains. Tag Manager does not check what it does. Beneath the code box sit a few options, such as support for older scripts that use document.write, and the usual firing triggers, blocking triggers, consent settings and tag sequencing apply as they would to any tag.

Why it matters

Custom HTML tags are how many businesses add a review widget, a live chat script, call tracking number swaps or a smaller ad network’s pixel. That is useful, but each one is third-party code running on your site with full access, and it is easy to forget it is there. For a UK business there are three specific risks:

  • Consent. Google’s own tags have built-in consent checks. A custom HTML tag has none. Unless you require additional consent in its consent settings, or gate it with a trigger tied to your consent platform, it may set cookies before the visitor agrees, which breaches PECR.
  • Personal data. A pasted script can read form fields, including names and email addresses, and send them elsewhere. Under UK GDPR you are responsible for that transfer whether or not you knew it was happening.
  • Speed and stability. Each script adds weight and network requests, which can harm Core Web Vitals, and an error in one script can stop other code on the page from running.

Where a vendor offers a custom template in the Community Template Gallery, I would use it instead. A template declares up front which cookies it reads and which domains it contacts, and Tag Manager holds it to that list.

Common mistakes

  • Pasting Google code into a custom HTML tag. Adding the GA4 or Google Ads snippet this way, rather than using Google’s own tag types, loses the built-in consent handling and often double counts.
  • Firing on all pages when one is enough. A chat script needed on the contact page does not have to load on every blog post.
  • Leaving old tags live. A pixel from an ad network you tried years ago still runs, still sets cookies and still slows the site.
  • No owner or note. Months later nobody knows what “Custom HTML 4” does or whether it is safe to remove.
  • Wide publishing rights. Anyone who can publish the container can put any code on your site. Keep publish access to the people who need it.

How to act on it

Open your container, filter the tag list by type and review every custom HTML tag. For each one, note what it does, who asked for it and whether it is still needed. Pause anything nobody can explain, and remove it once you are sure nothing depends on it.

For the tags that stay, check whether a template now exists and switch if it does. Set consent requirements on the rest, limit their triggers to the pages that need them, and test in preview mode with cookies declined first, to confirm nothing fires that should not. Use consent mode for Google’s tags and your consent platform’s signals for everything else. If your container has grown untidy, a review like this is part of the tracking setup I carry out for performance marketing work.

Do and do not

Do

  • Use a vendor template from the Community Template Gallery when one exists
  • Require additional consent on every custom HTML tag that is not strictly necessary
  • Record the owner and purpose of each tag in its name or notes

Do not

  • Paste GA4 or Google Ads code into a custom HTML tag
  • Fire scripts on every page when only one page needs them
  • Give container publish rights to anyone who does not need them

Questions people ask about this

Is a custom HTML tag bad for SEO?

Not directly, because search engines do not rank pages on which tags they load. Indirectly, heavy or badly written scripts slow pages down, which affects page experience. A script that rewrites page content after load can also change what Google renders, so keep content changes out of Tag Manager.

Can I stop people adding custom HTML tags to my container?

Yes. Tag Manager supports an allowlist and blocklist set in the site's code, which can block custom HTML tags entirely or limit the tag types a container may run. A developer has to add it, because it lives on the page rather than in the Tag Manager interface. Restricting who can publish the container is the other half of the control.

Do I need consent before a custom HTML tag fires?

If the code stores or reads information on the visitor's device for anything that is not strictly necessary, such as analytics or advertising, PECR normally requires consent first. A custom HTML tag has no built-in consent check, so you have to add one through its consent settings or its triggers. A chat widget that only loads when the visitor asks for it may be treated differently from a tracking pixel, so judge each script on what it actually does.

Related terms

Found this useful?

Share it, or ask an AI to summarise it

Back to the glossary

Knowing the term is the easy part

Applying it to your own site and budget is the work. Book a call and I will tell you what actually applies to you.