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
-
Go to the Google Cloud Console
-
Create a new project or select an existing one
-
Enable the following APIs:
- Google Analytics Admin API
- Google Analytics Data API
-
Go to APIs & Services > Credentials
-
Click Create Credentials > OAuth 2.0 Client ID
-
Configure the OAuth consent screen if prompted
-
Select Application type: Desktop app or Web application
-
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:
- Visit https://developers.google.com/oauthplayground
- Click the gear icon ⚙️ and check "Use your own OAuth credentials"
- Enter your Client ID and Client Secret
- Select the required scopes in Step 1
- Authorize APIs
- Exchange authorization code for tokens
- 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 tokenaccount_filter(optional): Array of account IDs to discover. Leave empty to discover all accessible accounts.include_audiences(optional, default: true): Whether to discover audience entitiesinclude_conversions(optional, default: true): Whether to discover conversion event entitiesinclude_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 IDdisplay_name: Account display name
Specs:
account_id: Numeric account IDresource_name: Full resource name (accounts/123)display_name: Account display nameregion_code: Account regioncreate_time: Creation timestampupdate_time: Last update timestamp
Represents a GA4 property within an account.
Labels:
property_id: Numeric property IDaccount_id: Parent account IDdisplay_name: Property display nameproperty_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 IDproperty_id: Parent property IDtype: 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 IDproperty_id: Parent property IDdisplay_name: Audience display name
Relationships:
HAS_AUDIENCE: Property → Audience
Represents a conversion event configuration.
Labels:
event_name: Event name marked as conversionproperty_id: Parent property ID
Relationships:
HAS_CONVERSION: Property → Conversion
Represents a custom dimension definition.
Labels:
dimension_id: Custom dimension IDproperty_id: Parent property IDparameter_name: Parameter namedisplay_name: Display name
Relationships:
HAS_CUSTOM_DIMENSION: Property → CustomDimension
Represents a custom metric definition.
Labels:
metric_id: Custom metric IDproperty_id: Parent property IDparameter_name: Parameter namedisplay_name: Display namemeasurement_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:
-
Cache discovery results when possible
-
Use batch operations when available
-
Implement exponential backoff for retries
-
Monitor your API quota in Google Cloud Console
-
Store OAuth tokens securely using the
x-sixdegree: {widget: "secret"}configuration -
Use least-privilege access - request only required scopes
-
Rotate OAuth tokens regularly
-
Consider using service account credentials for production deployments
For issues, questions, or feature requests:
- GitHub Issues: https://github.com/sixdegree-ai/molecules/issues
- Documentation: https://docs.sixdegree.ai/molecules/googleanalytics
- Email: support@sixdegree.ai