Duplicate schema/structured data markup?

2019-08-06 03:03发布

问题:

Will this structure be problematic?

<script type="application/ld+json">
{  
   "@context":"http://schema.org",
   "@type":"WebPage",
   "name":"Postcards",
   "url":"https://local.mysite.com/postcards.html",
   "breadcrumb":{  
      "@type":"BreadcrumbList",
      "itemListElement":[  
         {  
            "@type":"ListItem",
            "position":1,
            "item":{  
               "@id":"https://local.mysite.com",
               "name":"My Site"
            }
         },
         {  
            "@type":"ListItem",
            "position":2,
            "item":{  
               "@id":"https://local.mysite.com/postcards.html",
               "name":"Postcards"
            }
         }
      ]
   },
   "mainEntity":{  
      "@type":"WebPageElement",
      "offers":{  
         "@type":"Offer",
         "itemOffered":[  
            {  
               "@type":"Product",
               "name":"Christmas Postcards",
               "url":"https://local.mysite.com/christmas-postcards.html"
            },
            {  
               "@type":"Product",
               "name":"Getaway Postcards",
               "url":"https://local.mysite.com/getaway-postcards.html"
            }
         ]
      }
   }
}</script>

<script type="application/ld+json">
{  
   "@context":"http://schema.org",
   "@type":"WebPage",
   "name":"Postcards",
   "url":"https://local.mysite.com/postcards.html",
   "breadcrumb":{  
      "@type":"BreadcrumbList",
      "itemListElement":[  
         {  
            "@type":"ListItem",
            "position":1,
            "item":{  
               "@id":"https://local.mysite.com",
               "name":"My Site"
            }
         },
         {  
            "@type":"ListItem",
            "position":2,
            "item":{  
               "@id":"https://local.mysite.com/postcards.html",
               "name":"Postcards"
            }
         }
      ]
   },
   "mainEntity":{  
      "@type":"WebPageElement",
      "offers":{  
         "@type":"Offer",
         "itemOffered":[  
            {  
               "@type":"Product",
               "name":"Mini Postcards",
               "url":"https://local.mysite.com/mini-postcards.html"
            },
            {  
               "@type":"Product",
               "name":"Summer Postcards",
               "url":"https://local.mysite.com/summer-postcards.html"
            }
         ]
      }
   }
}</script>

The reason there could be "duplicate" markup like this for a single category page is that the page may use multiple product templates.

In the current implementation, the markup is dynamically constructed in the product template. For example, if there are two product templates for a single Category Page, the markup will be reconstructed twice, but containing different WebPageElement.

Will this yield bad results? I checked in Google's testing tool and it didn't give me any errors or warnings.

回答1:

Multiple nodes, same entity

If you have multiple nodes that represent the same entity on a page, the best practice is to give these nodes the same URI as identifier.

With JSON-LD, you can provide identifiers with @id.

So

  • both of your WebPage items could get "@id": "" (for the current URL; preferably specify your canonical URL here),
  • both of your BreadcrumbList items could get "@id": "#breadcrumbs",
  • both of your ListItem-1 items could get "@id": "#breadcrumbs-1", and
  • both of your ListItem-2 items could get "@id": "#breadcrumbs-2".

That way, Google’s SDTT will display each of these items only once, because it now knows that they are about the same entity.

Referencing nodes instead of duplicating them

@id also allows you to reference nodes instead of embedding them (and thereby duplicating their data). See an example.

In your case this would have the advantage that you don’t have to duplicate the WebPage/BreadcrumbList/ListItem nodes to begin with. You would specify these nodes once, and each product template would then outpout only the Offer/Product nodes. These nodes could include (reverse) references to the WebPage/etc. (might be easier for you to implement), or the WebPage/etc. could reference these nodes.