Google Cloud Setup
Set up a Google Cloud service account to securely connect your GA4 property to the plugin.
Why a service account? The plugin uses a service account (not OAuth) to access GA4 data. This means no user login flow is needed — the plugin authenticates automatically using JWT credentials stored in environment variables.
Step 1: Create a Google Cloud Project
If you don't already have one, create a Google Cloud project:
Step 2: Enable the Google Analytics Data API
Important: Make sure you enable the Google Analytics Data API (v1beta), not the older “Google Analytics API” or “Google Analytics Reporting API”.
Step 3: Create a Service Account
Step 4: Generate a JSON Key
The JSON key file contains the credentials you'll need for the environment variables:
{
"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 GA4 Property
Step 6: Find Your GA4 Property ID
You need the numeric Property ID (not the Measurement ID like G-XXXXXXX):
Note: The Property ID is a numeric value like 123456789. Don't confuse it with the Measurement ID (like G-XXXXXXXXX) which is used for frontend tracking scripts.
Next step: Now set up the environment variables → using the values from your service account JSON key.