12

I have a page where some events are dynamically loaded by reading some JSON with JavaScript. I build a div for every event with the Event Schema.org markup.

Google's testing tool doesn't read this markup. Is it because of an error in the markup, or is it because of the dynamic loading?

The HTML code of one Event is:

<div class="evento well" itemscope itemtype="http://schema.org/Event">
   <meta itemprop="startDate" content="2015-03-20T20:00:00.000Z">
   <meta itemprop="endDate" content="2015-01-21T20:00:00.000Z">
   <div class="dataEvento">
      <div class="dayWeekEvento">venerdì</div>
      <div class="dayNumEvento">20</div>
      <div class="monthEvento">Marzo</div>
   </div>
   <div class="datiEvento">
      <div class="oraEvento">ore 21:00</div>
      <div class="titoloEvento"><span itemprop="name">Titolo evento</span></div>
      <div class="luogoEvento" itemprop="address" itemscope="" itemtype="http://schema.org/PostalAddress"><a href="https://www.google.it/maps/place/Milano" target="_blank"><span class=" glyphicon glyphicon-map-marker" aria-hidden="true"></span> <span itemprop="addressLocality">Milano</span></a></div>
   </div>
</div>
TallTed
  • 9,069
  • 2
  • 22
  • 37
Migio B
  • 405
  • 1
  • 6
  • 22
  • you need to add the actual code you used, otherwise we cant look to see if its an error in our code – Jonathan Mar 15 '15 at 18:41
  • 2
    The short answer is **no**: Google will mostly only crawl the static markup of your page. That mens that you will have to provide the microtags in the markup that is eother static or rendered server side. If you make usage of a heavy javaScript Framework like Backbone, Angular, Ember and so on, you have the ability to let all of your pages be rendered by a service and be saved under the same URL, but with a #! (hashbang). Google, Bing and Yahoo (and some other) will try and index the hashbang URLS instead of the original ones then. – Rias Mar 15 '15 at 19:59

3 Answers3

25

Google’s documentation only mentions that they can consume dynamically added structured data if the syntax JSON-LD is used:

Also, Google can read JSON-LD data even when it is dynamically injected into the page's contents, such as by Javascript code or embedded "widgets".

This does not necessarily mean that they can’t read it in case of other syntaxes (like Microdata or RDFa), but at least they don’t document it.

That their testing tool doesn’t read it may or may not mean something (it could be that the tool doesn’t handle this but their internal system does). However, there should be no issue with your actual markup, as you can easily test it yourself by pasting your markup instead of entering your URL.

unor
  • 92,415
  • 26
  • 211
  • 360
  • 1
    are you sure about there internal system does?, I can't find it in there documentation – Karim Samir Oct 22 '15 at 20:52
  • @KarimSamir: What do you mean exactly? Sure that which system does what? – unor Oct 22 '15 at 21:10
  • Google does also pick up dynamically added or altered microdata. Their SD Testing Tool can deal with some JavaScript, but is far from 100% on it. You can paste in pre-rendered html to test things. The Google Search Console Structured Data report provides more accurate data on how Google read your markup, but you do have to wait until the page is crawled and processed. – Tony McCreath Jul 18 '18 at 07:36
  • Just recently Google added in their documentation that generating JSON-LD with Javascript is allowed and interpreted: https://developers.google.com/search/docs/guides/generate-structured-data-with-javascript – Daniel Amerbauer Apr 24 '20 at 06:40
3

If you're having trouble validating schema markup with the Google testing tool, you can create the json-ld snippet with JS, which also allows you to manipulate the data if needed like:

<script> 
    (function(){
       var data = {
            "@context": "http://www.schema.org",
            ...
        }
        var script = document.createElement('script');
        script.type = "application/ld+json";
        script.innerHTML = JSON.stringify(data);
        document.getElementsByTagName('head')[0].appendChild(script); 
    })(document);
</script>
Rich S
  • 111
  • 3
0

It depends on what type of markup it is. From Google:

JSON-LD is supported for all Knowledge Graph features, sitelink search boxes, Event Rich Snippets, and Recipe Rich Snippets; Google recommends the use of JSON-LD for those features. For the remaining Rich Snippets types and breadcrumbs, Google recommends the use of microdata or RDFa.

It should work but I know people have reported problems with the testing tool.

David Garcia
  • 101
  • 2