Google Analytics 4 Connection
The Google Analytics 4 (GA4) connection integrates your GA4 property with OpsTower, giving agents access to web and app analytics data from Google’s measurement platform. This connection uses a GCP service account for authentication, which requires a JSON key file and your GA4 Property ID.
Prerequisites
Section titled “Prerequisites”- A Google Cloud Platform (GCP) project (existing or new)
- A Google Analytics 4 property with data
- Permission to create service accounts in GCP and manage access in GA4
Credentials Required
Section titled “Credentials Required”To set up a GA4 connection, you need two things:
- Service Account JSON Key — a credentials file from a GCP service account
- Property ID — the numeric identifier for your GA4 property
How to Create a GCP Service Account
Section titled “How to Create a GCP Service Account”- Go to Google Cloud Console.
- Select an existing project or create a new one.
- In the left sidebar, navigate to IAM & Admin > Service Accounts.
- Click Create Service Account.
- Enter a name for the service account (e.g., “opstower-analytics”).
- Optionally add a description (e.g., “Read-only access for OpsTower analytics”).
- Click Create and Continue.
- Grant the role Viewer on the project. This provides sufficient read access for analytics queries.
- Click Continue, then click Done.
- In the service accounts list, click the service account you just created.
- Go to the Keys tab.
- Click Add Key > Create new key.
- Select JSON as the key type and click Create.
- The JSON file will download automatically. Keep this file secure — you will paste its contents into OpsTower.
How to Grant GA4 Access to the Service Account
Section titled “How to Grant GA4 Access to the Service Account”The service account needs read access to your GA4 property. You grant this through the Google Analytics admin panel.
- Open Google Analytics.
- Go to Admin (gear icon in the bottom-left corner).
- In the Property column, click Property Access Management.
- Click the + button to add a new user.
- Enter the service account’s email address. You can find this in the JSON file under the
client_emailfield (it looks likename@project-id.iam.gserviceaccount.com). - Set the role to Viewer.
- Click Add.
The service account can now read data from this GA4 property.
How to Find Your Property ID
Section titled “How to Find Your Property ID”- In Google Analytics, go to Admin.
- In the Property column, click Property Settings.
- The Property ID is a numeric value displayed at the top of the settings page (e.g.,
123456789). - When entering the Property ID in OpsTower, you can use either the plain number (
123456789) or the full format (properties/123456789).
Setting Up the Connection in OpsTower
Section titled “Setting Up the Connection in OpsTower”- In OpsTower, navigate to Connections in the sidebar.
- Click Add Connection and select GA4.
- Paste the full contents of your Service Account JSON file into the credentials field.
- Enter your Property ID.
- Optionally, add a Custom Analytics Prompt with instructions for how the agent should analyze your GA4 data (max 2000 characters).
- Click Save to create the connection.
What Agents Can Do with GA4
Section titled “What Agents Can Do with GA4”Once connected and enabled on an agent, the agent can:
- Query page views, sessions, and user metrics over time ranges
- Analyze traffic sources and acquisition channels
- Review event data and conversions
- Generate scheduled analytics reports with trend analysis and anomaly detection
GA4 connections are used in two primary contexts:
- Scheduled Reports — automated analytics summaries delivered on a recurring schedule, covering key metrics, period-over-period comparisons, and detected anomalies.
- Agent Chat via MCP — real-time queries during conversations with your agents, where the agent calls GA4 through the Model Context Protocol to fetch and analyze data on demand.
Troubleshooting
Section titled “Troubleshooting”- Permission denied errors: Verify that the service account email has been added to the GA4 property with Viewer access. Also confirm that the JSON key file has not been revoked in GCP.
- No data returned: Double-check that the Property ID is correct and that the property has recent data. Ensure you are using a GA4 property, not a Universal Analytics property.
- Invalid JSON key: Make sure you pasted the entire contents of the JSON file, including the opening and closing braces. Do not modify the file contents.
- Wrong project: If you have multiple GCP projects, ensure the service account belongs to a project where the necessary APIs are enabled. The Google Analytics Data API should be enabled in the GCP project.