How to Connect Google Analytics to n8n
Tired of manually exporting reports from Google Analytics every week? Connecting Google Analytics 4 directly to n8n allows you to completely automate this process, saving you hours and letting you build custom data workflows that fit your exact needs. This article provides a complete step-by-step guide to setting up the connection, from generating your Google API credentials to building your first automated reporting workflow.
Why Connect Google Analytics to n8n?
Connecting GA4 to n8n is all about automation and integration. Instead of being stuck inside the Google Analytics interface, you can treat your website data as just another building block in a larger, automated system. This opens up a whole new world of possibilities for your marketing and sales reporting.
Here are a few quick examples of what you can do:
- Automated Slack/Email Reports: Automatically pull key metrics like users, sessions, and conversions every Monday morning and send a summary to your team's Slack channel or via email.
- Custom Data Warehousing: Archive your daily performance data in a Google Sheet, Airtable base, or a SQL database to build up a historical record you fully own and control.
- Performance Alerts: Create workflows that trigger alerts if your website traffic suddenly drops below a certain threshold or if a specific campaign sees a huge spike in goal completions.
- Enrich Other Data: Combine GA4 data with information from other tools. You could, for instance, pull conversion data from GA4 and match it with lead data from your CRM to see the full customer journey.
By automating the data collection, you free up your time to focus on what the numbers actually mean instead of just gathering them.
Before You Get Started: What You'll Need
To successfully link Google Analytics and n8n, make sure you have these three things ready:
- An active n8n account (either on n8n Cloud or a self-hosted instance).
- A Google Account with at least 'Viewer' permissions for the Google Analytics 4 property you want to connect.
- Familiarity with the Google Cloud Platform (GCP) console is helpful, but not required. We’ll walk through every click needed to get set up.
Step-by-Step: Connecting Google Analytics to n8n
The connection process involves two major phases: first, creating API credentials inside Google Cloud Platform so n8n has permission to access your data, and second, adding those credentials into n8n.
Step 1: Create a Service Account and API Credentials in GCP
For n8n to talk to Google Analytics, it needs its own set of keys. You'll create these using something called a "Service Account," which is like giving a robot its own user account with specific permissions. This is the most technical part of the process, but if you follow these steps exactly, you'll be done in a few minutes.
1. Create a New Google Cloud Project
First, head over to the Google Cloud Platform Console. If you've never used it before, you may have to agree to the terms of service.
- In the top left, click the project selector dropdown (it might say "Select a project").
- In the popup window, click "NEW PROJECT".
- Give your project a descriptive name, like "n8n Reporting Automation," and click "CREATE".
2. Enable the Google Analytics Data API
Now, you need to tell your new project that it's allowed to use the Google Analytics API.
- Make sure your new project is selected in the top dropdown menu.
- Use the search bar at the top of the console and type "Google Analytics Data API". Select it from the results.
- On the API page, click the blue "ENABLE" button. If it's already enabled, you're good to go.
3. Create a Service Account
Next, you’ll create the actual service account that n8n will be using to log in.
- In the search bar, search for "Service Accounts" and navigate to that page.
- Click "+ CREATE SERVICE ACCOUNT" at the top.
- Give the service account a name like "n8n-ga4-connector" and optionally a description.
- Click "CREATE AND CONTINUE".
- On the next page ("Grant this service account access to project"), you don't need to add any roles. Just click "CONTINUE".
- On the final page, you can leave the fields blank and just click "DONE".
You should now see your newly created service account in the list. Copy its email address (it will look something like n8n-ga4-connector@your-project-name.iam.gserviceaccount.com) – you'll need this in a moment.
4. Generate a JSON Key
This is the "password" for your service account that you'll give to n8n.
- On the Service Accounts page, click the three dots under the "Actions" column for the account you just created, and select "Manage keys".
- Click "ADD KEY" and then "Create new key".
- Choose "JSON" as the key type and click "CREATE".
A JSON file will immediately download to your computer. Treat this file like a password. Keep it safe and don't share it publicly. You'll need its contents for the next step.
5. Add the Service Account as a User in Google Analytics
One final, crucial step: you need to grant your new service account permission to view your Google Analytics data.
- Go to your Google Analytics account.
- Navigate to the correct property. Click the "Admin" gear icon in the bottom left.
- In the "Property" column, click on "Property Access Management".
- Click the blue "+" icon in the top right and select "Add users".
- In the "Email address" field, paste a special email that identifies your n8n account. You can find this in n8n on the workflow screen when you add a Google Analytics node. Your email address should look something like:
<workflow-ID-number>@users.n8n.cloud. - Make sure the "Notify new users by email" box is unchecked.
- Assign the "Viewer" role. You don't need to give it any more permissions than that.
- Click "Add" in the top right.
It can take a few minutes for these permissions to kick in, so now is a perfect time to grab a coffee before adding the credentials to n8n.
Step 2: Add Your New Credentials to n8n
With the hard part done, let's connect everything inside n8n.
- Open your n8n dashboard and go to the "Credentials" section from the left-hand navigation pane.
- Click "Add credential".
- Search for "Google Analytics" and select it.
- For "Authentication", select "Using Service Account".
- Open the JSON credential file you downloaded earlier with a text editor (like Notepad or VS Code). Copy the entire content of the file.
- Paste that content into the "Service Account JSON" field in n8n.
- Give your credential a nickname, like "My GA4 Service Account".
- Click "Save".
That's it! Your connection is now live and ready to be used in workflows.
Building Your First Automated GA4 Workflow in n8n
Let's make this useful. Here’s how you can build a simple workflow that pulls yesterday's user numbers and saves them to a Google Sheet every morning.
Workflow Goal: Get Daily Users & Sessions and Send to Google Sheets
Head to the n8n canvas and let's add three nodes.
Node 1: Schedule Trigger
Instead of running this workflow manually, you want it to execute automatically.
- Add a Schedule Trigger node to your canvas. This will replace the default Manual trigger.
- In the node settings, you can set the "Trigger Interval" to run every day, week, or hour. To get daily results, set it to "Every Day" and pick a time (e.g., 9 AM).
Node 2: The Google Analytics Node
- Click the "+" button to add a new node and search for "Google Analytics".
- In the "Credential for Google Analytics" dropdown, select the credentials you just created.
- For the "Resource," choose "Report".
- For the "Operation," choose "Get Many".
- Now, locate your GA4 Property ID. You can find this by going to your GA4 account, clicking
Admin > Property > Property Details. It’s a string of numbers. Enter this into the "Property ID" field. - Click "Add Metric" and search for "sessions". Click "Add Metric" again and add "totalUsers".
- Click "Add Dimension" and search for "date". This tells GA4 to organize the results by day.
- For "Start Date," you can enter an expression like
<code>{{ $now.minus({days: 1}).toFormat('yyyy-MM-dd') }}</code>to always pull yesterday's data. Do the same for "End Date."
Node 3: Google Sheets Node
- First, create a new Google Sheet with three columns: "Date," "Sessions," and "Total Users".
- Add a Google Sheets node to your workflow. You'll need to add credentials for it if you haven't already (using OAuth is easy for Sheets).
- For "Operation," choose "Append or Update".
- Enter your Spreadsheet's ID (the long string of characters in its URL).
- For "Sheet Name," choose the correct sheet.
- Now, map the values. In the "Columns" section:
Test the node and check your Google Sheet - the data should appear magically! When you're ready, toggle the activation switch on your workflow to "Active" in the top right corner. Your automated report is now live.
Final Thoughts
Connecting Google Analytics to n8n transforms your website data from a static dashboard into a dynamic, automated asset. By building custom workflows, you can feed insights directly into your team's daily routines, archive crucial data points, and combine web analytics with information from across your entire tech stack.
For days when you would rather not mess with API credentials and node-based builders, we built Graphed. Our platform connects to Google Analytics and your other marketing sources in a few clicks, letting you create dashboards and get analyses instantly, just by describing what you need in plain English - no JSON keys or workflow configuration required.
Related Articles
How to Enable Data Analysis in Excel
Enable Excel's hidden data analysis tools with our step-by-step guide. Uncover trends, make forecasts, and turn raw numbers into actionable insights today!
What SEO Tools Work with Google Analytics?
Discover which SEO tools integrate seamlessly with Google Analytics to provide a comprehensive view of your site's performance. Optimize your SEO strategy now!
Looker Studio vs Metabase: Which BI Tool Actually Fits Your Team?
Looker Studio and Metabase both help you turn raw data into dashboards, but they take completely different approaches. This guide breaks down where each tool fits, what they are good at, and which one matches your actual workflow.