Microdata, JSON-LD, Google Structured Data & your product pages

Comments

2 comments

  • Avatar
    Immanuel

    Hi,

     

    there is a way to get rid of the following warnings:

    The priceValidUntil field is recommended.

    The aggregateRating field is recommended.

    The solution for the aggregateRating problem is, to fetch the necessary data from the Shopify Product Reviews App.

     

    It works, if you change the code of the product__structured-data.liquid. The new code of this file:

     


    <!-- immanuel rossteutscher-json-ld-product -->
    {% assign daysProductPriceValidUntil = 90 | times: 86400 %}
    {%- assign hasReviews = false -%}
    {%- assign reviewAppDescription = blank -%}
    {%- assign ratingValue = blank -%}
    {%- assign reviewCount = blank -%}
    {%- if product.metafields.spr.reviews != blank and hasReviews == false -%}

    {%- assign ratingValueReviewArray = product.metafields.spr.reviews | split: '"ratingValue": "' -%}
    {%- assign ratingValueArr = ratingValueReviewArray[1] |split: '"' -%}
    {%- assign reviewValue = ratingValueArr[0] -%}
    {%- assign reviewsCountStrArray = product.metafields.spr.reviews | split: '"reviewCount": "' -%}
    {%- assign reviewsCountArr = reviewsCountStrArray[1] | split: '"' -%}
    {%- assign reviewsCount = reviewsCountArr[0] -%}
    {%- unless reviewsCount == blank -%}
    {%- assign hasReviews = true -%}
    {%- assign reviewAppDescription = '"Shopify Product Reviews"' -%}
    {%- assign ratingValue = reviewValue -%}
    {%- assign reviewCount = reviewsCount -%}
    {%- endunless -%}
    {%- endif -%}


    {% assign current_variant = product.selected_or_first_available_variant %}

    <script type="application/ld+json">
    {
    "@context": "http://schema.org/",
    "@type": "Product",
    "gtin13": "{{product.selected_or_first_available_variant.barcode}}",
    "name": "{{ product.title | escape }}",
    "url": "{{ shop.url }}{{ product.url }}",
    {%- if product.featured_image -%}
    {%- assign image_size = product.featured_image.width | append: 'x' -%}
    "image": [
    "https:{{ product.featured_image.src | img_url: image_size }}"
    ],
    {%- endif -%}
    {%- if current_variant.sku != blank -%}
    "sku": "{{ current_variant.sku }}",
    {%- endif -%}
    "brand": {
    "@type": "Thing",
    "name": "{{ product.vendor | escape }}"
    },
    {%- if hasReviews and reviewAppDescription and ratingValue and reviewCount -%}
    "aggregateRating": {
    "@type": "AggregateRating",
    "description": {{ reviewAppDescription }},
    "ratingValue": "{{ ratingValue }}",
    "reviewCount": "{{ reviewCount }}"
    },
    {%- endif %}
    "offers": [
    {%- for variant in product.variants -%}
    {
    "@type" : "Offer",
    "gtin13": "{{variant.barcode}}",
    {%- if variant.sku != blank -%}
    "sku": "{{ variant.sku }}",
    {%- endif -%}
    "availability" : "http://schema.org/{% if variant.available %}InStock{% else %}OutOfStock{% endif %}",
    "price" : "{{ variant.price | divided_by: 100.00 }}",
    "priceCurrency" : "{{ cart.currency.iso_code }}",
    "url" : "{{ shop.url }}{{ variant.url }}",
    "priceValidUntil": "{{"now" | date: "%s" | plus: daysProductPriceValidUntil | date: "%Y-%m-%d"}}"
    }{% unless forloop.last %},{% endunless %}
    {%- endfor -%}
    ],
    "description": "{{ product.description | strip_html | escape }}"
    }
    </script>

     

     

    Unfortunately I have not yet a solution for the last warning: 

    The review field is recommended

    0
    Comment actions Permalink
  • Avatar
    Sehrab Naqibulah

    Hey, I'm trying to find the code: itemtype="http://schema.org/Product"/> in my product-template.liquid but it's not there. I'm using Parallax / Madrid version 3.7.2.


    What is going on here?

     

    1
    Comment actions Permalink

Please sign in to leave a comment.