---
title: "AggregateRating Schema"
description: "Add AggregateRating structured data to Sanity documents — display star ratings in Google search results and enable rich snippets for products, courses, and reviews."
canonical: https://sanity-plugin-seofields.thehardik.in/docs/schema-org/aggregate-rating
---

# 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

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `ratingValue` | string | Yes | The average rating value, e.g. "4.5". |
| `bestRating` | string | No | The highest value allowed in this rating system, e.g. "5". Defaults to 5. |
| `worstRating` | string | No | The lowest value allowed in this rating system, e.g. "1". Defaults to 1. |
| `ratingCount` | string | No | The total number of ratings (including those without a review text). |
| `reviewCount` | string | No | The total number of reviews contributing to this rating. |
| `ratingExplanation` | string | No | A short explanation for the rating, e.g. "Based on 120 verified purchases". |
| `author` | string \| object | No | The author of the rating — a URL string or a Person/Organization object. |

## Plugin Registration

```typescript
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:

```typescript
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

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

## Next.js Component

```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

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