Google had recently published a developer page for creating structured data with Javascript. The guide provides guidelines on how to generate the structured data properly so that it wins in Google search.
Recommendation: Google Search Console Introduces New Email Preferences And More Control Over Data
Three Ways To Create Structured Data With Javascript:
- Custom Javascript
- Google Tag Manager
- Server-Side Rendering
Providing guidance on how to generate structured data using Javascript will be very helpful as Javascript plays a crucial role in developing sites.
Google Tag Manager
Follow these 6 steps to generate structured data with Google Tag Manager
- Install and set up GTM on your website
- Insert a new custom HTML tag to the container
- Put all the desired structured data block into the tag content
- Install the container as specified in the Install Google Tag Manager section
- Publish your container in the Google Tag Manager system to add the tag to your website.
- Test your execution.
Custom Javascript
Three steps to develop javascript structured data with custom javascript:
- Search for the type of structured data you are interested in
- Edit your site’s HTML so as to insert a javascript snippet (ask your developers or refer to the documents provided by your hosting provider)
- Finally, Test with Rich results test
Google Documentation recommends doing the testing with Rich Results Test because it does two things at once:
- Check the validity of the structured data
- Tests for rich results eligibility
Google also has a structured data testing tool that only checks if the given structured data is valid and does not provide feedback about rich results. Rich Results test, therefore, does two things at once as it shows structured data eligibility and the warnings and errors. There are only two ways to test structured data-
- By entering the URL to make Google crawl the page and find out the structured data and then test it.
- Directly input the code
Google highly recommends using URL input rather than using code input.
Google Recommendation