web-dev-qa-db-ja.com

「Product」と「breadcrumb」を同じJSON-LDタグに入れる

製品ページに以前のJSON-LDタグがあり、うまく機能しました(エラーなし、 Googleの構造化データテストツール で3つの警告)。

<script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "Product",
            "name": "My product name",
            "description": "My product description",
            "image": [
                "https://link.to/my/image_1.jpg",
                "https://link.to/my/image_2.jpg",
                "https://link.to/my/image_3.jpg"
            ],
            "sku": "00000100000",
            "brand": {
                "@type": "Thing",
                "name": "BRANDNAME"
            },
            "offers": {
                "@type": "Offer",
                "url": "https://link.to/my/product/id",
                "priceCurrency": "EUR",
                "price": "249.90",
                "itemCondition": "https://schema.org/NewCondition",
                "availability": "https://schema.org/InStock"
            },
            "reviews": [
                {
                    "@type": "Review",
                    "datePublished": "2019/03/19",
                    "name": "Very Nice product",
                    "reviewBody": "Very Nice product \r\nI mean it",
                    "reviewRating": {
                        "@type": "Rating",
                        "ratingValue": 5,
                        "bestRating": 5,
                        "worstRating": 1
                    },
                    "author": {
                        "@type": "Person",
                        "name": "ClientPseudo"
                    }
                }
            ],
            "aggregateRating": {
                "@type": "AggregateRating",
                "ratingValue": "5",
                "reviewCount": 1,
                "bestRating": 5,
                "worstRating": 1
            }
        }
</script>

私のbreadcrumbコンテンツをProductタイプのmainEntityに移動してItemPageを追加しようとしました ここで提案されているように 、しかしツールは警告を表示しなくなりました。

<script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "ItemPage",
            "mainEntity": {
                "@type": "Product",
                "name": "My product name",
                "description": "My product description",
                "image": [
                    "https://link.to/my/image_1.jpg",
                    "https://link.to/my/image_2.jpg",
                    "https://link.to/my/image_3.jpg"
                ],
                "sku": "00000100000",
                "brand": {
                    "@type": "Thing",
                    "name": "BRANDNAME"
                },
                "offers": {
                    "@type": "Offer",
                    "url": "https://link.to/my/product/id",
                    "priceCurrency": "EUR",
                    "price": "249.90",
                    "itemCondition": "https://schema.org/NewCondition",
                    "availability": "https://schema.org/InStock"
                },
                "reviews": [
                    {
                        "@type": "Review",
                        "datePublished": "2019/03/19",
                        "name": "Very Nice product",
                        "reviewBody": "Very Nice product \r\nI mean it",
                        "reviewRating": {
                            "@type": "Rating",
                            "ratingValue": 5,
                            "bestRating": 5,
                            "worstRating": 1
                        },
                        "author": {
                            "@type": "Person",
                            "name": "ClientPseudo"
                        }
                    }
                ],
                "aggregateRating": {
                    "@type": "AggregateRating",
                    "ratingValue": "5",
                    "reviewCount": 1,
                    "bestRating": 5,
                    "worstRating": 1
                }
            },
            "breadcrumb": {
                "@type": "BreadcrumbList",
                "itemListElement": [
                    {
                        "@type": "ListItem",
                        "position": 1,
                        "item": {
                            "@id": "/",
                            "name": "Home"
                        }
                    },
                    {
                        "@type": "ListItem",
                        "position": 2,
                        "item": {
                            "@id": "/myCategory",
                            "name": "My Category"
                        }
                    },
                    {
                        "@type": "ListItem",
                        "position": 3,
                        "item": {
                            "@id": "/mySubCategory",
                            "name": "My subcategory"
                        }
                    }
                ]
            }
        }
</script>

コードが有効であることを確認するにはどうすればよいですか?

2
Marc Brillault

マークアップは有効です。ただし、Productを最上位から最下位に移動すると、テストツールは警告を抑制します。

http://linter.structured-data.org/ を使用してページを調べます-すべてが適切です。

実際に本当にテストツールで警告を表示したい場合は、以下の例のようにmainEntitymainEntityOfPageと反対のタイプを使用します。これは有効であり、テストツールに警告を表示させます。 Productタイプはトップレベルのままです。

    <script type="application/ld+json">
        {
            "@context": "https://schema.org/",
            "@type": "Product",
            "name": "My product name",
            "description": "My product description",
            "image": [
                "https://link.to/my/image_1.jpg",
                "https://link.to/my/image_2.jpg",
                "https://link.to/my/image_3.jpg"
            ],
            "sku": "00000100000",
            "brand": {
                "@type": "Thing",
                "name": "BRANDNAME"
            },
            "offers": {
                "@type": "Offer",
                "url": "https://link.to/my/product/id",
                "priceCurrency": "EUR",
                "price": "249.90",
                "itemCondition": "https://schema.org/NewCondition",
                "availability": "https://schema.org/InStock"
            },
            "reviews": [
                {
                    "@type": "Review",
                    "datePublished": "2019/03/19",
                    "name": "Very Nice product",
                    "reviewBody": "Very Nice product \r\nI mean it",
                    "reviewRating": {
                        "@type": "Rating",
                        "ratingValue": 5,
                        "bestRating": 5,
                        "worstRating": 1
                    },
                    "author": {
                        "@type": "Person",
                        "name": "ClientPseudo"
                    }
                }
            ],
            "aggregateRating": {
                "@type": "AggregateRating",
                "ratingValue": "5",
                "reviewCount": 1,
                "bestRating": 5,
                "worstRating": 1
            },
            "mainEntityOfPage":{
            "@type": "ItemPage",
            "@id": "https://link.to/my/product/id",
             "breadcrumb": {
                "@type": "BreadcrumbList",
                "itemListElement": [{
    "@type": "ListItem",
    "position": 1,
    "name": "Books",
    "item": "https://example.com/books"
  },{
    "@type": "ListItem",
    "position": 2,
    "name": "Authors",
    "item": "https://example.com/books/authors"
  },{
    "@type": "ListItem",
    "position": 3,
    "name": "Ann Leckie",
    "item": "https://example.com/books/authors/annleckie"
  },{
    "@type": "ListItem",
    "position": 4,
    "name": "Ancillary Justice",
    "item": "https://example.com/books/authors/ancillaryjustice"
  }]
}
            }
            }
        }
</script>
1
Evgeniy

stackOverflowに関するこの回答 のおかげで、 名前付きグラフ 配列を使用して、製品とブレッドクラムの両方で機能するコードを作成できました。

<script type="application/ld+json">
               {
            "@context": "https://schema.org/",
            "@type": "ItemPage",
            "@graph": [
                {
                    "@type": "Product",
                    "name": "My product name",
                    "description": "My product description",
                    "image": [
                        "https://link.to/my/image_1.jpg",
                        "https://link.to/my/image_2.jpg",
                        "https://link.to/my/image_3.jpg"
                    ],
                    "sku": "00000100000",
                    "brand": {
                        "@type": "Thing",
                        "name": "BRANDNAME"
                    },
                    "offers": {
                        "@type": "Offer",
                        "url": "https://link.to/my/product/id",
                        "priceCurrency": "EUR",
                        "price": "249.90",
                        "itemCondition": "https://schema.org/NewCondition",
                        "availability": "https://schema.org/InStock"
                    },
                    "reviews": [
                        {
                            "@type": "Review",
                            "datePublished": "2019/03/19",
                            "name": "Very Nice product",
                            "reviewBody": "Very Nice product \r\nI mean it",
                            "reviewRating": {
                                "@type": "Rating",
                                "ratingValue": 5,
                                "bestRating": 5,
                                "worstRating": 1
                            },
                            "author": {
                                "@type": "Person",
                                "name": "ClientPseudo"
                            }
                        }
                    ],
                    "aggregateRating": {
                        "@type": "AggregateRating",
                        "ratingValue": "5",
                        "reviewCount": 1,
                        "bestRating": 5,
                        "worstRating": 1
                    }
                },
                {
                    "@type": "BreadcrumbList",
                    "itemListElement": [
                        {
                            "@type": "ListItem",
                            "position": 1,
                            "item": {
                                "@id": "/",
                                "name": "Home"
                            }
                        },
                        {
                            "@type": "ListItem",
                            "position": 2,
                            "item": {
                                "@id": "/myCategory",
                                "name": "My Category"
                            }
                        },
                        {
                            "@type": "ListItem",
                            "position": 3,
                            "item": {
                                "@id": "/mySubCategory",
                                "name": "My subcategory"
                            }
                        }
                    ]
                }
            ]
        }
    </script>
0
Marc Brillault