Configuration
Configure the plugin options when registering it in your Sanity config.
Plugin Options
// sanity.config.ts
import { defineConfig } from 'sanity'
import { googleAnalyticsPlugin } from 'sanity-plugin-ga-dashboard'
export default defineConfig({
// ...other config
plugins: [
googleAnalyticsPlugin({
// All options are optional
apiUrl: '/api/analytics', // Default: '/api/analytics'
disabled: false, // Default: false
}),
],
})Options Reference
| Option | Type | Default | Description |
|---|---|---|---|
apiUrl | string | '/api/analytics' | URL of the API route that serves analytics data |
disabled | boolean | false | Disable the plugin entirely — the tool won't appear in the Sanity toolbar. Useful for environment-based toggling. |
Custom API URL
If your API route is at a different path than the default /api/analytics, specify it:
googleAnalyticsPlugin({
apiUrl: '/api/my-analytics'
})Make sure the API route file is at the matching path. For the example above, the file would be at app/api/my-analytics/route.ts.
Environment-based Toggling
Use the disabled option to show the dashboard only in specific environments — for example, production only:
googleAnalyticsPlugin({
disabled: process.env.NODE_ENV !== 'production',
})When disabled is true, the Google Analytics tool is completely omitted from the Sanity toolbar and no requests are made.
Zero Config
The plugin works with zero configuration if you use the default API route path:
// Simplest configuration — no options needed
plugins: [
googleAnalyticsPlugin(),
]As long as your API route is at /api/analytics and your environment variables are set, the plugin will work out of the box.
TypeScript
The plugin config type is exported if you need it:
import type { GoogleAnalyticsPluginConfig } from 'sanity-plugin-ga-dashboard'
const config: GoogleAnalyticsPluginConfig = {
apiUrl: '/api/analytics',
disabled: process.env.NODE_ENV !== 'production',
}