Blog
guide

How to Connect Google Analytics to OpenAI Codex Using Sequel

Musthaq Ahamad
Musthaq Ahamad
How to Connect Google Analytics to OpenAI Codex Using Sequel

GA4 is where all your traffic and behavior data lives. The OpenAI Codex CLI brings AI assistance to your terminal. Connect them through Sequel's MCP server and you can ask questions about your traffic and user behavior from the same terminal where you write and debug code. No exporting reports, no switching to a browser.

What You'll Accomplish

Once set up, you can launch Codex and ask:

  • "How many sessions did we have last week compared to the week before?"
  • "Which pages have the highest bounce rate this month?"
  • "What are the top 5 traffic sources by new users today?"

Prerequisites

Step 1: Connect Google Analytics 4 to Sequel

Sign in to sequel.sh and click Data Sources in the left sidebar.

Sequel Data Sources page

Click New Connection. On the "Choose a connector" page, select Google Analytics 4.

Choose a connector

Enter a Connection Name, a label to identify this property, e.g. sequel.sh Analytics.

Then click Connect with Google.

Google Analytics 4 connection form

A Google OAuth window will open. Sign in with the Google account that has access to your GA4 property and grant Sequel the requested permissions. You'll be redirected back to Sequel with the connection saved.

Step 2: Get Your Sequel API Key

Click Settings in the left sidebar, then select API Keys from the settings navigation.

Sequel API Keys page

Click New key, name it codex-ga, and copy the key (starts with sql_).

Step 3: Configure Codex CLI to Use Sequel MCP

Set your API key as an environment variable. Add to ~/.zshrc or ~/.bashrc:

export SEQUEL_API_KEY="sql_your_api_key"

Reload your shell:

source ~/.zshrc

Add Sequel to ~/.codex/config.toml. Create the file if it doesn't exist:

[mcp_servers.sequel]
url = "https://api.sequel.sh/mcp"
bearer_token_env_var = "SEQUEL_API_KEY"

Save the file. The next Codex session will load the Sequel MCP server automatically.

Step 4: Query Your Google Analytics Data

codex

Then ask:

How many users visited the site last week?
What were the top 10 landing pages by sessions this month?
Show me the traffic breakdown by device type for the past 30 days.

What You Can Do Now

  • Weekly performance checks: ask "How does this week's traffic compare to last week?" without opening the GA4 dashboard
  • Content analysis: ask "Which blog posts drove the most engaged sessions this month?"
  • Campaign reporting: ask "What's the conversion rate for users who came from paid search?"
  • Device and geo breakdown: ask "What percentage of our users are on mobile?"
  • Data-grounded feature development: describe the metric you need, ask Codex to write the code, with real GA4 data to validate against

Try Sequel

Meet your always-on data analyst.

An AI data analyst that connects to all your data and answers questions with reports and visualizations. Free for up to 3 seats - no credit card required.

Get started free

Frequently asked questions

Which Google Analytics version does Sequel support?

Sequel supports Google Analytics 4 (GA4). Universal Analytics (UA) properties were sunset in 2023 and are not supported.

What Google permissions does Sequel request?

Sequel requests read-only access to your Google Analytics 4 data via the Google Analytics Data API. You can revoke this at any time from your Google account settings under Security, then Third-party apps.

Does Sequel store my GA4 data?

No. Sequel queries the Google Analytics API when you ask a question and returns the result in your conversation. No data is cached or retained beyond the duration of the tool call.

Do I need a Google Analytics admin role to connect?

No. Viewer-level access to the GA4 property is sufficient. Sequel only reads data.

Can I connect multiple GA4 properties?

Yes. Add multiple Google Analytics data sources in Sequel, each with a distinct Connection Name, and target them by name in your queries.

Why use bearer_token_env_var for the API key?

Storing the API key in an environment variable keeps it out of config files that might be committed to source control or shared with others.

Written by

Musthaq Ahamad
Musthaq Ahamad

Co-founder and CEO of Sequel. Previously built developer tools and data infrastructure. Passionate about making data accessible for everyone.