Analytics and Tracking

Custom Template

Also called Sandboxed template, gallery template

A reusable, sandboxed tag definition with named fields, built once and used by people who never touch the code.

Quick facts: Custom Template

Category
Analytics and Tracking
Also called
Sandboxed template, gallery template
Level
Advanced
Affects
Tag safety, delegation to non-technical staff, consistency
Where to see it
Google Tag Manager (Templates, Community Template Gallery)
In this article4
  1. How a custom template works
  2. Why custom templates matter
  3. Where custom templates go wrong
  4. How to act on it

How a custom template works

A template is a definition rather than a tag. You describe the fields somebody should fill in — an ID, a switch, a destination — and write the logic in Tag Manager’s own sandboxed language instead of ordinary JavaScript. Once saved, the template appears in the tag list beside the vendor tags, and colleagues create real tags from it by filling in those fields.

The sandbox is the part that matters. Template code cannot reach the page freely. It asks for specific permissions — to read a named data layer variable, to set a particular cookie, to send a request to a stated domain — and that permission list is shown to whoever installs it. Anything not granted simply fails rather than quietly succeeding.

Templates can stay private to your container, or come from the Community Template Gallery, where vendors and independent developers publish their own.

Why custom templates matter

They turn a risky one-off snippet into something you can hand to a non-technical colleague. The person creating the tag sees labelled fields, not code, so the usual failure of a pasted snippet — a wrong ID sitting in a line nobody read — becomes very hard to reproduce.

They also make permissions legible. With raw code you have to read it to know what it touches. With a template the permission list states it plainly, which is the difference between guessing and answering when a client asks what a third-party script on their site is allowed to do.

Where custom templates go wrong

The commonest mistake is installing a gallery template without reading its permissions. A gallery template is still somebody else’s code. The sandbox constrains it, but a template granted permission to send data to an unfamiliar domain is doing exactly that, with your approval on record.

The second is over-engineering. Writing and maintaining a template for a tag that will exist on one site, once, costs more than it saves. Templates repay effort through reuse or through delegation, and a one-off case offers neither.

How to act on it

Prefer the vendor’s official template, then a gallery template you have actually read, then your own, and treat a Custom HTML tag as the last resort. When you build one, expose only the fields a user genuinely needs and set sensible defaults for everything else, because every extra field is another chance to get it wrong.

Check the permissions on templates already sitting in your container, particularly any inherited from a previous agency. If that list is long or unfamiliar, folding it into a wider analytics and tracking review is more productive than opening each template one at a time.

Do and do not

Do

  • Read a template's permissions before installing it
  • Expose only the fields a user must change
  • Reuse one template across your containers

Do not

  • Build a template for a one-off tag
  • Grant permission to contact unfamiliar domains
  • Inherit templates without reviewing them

Questions people ask about this

How is a custom template different from a Custom HTML tag?

A Custom HTML tag runs whatever code you paste, with full access to the page. A template runs sandboxed code that must request each permission it needs, and it gives the person creating the tag labelled fields instead of code. The template takes longer to build and is far safer to hand to somebody else.

Are gallery templates safe to install?

They are safer than pasted code, because the sandbox limits what any template can reach and every permission is listed before installation. Safety is not automatic, though. Read that permission list and check which domains the template may contact, in the same way you would check what a plugin on your website is asking for.

Do I need to be a developer to build one?

In practice, yes. Templates are written in Tag Manager's own sandboxed language, and although it resembles JavaScript, the permission model and the available functions are specific to it. Most businesses never write one. They use vendor templates, install a reviewed gallery template, or have a developer build a single template the marketing team then reuses.

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.