Lighthouse Schema
The plugin registers an analytics.lighthouseReport document type in your Sanity schema to persist audit results.
Auto-registered. When you use lighthousePlugin() or sanityAnalyticsPlugin(), the schema type is automatically added to your studio — you don't need to add it manually.
Schema Definition
Schema exports
// Exported from 'sanity-plugin-analytics'
import { analyticsSchemas, lighthouseReport } from 'sanity-plugin-analytics'
// analyticsSchemas = [lighthouseReport]
// Already registered by the plugin — only import if you need manual controlanalytics.lighthouseReport schema
// analytics.lighthouseReport
{
name: 'analytics.lighthouseReport',
title: 'Lighthouse Report',
type: 'document',
fields: [
{ name: 'documentId', type: 'string' }, // Sanity document ID
{ name: 'documentType', type: 'string' }, // e.g. 'post'
{ name: 'title', type: 'string' }, // display name
{ name: 'url', type: 'url' }, // audited URL
{ name: 'strategy', type: 'string' }, // 'mobile' | 'desktop'
{ name: 'lastGenerated', type: 'datetime' }, // ISO timestamp
{ name: 'performance', type: 'number' }, // 0.0 – 1.0
{ name: 'accessibility', type: 'number' }, // 0.0 – 1.0
{ name: 'bestPractices', type: 'number' }, // 0.0 – 1.0
{ name: 'seo', type: 'number' }, // 0.0 – 1.0
{ name: 'report', type: 'text' }, // raw JSON from PageSpeed API
],
}Fields Reference
| Field | Type | Description |
|---|---|---|
documentId | string | ID of the source Sanity document (drafts. prefix stripped). |
documentType | string | Sanity _type of the source document. |
title | string | Display title resolved from the document's titleField. |
url | url | The public URL that was audited. |
strategy | string | 'mobile' or 'desktop'. |
lastGenerated | datetime | When this report was last generated. |
performance | number | Performance score 0.0–1.0 (multiply × 100 for display). |
accessibility | number | Accessibility score 0.0–1.0. |
bestPractices | number | Best Practices score 0.0–1.0. |
seo | number | SEO score 0.0–1.0. |
report | text | Raw JSON response from the PageSpeed Insights API. |
GROQ Queries
You can query Lighthouse reports in GROQ just like any other document:
GROQ examples
// All reports, newest first
*[_type == "analytics.lighthouseReport"] | order(lastGenerated desc) {
_id, url, title, strategy, lastGenerated,
performance, accessibility, bestPractices, seo
}
// Only mobile reports with performance < 0.5 (poor)
*[_type == "analytics.lighthouseReport" && strategy == "mobile" && performance < 0.5] {
url, title, performance, lastGenerated
}
// Latest report per URL (mobile)
*[_type == "analytics.lighthouseReport" && strategy == "mobile"] | order(lastGenerated desc) {
url, title, performance, accessibility, bestPractices, seo
}TypeScript Types
TypeScript types
import type {
LighthouseCandidate,
LighthouseConfig,
LighthouseDocumentTypeConfig,
LighthouseReportSummary,
LighthouseResolveContext,
LighthouseStrategy,
} from 'sanity-plugin-analytics'
// LighthouseReportSummary matches the stored document shape
const report: LighthouseReportSummary = {
_id: 'analytics-lighthouse-mobile-abc123',
url: 'https://mysite.com/blog/my-post',
title: 'My Post',
documentId: 'abc123',
documentType: 'post',
strategy: 'mobile',
lastGenerated: '2025-06-01T12:00:00Z',
performance: 0.87,
accessibility: 0.95,
bestPractices: 0.92,
seo: 1.0,
}Manual schema registration. If you need to add the schema without using the plugin (e.g. to use it in another tool), import and register it directly:
Manual schema registration
import { defineConfig } from 'sanity'
import { analyticsSchemas } from 'sanity-plugin-analytics'
export default defineConfig({
schema: {
types: [...analyticsSchemas, /* your types */],
},
})Back to setup: Lighthouse Configuration →