Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Google Rich Snippets Support For Product Ratings #36

Open
octave opened this issue Nov 20, 2024 · 2 comments
Open

Google Rich Snippets Support For Product Ratings #36

octave opened this issue Nov 20, 2024 · 2 comments

Comments

@octave
Copy link

octave commented Nov 20, 2024

It would be great to show how to implement google rich snippets using the summaryData in the Hydrogen demo store, similar to this:

https://support.okendo.io/en/articles/3813081-set-up-google-rich-snippets-for-product-ratings

@octave
Copy link
Author

octave commented Nov 20, 2024

Here is how I did it so far:

Add this to your product query:

reviewsData: metafield(namespace: "okendo", key: "summaryData") {
  value
  type
}

Then in your loader:

type ReviewsData = {
  reviewAverageValue: number;
  reviewCount: number;
};

let reviewsData: ReviewsData | null;
  try {
    reviewsData = product?.reviewsData?.value
      ? (JSON.parse(product.reviewsData.value) as ReviewsData)
      : null;
  } catch (error) {
    console.error('Failed to parse reviews data:', error);
    reviewsData = null;
  }
const aggregateRating = {
  '@type': 'AggregateRating',
  ratingValue: reviewsData?.reviewAverageValue ?? 5,
  ratingCount: reviewsData?.reviewCount ?? 1,
};

@Zwyx
Copy link
Member

Zwyx commented Nov 22, 2024

Hi Octave, indeed we can definitely do that. We should be able to work on it soon. Thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants