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:
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.
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:
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.
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:
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); }); 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.
To make sure that Google can index your structured data, follow the following steps:
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