GA Analytics
docs

Search Console Setup

Configure Google Cloud so the plugin can securely access your Search Console data.

Already set up the GA plugin? If you've already configured a service account for the Google Analytics plugin, you can reuse the same credentials. Just make sure to enable the Search Console API and add the service account to your Search Console property (Steps 2 and 5 below).

Step 1: Create a Google Cloud Project

If you don't already have one, create a Google Cloud project:

1Go to the Google Cloud Console (console.cloud.google.com)
2Click "Select a project" → "New Project"
3Enter a project name (e.g., "My Website Analytics")
4Click "Create"

Step 2: Enable the Search Console API

1In Google Cloud Console, go to "APIs & Services" → "Library"
2Search for "Google Search Console API"
3Click on it and press "Enable"

Important: Make sure you enable the Google Search Console API (also known as the Search Console API / Webmasters API), not the “Google Analytics Data API”.

Step 3: Create a Service Account

Skip this step if you already have a service account from the GA plugin setup.

1Go to "IAM & Admin" → "Service Accounts"
2Click "+ Create Service Account"
3Enter a name (e.g., "sanity-analytics") and description
4Click "Create and Continue" (skip optional role assignment)
5Click "Done"

Step 4: Generate a JSON Key

Skip this step if you already have a JSON key from the GA plugin setup.

1Click on the service account you just created
2Go to the "Keys" tab
3Click "Add Key" → "Create new key"
4Select "JSON" and click "Create"
5A JSON file will be downloaded — keep it safe!

The JSON key file contains the credentials you'll need:

service-account-key.json
{
  "type": "service_account",
  "project_id": "your-project-id",
  "private_key_id": "abc123...",
  "private_key": "-----BEGIN PRIVATE KEY-----\nMIIEv...\n-----END PRIVATE KEY-----\n",
  "client_email": "sanity-analytics@your-project.iam.gserviceaccount.com",
  "client_id": "123456789",
  ...
}

Step 5: Add Service Account to Search Console

1Go to Google Search Console (search.google.com/search-console)
2Select your property (URL or domain)
3Go to Settings → Users and permissions
4Click "Add user"
5Enter the service account email (e.g., sanity-analytics@your-project.iam.gserviceaccount.com)
6Set the permission to "Full" (needed for sitemap management) or "Restricted" (read-only)
7Click "Add"

Permission level: If you want to use the sitemap submit/re-submit feature from the dashboard, choose “Full” permission. For read-only access to search data, “Restricted” is sufficient.

Step 6: Set Environment Variables

Add these environment variables to your .env.local file in the web/frontend package:

.env.local
# Service account credentials (same as GA plugin)
GA_SERVICE_ACCOUNT_EMAIL=sanity-analytics@your-project.iam.gserviceaccount.com
GA_PRIVATE_KEY="-----BEGIN PRIVATE KEY-----\nMIIEv...\n-----END PRIVATE KEY-----\n"

# Search Console site URL (the property URL registered in Search Console)
SEARCH_CONSOLE_SITE_URL=https://your-website.com

SEARCH_CONSOLE_SITE_URL must match exactly how your property appears in Search Console. For a URL prefix property, include the protocol (e.g., https://example.com). For a domain property, use sc-domain:example.com.

Next step: Now create the API route → so the dashboard can fetch Search Console data.