Home » n8n» Connect Google Analytics to n8n with Docker and OAuth2

Connect Google Analytics to n8n?

This tutorial shows how to Connect Google Analytics to n8n using OAuth2 and Docker for a secure workflow. Yes, you can connect Google Analytics to n8n by enabling the Google Analytics API, creating OAuth 2.0 credentials in Google Cloud, and adding those credentials inside n8n’s OAuth2 credential to authorize the Google Analytics node.

What You Need

  • A Google account with access to Google Cloud Console.
  • An n8n instance running in Docker on a reachable host (localhost or a server).
  • Basic command-line access and a browser to complete the OAuth flow.
  • Familiarity with enabling APIs in Google Cloud and creating OAuth credentials.

How to Connect Google Analytics to n8n

Follow the numbered steps below. Each step gives commands or UI actions. Keep values like PROJECT_ID and REDIRECT_URI ready.

Step 1: Create a Google Cloud project and enable the API

  1. In Google Cloud Console create or select a project.
  2. Enable the Google Analytics API (Analytics Data API or Core Reporting API depending on your needs).
# Example using gcloud to enable the Analytics API
gcloud projects create PROJECT_ID --name="n8n-analytics"
gcloud config set project PROJECT_ID
gcloud services enable analytics.googleapis.com

Step 2: Create OAuth 2.0 credentials

  1. Open APIs & Services → OAuth consent screen. Choose External for testing or Internal for GSuite only. Fill app name and support email.
  2. Under Credentials, choose Create Credentials → OAuth client ID → Web application.
  3. Add an authorized redirect URI. For a local n8n instance use:
http://localhost:5678/rest/oauth2-credential/callback

After creation copy the Client ID and Client Secret. You will paste these into n8n.

Step 3: Run n8n with Docker

Start n8n so the OAuth callback can return to it. Use environment variables for security in production.

# Simple local Docker run for testing
docker run -it --rm -p 5678:5678 \
  -e N8N_HOST="localhost" \
  -e N8N_PORT=5678 \
  -e N8N_PROTOCOL="http" \
  -v ~/.n8n:/home/node/.n8n \
  n8nio/n8n:latest

If you run behind a domain and HTTPS, set N8N_HOST and N8N_PROTOCOL accordingly and use that domain in redirect URIs.

Step 4: Configure Google OAuth2 credential in n8n

  1. Open n8n in your browser at http://localhost:5678.
  2. Go to Credentials → New Credential → OAuth2 API (Google).
  3. Enter the Client ID and Client Secret from Google Cloud.
  4. Set the Access Token URL and Auth URL if prompted (n8n pre-fills these for Google). Leave scope to include analytics scopes like https://www.googleapis.com/auth/analytics.readonly.
  5. Click Authenticate and complete the Google OAuth consent flow.

Step 5: Test the Google Analytics node

  1. Create a workflow and add the Google Analytics node.
  2. Select the credential you created and choose a dimension or metric to fetch.
  3. Run the node to verify data returns.

Update

Refresh tokens can expire. If the node shows authentication errors, re-open the credential and click Authenticate again. For large deployments, consider renewing credentials in a secure CI/CD process. Keep n8n and Docker images updated:

# Update n8n Docker image
docker pull n8nio/n8n:latest
docker stop 
docker run ... n8nio/n8n:latest

Security

  • Use HTTPS and a proper domain for production redirect URIs.
  • Never commit Client ID or Client Secret into source control.
  • Store secrets as environment variables or in a secrets manager.
  • Restrict OAuth consent screen and OAuth client to required users if possible.
  • Limit API scopes to the minimum required, for example analytics.readonly.

Done

You now have Google Analytics connected to n8n. Use the Google Analytics node in workflows to fetch metrics or trigger automations. If you need more data types, enable the matching Google Analytics API and adjust scopes.

Neil
Written by Neil

Neil is a true n8n geek who lives and breathes workflow automation. He dives deep into nodes, triggers, webhooks, custom logic, and self-hosting setups, sharing everything he learns about n8n on AutomationCompare.com. As part of a broader team of automation specialists, Neil focuses purely on mastering n8n and helping others unlock its full potential.

Keep Reading

Scroll to Top