Google Analytics
Give agents tools to run standard, pivot, realtime, and batch reports, read report metadata, and manage properties, data streams, and conversion events in Google Analytics through Mastra Connect. Each tool call goes through the Mastra platform, which adds the connection's credential. Your application never stores Google Analytics credentials.
ConnectDirect link to Connect
Before you start, complete the Connect setup to install @mastra/connect and configure your platform project.
Connect an accountDirect link to Connect an account
Run this command from the directory that contains your .env file:
mastra connect add google-analytics
The CLI guides you through Google Analytics' authorization and waits until the connection is active.
Add tools to an agentDirect link to Add tools to an agent
Pass tools() to the agent and select the google-analytics provider:
import { Agent } from '@mastra/core/agent'
import { tools } from '@mastra/connect'
export const googleAnalyticsAgent = new Agent({
id: 'google-analytics-agent',
name: 'Google Analytics agent',
instructions:
'You help people run standard, pivot, realtime, and batch reports, read report metadata, and manage properties, data streams, and conversion events in Google Analytics.',
model: 'openai/gpt-6-luna',
tools: tools({ providers: ['google-analytics'] }),
})
The agent gets 11 Google Analytics tools, with keys such as google_analytics_archive_conversion_event. See Google Analytics tools for the full list, and the tools() parameters to restrict tools or require approval before a call runs.