You can automate a weekly marketing report in n8n by scheduling a workflow that queries the Google Analytics Data API v1 for a rolling 7-day window, transforms the response into a flat array, and appends the results to a Google Sheets document. This removes manual exports and gives your team a consistent, timestamped record of performance.
Prerequisites
- An active n8n instance (cloud or self-hosted).
- A Google Cloud project with the Analytics Data API v1 enabled.
- Your GA4 property ID.
- Google Sheets credentials configured inside n8n.
- A target spreadsheet with a header row that matches the fields you plan to write.
Step-by-Step Workflow
1. Trigger the Workflow Weekly
Add the
Schedule Trigger node and set it to run on a weekly cadence. For example, configure a cron expression to execute every Monday at 09:00 in your local timezone. Explicitly set the timezone in the node or instance settings to avoid off-by-one date ranges.
2. Query GA4 for the Last Seven Days
Use an HTTP Request node to call the
Google Analytics Data API v1. In the request body, include your GA4 property ID and define a rolling date range such as
7daysAgo to
yesterday. Select dimensions like
Session source and
Session medium, and metrics like
Sessions,
Total users, and
Key events.
3. Transform the API Response
The API returns nested rows. Convert each row into a flat object whose keys align with your sheet headers. Before passing data downstream, validate that the array is not empty to prevent blank inserts.
4. Append Results to Google Sheets
Add the
Google Sheets node, choose the
Append operation, and supply the Spreadsheet ID, sheet name, and mapped data array. The node writes each object as a new row. If your object keys match the sheet headers left-to-right, the data lands in the correct columns.
Fictional Data Example
Suppose your spreadsheet uses the headers:
Week,
Source,
Medium,
Sessions,
Users,
Conversions. After transforming the API response, n8n produces an object like this:
{
"Week": "2024-W03",
"Source": "google",
"Medium": "organic",
"Sessions": 15420,
"Users": 12300,
"Conversions": 340
}
The Google Sheets node appends this as a single row. If the API returns multiple source/medium combinations, each becomes its own row in the same execution.
Edge Cases and How to Handle Them
- Expired OAuth credentials. If the workflow halts with an authentication error, reauthorize the Google credential in n8n and confirm the service account or OAuth client still has access to the spreadsheet and GA4 property.
- Column mismatch. When object keys do not align with the sheet header row, data is written to incorrect columns or the node returns a validation error. Compare your transformed keys against the header row before the append step.
- Timezone misconfiguration. An incorrect timezone can shift the execution time so the date range captures the wrong week. Set the timezone explicitly in the Schedule Trigger or in your n8n instance settings.
- Empty result set. If the Analytics Data API returns zero rows for the selected period, the append operation may insert blank rows. Route the data through an IF node that checks for non-empty rows before sending them to Google Sheets.
FAQ
Can I update existing rows instead of appending?
Yes. The
Google Sheets node supports read, update, and clear operations, but you must specify the exact range or row number.
Do I need a service account or OAuth2 user consent?
Either credential type works in n8n. The important part is that the authenticated identity has viewer access to the GA4 property and editor access to the target spreadsheet.
Can I run this daily instead of weekly?
Yes. Change the Schedule Trigger from a weekly interval to a daily interval or adjust the cron expression.
Related Automation Patterns
If you are expanding your automation stack, the
n8n lead qualification workflow shows how to route and score inbound leads before they reach your CRM. For more hands-on guides, see the latest work at
John Steven Lie.