Skip to main content
Google Analytics

Google Analytics

The Google Analytics molecule for SixDegree provides comprehensive discovery and management capabilities for Google Analytics 4 (GA4) properties.

  • Account Discovery: Automatically discover all accessible GA4 accounts

  • Property Discovery: Discover GA4 properties within accounts

  • Data Streams: Discover web, iOS, and Android app data streams

  • Audiences: Discover user audiences configured for targeting

  • Conversions: Discover conversion events and their configurations

  • Custom Definitions: Discover custom dimensions and metrics

  • Admin Operations: List accounts, properties, data streams; create data streams

  • Audience Management: List, create, update, and archive audiences

  • Conversion Management: List, create, and delete conversion events

  • Analytics Reporting: Run standard and real-time reports, get metadata

  • Custom Definitions: List and create custom dimensions and metrics

  1. Go to the Google Cloud Console

  2. Create a new project or select an existing one

  3. Enable the following APIs:

    • Google Analytics Admin API
    • Google Analytics Data API
  4. Go to APIs & Services > Credentials

  5. Click Create Credentials > OAuth 2.0 Client ID

  6. Configure the OAuth consent screen if prompted

  7. Select Application type: Desktop app or Web application

  8. Note the Client ID and Client Secret

You need to obtain an OAuth 2.0 access token with the following scopes:

https://www.googleapis.com/auth/analytics.readonly
https://www.googleapis.com/auth/analytics.edit

Using Google OAuth 2.0 Playground:

  1. Visit https://developers.google.com/oauthplayground
  2. Click the gear icon ⚙️ and check "Use your own OAuth credentials"
  3. Enter your Client ID and Client Secret
  4. Select the required scopes in Step 1
  5. Authorize APIs
  6. Exchange authorization code for tokens
  7. Copy the Access Token

Note: Access tokens expire after 1 hour. For production use, implement token refresh or use service account credentials.

discovery:
enabled: true
settings:
oauth_token: "ya29.a0AfH6SMB..." # Required: OAuth 2.0 access token
account_filter: [] # Optional: Specific account IDs to discover
include_audiences: true # Optional: Include audience entities
include_conversions: true # Optional: Include conversion entities
include_custom_definitions: false # Optional: Include custom dimensions/metrics

Configuration Options:

  • oauth_token (required): Google OAuth 2.0 access token
  • account_filter (optional): Array of account IDs to discover. Leave empty to discover all accessible accounts.
  • include_audiences (optional, default: true): Whether to discover audience entities
  • include_conversions (optional, default: true): Whether to discover conversion event entities
  • include_custom_definitions (optional, default: false): Whether to discover custom dimensions and metrics
mcp:
enabled: true
settings:
oauth_token: "ya29.a0AfH6SMB..." # Required: OAuth 2.0 access token
default_property_id: "123456789" # Optional: Default property ID for MCP operations

Represents a Google Analytics account (top-level container).

Labels:

  • account_id: Numeric account ID
  • display_name: Account display name

Specs:

  • account_id: Numeric account ID
  • resource_name: Full resource name (accounts/123)
  • display_name: Account display name
  • region_code: Account region
  • create_time: Creation timestamp
  • update_time: Last update timestamp

Represents a GA4 property within an account.

Labels:

  • property_id: Numeric property ID
  • account_id: Parent account ID
  • display_name: Property display name
  • property_type: Property type (PROPERTY_TYPE_ORDINARY, etc.)

Relationships:

  • HAS_PROPERTY: Account → Property

Represents a data stream (web, iOS, or Android app).

Labels:

  • stream_id: Data stream ID
  • property_id: Parent property ID
  • type: Stream type (WEB_DATA_STREAM, IOS_APP_DATA_STREAM, ANDROID_APP_DATA_STREAM)

Relationships:

  • HAS_STREAM: Property → DataStream

Represents a user audience for targeting and analysis.

Labels:

  • audience_id: Audience ID
  • property_id: Parent property ID
  • display_name: Audience display name

Relationships:

  • HAS_AUDIENCE: Property → Audience

Represents a conversion event configuration.

Labels:

  • event_name: Event name marked as conversion
  • property_id: Parent property ID

Relationships:

  • HAS_CONVERSION: Property → Conversion

Represents a custom dimension definition.

Labels:

  • dimension_id: Custom dimension ID
  • property_id: Parent property ID
  • parameter_name: Parameter name
  • display_name: Display name

Relationships:

  • HAS_CUSTOM_DIMENSION: Property → CustomDimension

Represents a custom metric definition.

Labels:

  • metric_id: Custom metric ID
  • property_id: Parent property ID
  • parameter_name: Parameter name
  • display_name: Display name
  • measurement_unit: Unit of measurement

Relationships:

  • HAS_CUSTOM_METRIC: Property → CustomMetric

List all Google Analytics accounts accessible with current credentials.

Input: None

Output:

{
"accounts": [
{
"name": "accounts/123456",
"account_id": "123456",
"display_name": "My Company",
"region_code": "US",
"create_time": "2020-01-15T10:30:00Z"
}
],
"count": 1
}

List all GA4 properties for a specific account.

Input:

{
"account_id": "123456" // or "accounts/123456"
}

Get detailed information about a specific GA4 property.

Input:

{
"property_id": "987654321" // or "properties/987654321"
}

List all data streams (web, iOS, Android) for a GA4 property.

Input:

{
"property_id": "987654321"
}

Create a new web data stream for a GA4 property.

Input:

{
"property_id": "987654321",
"display_name": "My Website",
"default_uri": "https://example.com"
}

List all audiences for a GA4 property.

Create a new audience for a GA4 property.

Input:

{
"property_id": "987654321",
"display_name": "High Value Users",
"description": "Users with total revenue > $100",
"membership_duration_days": 30
}

Update an existing audience.

Archive an audience (soft delete).

List all conversion events for a GA4 property.

Mark an event as a conversion event.

Input:

{
"property_id": "987654321",
"event_name": "purchase"
}

Remove conversion marking from an event.

Run an analytics report with dimensions and metrics.

Input:

{
"property_id": "987654321",
"date_ranges": [
{"start_date": "7daysAgo", "end_date": "today"}
],
"dimensions": [
{"name": "country"},
{"name": "city"}
],
"metrics": [
{"name": "activeUsers"},
{"name": "sessions"}
],
"limit": 10
}

Output:

{
"rows": [
{
"country": "United States",
"city": "New York",
"activeUsers": "1234",
"sessions": "5678"
}
],
"row_count": 10,
"total_rows": 100,
"property_id": "987654321"
}

Run a real-time analytics report.

Input:

{
"property_id": "987654321",
"dimensions": [{"name": "country"}],
"metrics": [{"name": "activeUsers"}],
"limit": 10
}

Get available dimensions and metrics for a property.

Input:

{
"property_id": "987654321"
}

Output:

{
"dimensions": [
{
"api_name": "country",
"ui_name": "Country",
"description": "The country from which the user activity originated",
"category": "Geography"
}
],
"metrics": [
{
"api_name": "activeUsers",
"ui_name": "Active Users",
"description": "The number of distinct users who visited your site or app",
"type": "TYPE_INTEGER",
"category": "User"
}
]
}

List recent events for a property.

Input:

{
"property_id": "987654321",
"limit": 20
}

List all custom dimensions for a property.

Create a new custom dimension.

Input:

{
"property_id": "987654321",
"parameter_name": "user_tier",
"display_name": "User Tier",
"description": "Subscription tier of the user",
"scope": "USER" // or "EVENT"
}

List all custom metrics for a property.

Create a new custom metric.

Input:

{
"property_id": "987654321",
"parameter_name": "cart_value",
"display_name": "Cart Value",
"description": "Total value of items in cart",
"measurement_unit": "CURRENCY",
"scope": "EVENT"
}

Error: "failed to create Analytics Admin service: oauth2: cannot fetch token"

Solution: Verify your OAuth token is valid and has not expired. Access tokens expire after 1 hour.

Error: "User does not have sufficient permissions for this account"

Solution: Ensure the Google account associated with the OAuth token has appropriate permissions in Google Analytics. Required roles:

  • Viewer (for read-only operations)
  • Editor or Administrator (for write operations)

Google Analytics APIs have quota limits:

  • Admin API: 500 requests per day per project
  • Data API: 25,000 requests per day per property

Solution: Implement rate limiting and caching. Use the account_filter configuration to limit discovery scope.

The molecule accepts property IDs in two formats:

  • Numeric: "987654321"
  • Full resource name: "properties/987654321"

Both formats are automatically normalized.

The Google Analytics APIs have rate limits. Best practices:

For issues, questions, or feature requests: