Analytics
docs
Plugin

Introduction

sanity-plugin-analytics brings GA4 analytics, Google Search Console, and Lighthouse performance audits into Sanity Studio — so your content team has everything they need without leaving the Studio.

Why this plugin?

Content teams shouldn't need to tab over to Google Analytics, Search Console, or Lighthouse to understand how their content performs. This plugin surfaces analytics, search rankings, and performance scores directly inside the Studio — one place, zero context switching.

Features

01
GA4 Analytics

Overview Metrics

10 KPIs — users, sessions, pageviews, bounce rate, engagement rate, session duration.

Traffic & Channels

Time series & hourly charts plus channel grouping.

Content & Pages

Top 15 pages and 10 landing pages with session counts.

Audience & Devices

Device, browser & OS breakdown, new vs returning.

Geography

Top 10 countries and cities by active users.

Events & Acquisition

Top 15 events, traffic sources, referrers.

02
Search Console

Query Analytics

Top queries with clicks, impressions, CTR, and average position.

Performance Trends

Daily time-series charts for clicks and impressions.

Country & Device

Geographic and device splits with per-segment performance.

03
Lighthouse

PageSpeed Scores

Performance, Accessibility, Best Practices, and SEO — 0–100 per page.

Mobile & Desktop

Run audits for both strategies and compare in one view.

Persistent Reports

Scores stored as Sanity documents — track improvement over time.

04
Platform

16 Parallel Queries

All GA4 data fetched at once via Promise.allSettled() — fast first load.

Smart Caching

5-min public cache + 1-hour in-memory token cache.

Date Ranges

7, 14, 30 or 90 day views.

Service Auth

JWT-based GCP service account — no OAuth required.

Full TypeScript

Exported types for all API data structures.

Dashboard Tabs

Seven sections, all loaded in a single API call.

01
Overview

10 KPIs, daily time-series area chart, hourly traffic bar chart, and a live active-user badge showing the last 30 minutes.

02
Traffic

Channel grouping donut, daily sessions trend, top-10 traffic sources table, and top referrer URLs.

03
Content

Top 15 pages by screen page views and top 10 landing pages by sessions — ranked tables with sparkline indicators.

04
Audience

Device category split, browser & OS distribution charts, and a new vs returning visitor ratio gauge.

05
Geography

Top 10 countries and top 10 cities ranked by active user count with session percentages.

06
Events

Top 15 GA4 events — automatically collected and custom — with event count and unique user count per event.

07
Acquisition

Traffic sources by session/medium pair, channel grouping breakdown, and top external referrer URLs.

Quick Example

Use the combined plugin for all three tools in one toolbar entry:

sanity.config.ts
import { defineConfig } from 'sanity'
import { sanityAnalyticsPlugin } from 'sanity-plugin-analytics'

export default defineConfig({
  name: 'my-project',
  title: 'My Project',
  projectId: 'your-project-id',
  dataset: 'production',
  plugins: [
    sanityAnalyticsPlugin({
      analytics: {},            // GA4 dashboard
      searchConsole: {},        // Search Console dashboard
      lighthouse: {             // Lighthouse dashboard
        siteUrl: 'https://mysite.com',
        documentTypes: [{ type: 'post', slugField: 'slug', pathPrefix: '/blog' }],
      },
    }),
  ],
  schema: { types: [/* your schemas */] },
})

Or use individual plugins — googleAnalyticsPlugin(), searchConsolePlugin(), lighthousePlugin() — each adds its own tool to the Sanity toolbar.