Generation of structured data using JavaScript for your Google website

Generation of structured data using JavaScript for your Google website

Modern websites are actively using JavaScript to display dynamic content. When you use JavaScript to create structured data on your website, there are several points that you should pay attention to. This manual discusses the best practices and implementation strategies.

If you are just starting to work with structured data, you can familiarize yourself with how these data work in the Google search engine.

There are several options to generate structured data using JavaScript, but the most popular of them are: the following:

  • Google Tag Manager
  • Castle JavaScript

If you use marking for products, keep in mind that dynamically generated marking can reduce the frequency and accuracy of product indexing in search engines, which is especially important for rapidly changing data, such as the availability of goods and its price. If you are a seller who optimizes all types of trade results, make sure that your server is able to cope with an increased load from Google.

Using Google Tag Manager for the dynamic generation JSON-LD for your Google website

Google Tag Manager is a platform that allows you to control tags on your site without the need to edit the code. To generate structured data using Google Tag Manager, follow the following steps:

  • Set up and install Google Tag Manager on your site.
  • Add a new user -tag to the container.
  • Insert the supported block of structured data into the tag content.
  • Install the container as shown in the menu of the container administrator.
  • To add a tag to your site, publish a container in the Google Tag Manager interface.
  • Test the implementation.

Use of Google Tag Manager variables for your Google site

Google Tag Manager (GTM) supports the use of variables in order to extract data from the page and include it in structured data. The use of variables avoids duplication of information in GTM, which reduces the risk of discrepancies between the content of the page and structured data implemented using GTM.

For example, you can dynamically create a JSON-LD block for a recipe that uses the name of the page as the name of the recipe, creating the following user variable named Recipe_Name:

 function() { return document.title; } 

After that, you can use recipe_name in your custom -tag.

We recommend that you create variables for collecting all the necessary information from the page.

Here is an example of the contents of the custom -tag:

  

Note: This example suggests that you have determined the variables recipe_name, recipe_image and recipe_author in GTM.

Generation of structured data using a custom JavaScript for your Google website

Another method for generating structured data is the use of JavaScript to generate all your data or to add information to server markings. In any case, Google can process and understand the structured data that are present in DOM when rendering the page. To find out more about how Google processes JavaScript, read the JavaScript leadership.

An example of generated structured data using JavaScript:

  • Determine the type of structured data that interests you.
  • Edit your site to enable the next fragment JavaScript (refer to the documentation of your CMS or hosting supplier, or contact the developers).
 fetch('https://api.example.com/recipes/123') .then(response => response.text()) .then(structuredDataText => { const script = document.createElement('script'); script.setAttribute('type', 'application/ld+json'); script.textContent = structuredDataText; document.head.appendChild(script); }); 
  • Test your implementation using the Rich Results Test tool.

Using server rendering for structured data on your Google website

If you use server rendering, you can also include structured data in the result of rendering. Check out the documentation of your framework to find out how to generate JSON-LD for the desired type of structured data.

Testing your implementation of structured data for your Google website

To make sure that Google can index your structured data, follow the following steps:

  • Open the Rich Results Test tool.
  • Enter the URL pages you want to test. We recommend using the URL input, not code, because when using the code, restrictions may occur (for example, CORS restrictions).
  • Click "Test url".

Success: If you have done everything correctly and your type of structured data is supported in the tool, you will see the message "Page is Eligible for Rich Results". If you test the type of structured data that is not supported in the Rich Results test, check rendering. If it contains structured data, Google will be able to process it.

Try again: If there are errors or warnings, most likely it is a syntactic error or an absent property. Check out the documentation for your type of structured data and make sure that you have added all the necessary properties. If the problem is not eliminated, also check the guide to fix the problems with JavaScript for the search.

If you need help in generating or testing structured data for your site, you can contact the SEO company "SEO.computer" for any issue on email info@seo.computer Or through WhatsApp +79202044461.

ID 15

Send a request and we will provide a consultation on SEO promotion of your website