Skip to content

Schema markup in Google Tag Manager: which crawlers can read it

Schema markup added with Google Tag Manager exists only after JavaScript runs. How GTM injects JSON-LD, what consent does to it, and how to move it server-side.

By Crawlito · 8 min read

In short

  • Google documents Google Tag Manager as a supported way to add JSON-LD, because Google Search processes structured data that is in the DOM when it renders the page.
  • JSON-LD from a GTM Custom HTML tag is never in the raw HTML, so crawlers that do not run JavaScript, such as the OpenAI, Anthropic and Perplexity crawlers in Vercel's December 2024 analysis, never see it.
  • A schema tag set to 'Require additional consent for tag to fire' only fires when all listed consent types are granted, and Google's renderer clears cookies and storage across page loads.
  • Google says JavaScript-generated Product markup can make Shopping crawls less frequent and less reliable, and recommends Product structured data in the initial HTML.
  • An exported GTM container is a JSON file, so you can search it for ld+json to list every tag that emits schema before moving each block into server templates.
On this page

Schema markup added through Google Tag Manager is read by Google, and by little else. A GTM Custom HTML tag inserts the JSON-LD with JavaScript after the page starts loading, so it exists only in the rendered page. Googlebot renders pages and can use it; crawlers that read only the raw HTML, which at the time of writing includes the major AI crawlers that have been measured, never receive it. GTM is a reasonable stopgap when you cannot edit templates, but the markup belongs in the server response.

This post covers what is specific to GTM: how the tag injects the block, which triggers and variables matter, what consent settings do to it, how to find every schema tag in a container, and how to migrate each one. For why raw HTML matters in general, see raw vs rendered HTML; for syntax problems, see common JSON-LD errors.

How a GTM Custom HTML tag adds JSON-LD

Google's guide to generating structured data with JavaScript describes the GTM method directly: install GTM, add a Custom HTML tag to the container, paste a structured data block into it, then publish the container and test. Google supports this because "Google Search can understand and process structured data that's available in the DOM when it renders the page."

A typical tag looks like this:

html
<script type="application/ld+json">
{
  "@context": "https://schema.org",
  "@type": "Article",
  "headline": "{{Article Headline}}",
  "author": { "@type": "Person", "name": "{{Article Author}}" },
  "datePublished": "{{Article Published}}"
}
</script>

The {{...}} parts are GTM variables. Tag Manager's Custom HTML help page says to insert a variable by wrapping its name in double braces, and Google's structured data guide recommends variables rather than typed-in values, because "Duplicating the information in GTM increases the risk of having a mismatch between page content and the structured data." Its example uses a Custom JavaScript variable that returns document.title, placed inside quotes in the JSON-LD.

Two GTM details are easy to miss:

  • Tag Manager rewrites the code. The help page says GTM minifies Custom HTML code, which can change single quotes to double quotes. Test the published output, not the code you typed.
  • Escaping is not documented. Neither page says whether Tag Manager escapes a variable's value inside a JSON-LD block. If a headline can contain a double quote or a line break, test such a page in Preview mode and confirm the block still parses.

A pattern that does not depend on that builds the object in JavaScript and serializes it, so every value is escaped. The help page's own example uses a variable as a bare JavaScript value (var foo = {{bar}};), which is how the variables are used here:

html
<script>
(function () {
  var data = {
    "@context": "https://schema.org",
    "@type": "Article",
    "headline": {{Article Headline}},
    "author": { "@type": "Person", "name": {{Article Author}} }
  };
  var s = document.createElement("script");
  s.type = "application/ld+json";
  s.text = JSON.stringify(data).replace(/</g, "\\u003c");
  document.head.appendChild(s);
})();
</script>

Here the variables are used as JavaScript values rather than inside quotes, and JSON.stringify handles the escaping. It is still JavaScript, so it still exists only after rendering.

Which trigger and variables the schema tag depends on

The trigger decides when the block appears, and the variables decide whether it has anything in it. Tag Manager's trigger documentation lists the page view triggers in the order they fire:

TriggerWhen it fires, per GoogleEffect on a schema tag
Consent InitializationBefore all other triggersMeant for consent tags, not schema
InitializationBefore all others except Consent InitializationFires early, but DOM variables may be empty
Page View"immediately when the web browser begins to load a page"Same risk: page elements may not exist yet
DOM Ready"after the browser has finished constructing the full page in HTML"Usual choice when variables read page elements
Window LoadedAfter the page and embedded resources, such as images and scripts, have loadedLatest; waits for every image and script

If a variable reads an element (a DOM Element variable, or Custom JavaScript that queries the page) and the tag fires before that element exists, the markup ships with empty strings. If the element is itself rendered by a client-side framework, even DOM Ready can be too early. Use GTM's Preview mode to check the variable values at the moment the tag fires.

Google does not document how long its renderer waits for late tags, so a tag on Window Loaded, or one held back by a script-delay plugin, adds uncertainty. Delaying JavaScript execution covers that problem.

Consent settings can stop a schema tag from firing at all. Tag Manager's consent settings page gives every tag an Additional Consent Checks option under Advanced Settings > Consent Settings, with three values:

SettingMeaning, per Google
Not setThe default; no additional consent checks
No additional consent requiredThe tag does not need extra consent to fire
Require additional consent for tag to fireThe tag fires only if all selected consent types are "granted" when it is triggered

Schema markup sets no cookies and tracks no one, but schema tags often get swept into bulk edits of the whole container, ending up with something like analytics_storage required. Google's page does not say whether such a tag fires later if consent is granted after the trigger has passed.

For crawlers, the important fact is in Google's JavaScript troubleshooting guide: its renderer "does not retain state across page loads", and "HTTP Cookies are cleared across page loads", as are Local Storage and Session Storage. A stored consent choice never carries over, so Google's renderer arrives with no stored consent. Unless your consent defaults grant the required type, a schema tag that requires consent is unlikely to fire for Google. A crawler that does not run JavaScript never runs GTM in the first place.

To review it, go to Admin > Container Settings and, under Additional Settings, select Enable consent overview. The overview groups tags into "Consent Not Configured" (tags still on "Not set") and "Consent Configured" (tags set to either of the other two options), so open each schema tag in the second group and check which option it uses. The usual fix is to set schema tags to "No additional consent required". Consent platforms can also hold tags back with blocking triggers (trigger exceptions), so check the tag's triggering section as well.

Google's caveat for Product markup

Product markup is where GTM costs the most, because Google says so. Both the JavaScript structured data guide and the merchant listing documentation warn that dynamically generated Product markup "can make Shopping crawls less frequent and less reliable", which matters for fast-changing content like price and availability. The merchant listing page recommends "putting Product structured data in the initial HTML for best results", and asks sites that generate it with JavaScript to make sure the server can handle increased traffic from Google.

A GTM Product tag that scrapes the price from the page also inherits every timing problem above: if the price element renders late, the markup carries an empty or stale price. If you only move one block out of GTM, make it Product. The product schema guide lists the properties to carry over.

How to find every tag that emits schema in a container

Containers built over several years often have schema tags nobody remembers. Export the container and search it.

  1. In Tag Manager, click Admin, then Export Container in the Container section.
  2. Click Choose a version or workspace, select the live version, and click Download. Google's export help page says containers are exported as JSON.
  3. List every tag whose code mentions ld+json:
bash
python3 - GTM-XXXXXXX_v42.json <<'EOF'
import json, sys
data = json.load(open(sys.argv[1], encoding="utf-8"))

def walk(node, path=""):
    if isinstance(node, dict):
        if "tagId" in node and "ld+json" in json.dumps(node):
            print(node.get("tagId"), node.get("name"), node.get("type"))
            return
        for k, v in node.items():
            walk(v, f"{path}/{k}")
    elif isinstance(node, list):
        for v in node:
            walk(v, path)

walk(data)
EOF

Google does not document the file's field names, so if this prints nothing, fall back to grep -c "ld+json" on the file and search by hand. A tag that builds the script with createElement and JSON.stringify may not contain the string ld+json at all; search for @context and schema.org too.

For each tag, record its schema type, trigger, consent setting and the variables it reads. Then check one live page per template for duplicates: if a CMS plugin already outputs Organization or Product and GTM adds another, you have two versions of the same facts.

How to move each block into server templates

Migrate one tag at a time, so you never have zero or two copies of a type on a page.

  1. Find the source of each variable. A variable that reads document.title or an element on the page reads data your CMS already has. Use that field in the template instead of scraping it back from the page.
  2. Generate the JSON-LD on the server. Build an object and serialize it with your platform's encoder, such as wp_json_encode() in WordPress or JSON.stringify() in a Node template, then escape < as < so no value can close the script element. Where entities repeat across pages, give them a stable @id so each page can reference them instead of repeating them.
  3. Deploy the template change, then pause the GTM tag in the same release window. Pausing rather than deleting keeps a quick way back.
  4. Check the raw HTML with the curl and Python check in structured data for AI search. The block count should go up by one, and the Rich Results Test should show the type only once.
  5. Publish a new container version with a clear name, such as "Removed Product schema tag: now in theme". Tag Manager's Versions view records the change.

If you truly cannot edit templates, keep the GTM tag but set it to "No additional consent required", fire it on DOM Ready, and build the JSON with JSON.stringify. That gives Google its best chance of reading it; it does nothing for crawlers that read only the raw HTML, which do AI crawlers run JavaScript? explains.

Frequently asked questions

Does Google read schema markup added with Google Tag Manager?

Yes. Google's documentation describes the GTM method and says Google Search processes structured data that is in the DOM when it renders the page. It recommends testing with the URL input of the Rich Results Test.

Can ChatGPT, Claude or Perplexity read JSON-LD from GTM?

Their operators do not document JavaScript rendering, and Vercel's December 2024 analysis found that OpenAI's crawlers, ClaudeBot and PerplexityBot did not execute it. Assume they see only the raw HTML, where GTM markup does not exist.

In Tag Manager's own consent settings, only if the tag requires a consent type that is not granted when it triggers. A consent platform that adds blocking triggers can also stop it, so check both.

Why does the Rich Results Test pass but view-source shows no JSON-LD?

The Rich Results Test renders the page and runs GTM, while view-source shows the raw HTML before any script runs. Both results are correct; only the raw HTML reaches crawlers that do not render.

Is it a problem to keep schema in both GTM and the template?

Two blocks of the same type with different values give crawlers two versions of the same facts. Pause the GTM tag as soon as the template outputs the same markup.

Check what your pages send

Before and after a migration, run the free check on a product or article page to see whether its structured data is in the HTML a crawler receives, with no account needed. If many templates rely on GTM, an audit covers up to 500 pages with evidence and prioritized fixes.

Filed under Structure and schema. Topics: structured-data, json-ld, javascript, raw-html, ai-crawlers