Skip to main content

Connect Google Analytics with ShedBoxAI

Pull web analytics data from Google Analytics 4 and build traffic analysis pipelines.

Quick Start

data_sources:
analytics:
type: rest
url: "https://analyticsdata.googleapis.com/v1beta/properties/${GA_PROPERTY_ID}:runReport"
method: POST
headers:
Authorization: "Bearer ${GOOGLE_ACCESS_TOKEN}"
Content-Type: "application/json"
options:
json:
dateRanges:
- startDate: "30daysAgo"
endDate: "today"
dimensions:
- name: "date"
metrics:
- name: "sessions"
- name: "activeUsers"

output:
type: file
path: "analytics.json"
format: json

Authentication

Use OAuth 2.0 for Google APIs:

export GOOGLE_ACCESS_TOKEN="your-oauth-token"
export GA_PROPERTY_ID="your-property-id"

Common Pipelines

Traffic by Source

data_sources:
traffic:
type: rest
url: "https://analyticsdata.googleapis.com/v1beta/properties/${GA_PROPERTY_ID}:runReport"
method: POST
headers:
Authorization: "Bearer ${GOOGLE_ACCESS_TOKEN}"
Content-Type: "application/json"
options:
json:
dateRanges:
- startDate: "30daysAgo"
endDate: "today"
dimensions:
- name: "sessionSource"
metrics:
- name: "sessions"
- name: "conversions"

processing:
content_summarization:
traffic:
method: "statistical"
fields: ["sessions", "conversions"]
summarize: ["sum", "mean", "max"]

output:
type: file
path: "traffic_by_source.json"
format: json

Page Performance

data_sources:
pages:
type: rest
url: "https://analyticsdata.googleapis.com/v1beta/properties/${GA_PROPERTY_ID}:runReport"
method: POST
headers:
Authorization: "Bearer ${GOOGLE_ACCESS_TOKEN}"
Content-Type: "application/json"
options:
json:
dateRanges:
- startDate: "7daysAgo"
endDate: "today"
dimensions:
- name: "pagePath"
metrics:
- name: "screenPageViews"
- name: "averageSessionDuration"
limit: 20

output:
type: file
path: "page_performance.json"
format: json

Analytics Insights with AI

data_sources:
traffic:
type: rest
url: "https://analyticsdata.googleapis.com/v1beta/properties/${GA_PROPERTY_ID}:runReport"
method: POST
headers:
Authorization: "Bearer ${GOOGLE_ACCESS_TOKEN}"
Content-Type: "application/json"
options:
json:
dateRanges:
- startDate: "30daysAgo"
endDate: "today"
dimensions:
- name: "date"
- name: "sessionSource"
metrics:
- name: "sessions"
- name: "conversions"

ai_interface:
model:
type: rest
url: "https://api.anthropic.com/v1/messages"
method: POST
headers:
x-api-key: "${ANTHROPIC_API_KEY}"
Content-Type: "application/json"
options:
model: "claude-sonnet-4-20250514"

prompts:
analyze:
system: "You are a web analytics expert."
user_template: |
Analyze this traffic data and provide insights:

{{ traffic | tojson }}

Identify traffic trends and optimization opportunities.

output:
type: file
path: "analytics_insights.md"
format: json