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 shows star ratings in search results, increasing CTR. When users see ratings directly in the SERP, they are more likely to click through to your page, especially for product and service listings.

Fields

FieldTypeRequiredDescription
ratingValuenumberThe average rating value (e.g. 4.5 out of 5).
reviewCountnumberThe total number of reviews contributing to the rating.

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 theschemaOrgAggregateRating 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
const query = groq`*[_type == "product"][0]{
  "rating": schemaOrgAggregateRating {
    ratingValue,
    reviewCount
  }
}`;

Next.js Component

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

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,
  "reviewCount": 120
}

Was this page helpful?