Skip to content

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.

  • 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

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
  1. Go to Google Cloud Console.
  2. Select an existing project or create a new one.
  3. In the left sidebar, navigate to IAM & Admin > Service Accounts.
  4. Click Create Service Account.
  5. Enter a name for the service account (e.g., “opstower-analytics”).
  6. Optionally add a description (e.g., “Read-only access for OpsTower analytics”).
  7. Click Create and Continue.
  8. Grant the role Viewer on the project. This provides sufficient read access for analytics queries.
  9. Click Continue, then click Done.
  10. In the service accounts list, click the service account you just created.
  11. Go to the Keys tab.
  12. Click Add Key > Create new key.
  13. Select JSON as the key type and click Create.
  14. 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.

  1. Open Google Analytics.
  2. Go to Admin (gear icon in the bottom-left corner).
  3. In the Property column, click Property Access Management.
  4. Click the + button to add a new user.
  5. Enter the service account’s email address. You can find this in the JSON file under the client_email field (it looks like name@project-id.iam.gserviceaccount.com).
  6. Set the role to Viewer.
  7. Click Add.

The service account can now read data from this GA4 property.

  1. In Google Analytics, go to Admin.
  2. In the Property column, click Property Settings.
  3. The Property ID is a numeric value displayed at the top of the settings page (e.g., 123456789).
  4. When entering the Property ID in OpsTower, you can use either the plain number (123456789) or the full format (properties/123456789).
  1. In OpsTower, navigate to Connections in the sidebar.
  2. Click Add Connection and select GA4.
  3. Paste the full contents of your Service Account JSON file into the credentials field.
  4. Enter your Property ID.
  5. Optionally, add a Custom Analytics Prompt with instructions for how the agent should analyze your GA4 data (max 2000 characters).
  6. Click Save to create the connection.

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.
  • 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.