April 9th 2020

How to Implement Schema Markup with Google Tag Manager

Note: In our experience, schema markup implemented via GTM (Google Tag Manager) is a great option if there’s a development backlog. It can be a great way to test before going ahead with a full implementation and is quick to deploy for a quick win. However, this is not always our preferred implementation. Occasionally it can take longer for this to be picked up by Search Engines and in rare cases, not indexed at all. Therefore, if possible, always implement schema directly in the source code.

This article assumes you have a basic understanding of schema markup and can create your own JSON-LD markup. You can refresh your memory by reading our Beginners’ Guide to Structured Data.

How to Implement Schema with Google Tag Manager

  • You’ll need to start with your JSON-LD markup. If you need help creating this, jump over to this article.
  • Validate your JSON-LD markup by pasting your code snippet into the Structured Data Testing Tool and checking for errors.
  • With your validated code, go to Google Tag Manager, and in a new workspace, click ‘Add a New Tag’
New Tag button is in the top left hand corner of the screen
  • Give your tag a name and select the ‘Custom HTML’ option from the Tag Configuration box.
Add a name in the top left hand corner. The tag configuration box is at the top. Select the 'Custom HTML; option from the right hand popover.
  • Paste your JSON-LD into the box.
Paste JSON-LD into the box below 'Custom HTML'
  • Next, we need to set up a trigger for the new tag. The trigger determines when our new tag will fire. In this case, it should only fire on one page. To do this, we need to click into the ‘Triggering’ box, (the box below the Tag Configuration box) and create a new trigger by using the ‘+’ icon in the top right.
Click the 'Triggering' box below the 'Tag Configuration'. Add a new trigger with the blue + in the top right hand corner.
  • This will open a new dialogue box, which allows you to give the trigger a name.
Give the trigger a name in the top left hand corner
  • Name your trigger, and then click the Trigger Configuration box to choose a trigger type and choose ‘Page View’.
In the right hand pop-over, select 'Page View' which is the first option.
  • Select the ‘some page views’ checkbox, which will show you more options.
Select the second checkbox, 'Some Page Views' and then use the drop downs to select 'Page Path', 'equals' and your URL slug.
  • From the drop-downs, select ‘Page Path’ and ‘equals’ and add your URL slug.
  • Save your trigger, and then save your tag. You should now have schema markup ready to test!

Testing Your Schema Markup

There are two ways we need to check our schema markup. Firstly, we need to verify that the tag is firing correctly in GTM before we publish the container. Next, we need to validate the markup using the structured data tester.

Testing the Tag is Firing Correctly

Now we should have a tag saved in its own workspace in GTM, but not published. To test the tag is working correctly, enter preview mode by clicking the ‘Preview’ button in the top right-hand corner.  Next, open a new tab, and go to the page you’ve added schema markup to. You’ll see ‘Tags Fired on This Page’ in the debugger’s dialogue box, under the ‘Tags’ tab. Click on this to dive deeper and check that your schema tag has fired. Hopefully you’ll see your tag, and when you click on that it should reveal your JSON-LD code.

Next, navigate to a few pages that shouldn’t have this piece of markup on them. Double check that your new tag is not being fired on these pages using the same method. Once you’re satisfied your tag is firing correctly, you can publish your container!

Testing the Markup is Being Detected Correctly

Once you have published your container, you can test the schema is able to be detected. Open your newly marked up page, and right click and ‘View Source’. Copy the entire source code, and open a new tab.

Go to the Structured Data Testing Tool and select ‘Code Snippet’. Paste in your copied code and hit ‘Run Test’. Look for your new schema in the right-hand column of the results page, check that it’s appeared and is error free. Normally, you can test a structured data implementation using the URL, but sometimes when you’ve used GTM to implement schema it’s not picked up this way (due to the way GTM injects code), so it’s best to test with the rendered HTML for the page.

You’ve now implemented schema markup using GTM! Want to get more out of GTM? Check out our step by step guide to tracking element visibility using GTM .