Installation
Install the plugin and get your GA4 dashboard running in your Sanity Studio.
npm
Package Managers
npm
npm install sanity-plugin-ga-dashboardyarn
yarn add sanity-plugin-ga-dashboardpnpm
pnpm add sanity-plugin-ga-dashboardRequirements
Sanity Studiov3
Reactv18 or v19
Next.jsv13+ (App Router)
rechartsv2+
Peer Dependencies
The plugin requires the following peer dependencies. Most are already included in a standard Sanity + Next.js project:
Install peer dependencies
npm install @sanity/icons @sanity/ui rechartsRegister the Plugin
Add the plugin to your sanity.config.ts (or .js) file:
sanity.config.ts
import { defineConfig } from 'sanity'
import { googleAnalyticsPlugin } from 'sanity-plugin-ga-dashboard'
export default defineConfig({
name: 'your-project',
title: 'Your Project',
projectId: 'your-project-id',
dataset: 'production',
plugins: [
googleAnalyticsPlugin(), // Add the GA4 dashboard
// ... other plugins
],
schema: {
types: [
// ... your schema types
],
},
})Install in Both Packages
If your project uses a monorepo structure (like the Sanity + Next.js template), you need to install the plugin in both your studio and web packages:
Monorepo installation
# In your studio package (for the Sanity Studio dashboard)
cd studio
npm install sanity-plugin-ga-dashboard
# In your frontend package (for the API route)
cd frontend
npm install sanity-plugin-ga-dashboardNext steps: After installation, you need to set up Google Cloud and create the API route to complete the setup.