Skip to main content
seofields
docs

AggregateRating

Add AggregateRating structured data to your Sanity-powered site. Display star ratings in search results to increase click-through rates.

About AggregateRating

AggregateRating can make eligible product, course, and review pages clearer to search engines by describing the average rating and review volume. Rich result display is not guaranteed, but accurate rating markup can improve how users evaluate a result when Google chooses to show it.

Fields

FieldTypeRequiredDescription
ratingValuestringThe average rating value, e.g. "4.5".
bestRatingstringThe highest value allowed in this rating system, e.g. "5". Defaults to 5.
worstRatingstringThe lowest value allowed in this rating system, e.g. "1". Defaults to 1.
ratingCountstringThe total number of ratings (including those without a review text).
reviewCountstringThe total number of reviews contributing to this rating.
ratingExplanationstringA short explanation for the rating, e.g. "Based on 120 verified purchases".
authorstring | objectThe author of the rating — a URL string or a Person/Organization object.

Plugin Registration

sanity.config.ts
import { defineConfig } from "sanity";
import { schemaOrgAggregateRatingPlugin } from "sanity-plugin-seofields/schema";

export default defineConfig({
  // ... your project config
  plugins: [
    schemaOrgAggregateRatingPlugin(),
  ],
});

Schema Usage

Add the schemaOrgAggregateRating field to any document schema:

schemas/page.ts
import { defineField, defineType } from 'sanity'

export default defineType({
  name: 'page',
  title: 'Page',
  type: 'document',
  fields: [
    // ... your other fields
    defineField({
      name: 'schemaOrgAggregateRating',
      title: 'Aggregate Rating',
      type: 'schemaOrgAggregateRating',
    }),
  ],
})

GROQ Query

GROQ query
*[_type == "yourDocument"][0]{
  schemaOrgAggregateRating {
    ratingValue,
    bestRating,
    worstRating,
    ratingCount,
    reviewCount,
    ratingExplanation,
    author
  }
}

Next.js Component

app/layout.tsx
import { AggregateRatingSchema } from "sanity-plugin-seofields/schema/next";

export default function Layout({ children }: { children: React.ReactNode }) {
  // Fetch your rating data from Sanity
  const product = await sanityClient.fetch(query);

  return (
    <html lang="en">
      <body>
        <AggregateRatingSchema data={product.rating} />
        {children}
      </body>
    </html>
  );
}

JSON-LD Output

Generated JSON-LD
{
  "@context": "https://schema.org",
  "@type": "AggregateRating",
  "ratingValue": "4.5",
  "bestRating": "5",
  "worstRating": "1",
  "ratingCount": "350",
  "reviewCount": "120",
  "ratingExplanation": "Based on 120 verified purchases"
}

Last updated: May 27, 2026. Tested with: Sanity Studio v3, v4, and v5.

Was this page helpful?