## Introduction
In today’s data-driven marketing environment, timely access to social media metrics is crucial for data & analytics teams that support growth and marketing departments. Manually collecting performance data from multiple social platforms can be tedious, error-prone, and inefficient. Automating the daily fetching of social media metrics saves time, ensures accuracy, and enables faster decision-making.
This guide provides a step-by-step tutorial for building an automation workflow using n8n — a powerful open-source workflow automation tool — to extract social media metrics daily from platforms like Facebook, Instagram, and Twitter, and store the data in Google Sheets for analysis and reporting.
## Problem and Beneficiaries
**Problem:** Marketing and analytics teams spend hours manually logging into each social media account, exporting data, and consolidating metrics into spreadsheets.
**Who benefits:**
– Data & Analytics teams gain reliable, on-time datasets.
– Marketing teams receive near real-time insights.
– Operations teams save manual labor and reduce errors.
## Tools and Services Integrated
– **n8n:** Core automation platform.
– **Facebook Graph API:** To fetch Facebook and Instagram metrics.
– **Twitter API v2:** To retrieve Twitter metrics.
– **Google Sheets:** Centralized repository to store daily metrics.
– **Scheduler node in n8n:** To run the workflow daily automatically.
## Workflow Overview
The automation workflow triggers every day at a specified time, connects to each social media API to retrieve relevant metrics, processes and cleans the data, then appends or updates records in a Google Sheet. Errors are handled gracefully with retry mechanisms and notifications for failures.
## Detailed Step-by-Step Tutorial
### Prerequisites
– An n8n instance set up (cloud-hosted or self-hosted).
– API credentials:
– Facebook Developer App with access tokens for Facebook & Instagram.
– Twitter Developer Account with Bearer Token.
– Google Service Account or OAuth credentials with Sheets API enabled.
– A Google Sheet created with headers for date, platform, metric type, and values.
—
### Step 1: Configure the Trigger Node (Scheduler)
– Add a **Scheduler** node.
– Set it to run **daily** at your preferred time, e.g., 7:00 AM UTC.
– This node initiates your workflow automatically without manual intervention.
—
### Step 2: Fetch Facebook & Instagram Metrics
– Add an **HTTP Request** node to call the Facebook Graph API.
– Configure the node:
– Method: GET
– URL: `https://graph.facebook.com/v15.0/me/insights`
– Query params: `metric=page_impressions,page_engaged_users,instagram_impressions,instagram_profile_views&access_token=YOUR_FACEBOOK_ACCESS_TOKEN&since=yesterday_timestamp&until=today_timestamp`
– Extract the required metrics from the JSON response.
**Tip:** Use n8n’s **Set** and **Function** nodes to parse and format the data into rows for Google Sheets.
—
### Step 3: Fetch Twitter Metrics
– Add another **HTTP Request** node.
– Set it up to call Twitter API v2:
– Endpoint example: `https://api.twitter.com/2/users/{user_id}/tweets?start_time=yesterday_iso_datetime&end_time=today_iso_datetime&tweet.fields=public_metrics`
– Authorization header: `Bearer YOUR_TWITTER_BEARER_TOKEN`
– Parse the JSON response to extract metrics such as impressions, retweets, likes for tweets from the previous day.
**Tip:** Use JavaScript within n8n’s **Function** node to aggregate totals if necessary.
—
### Step 4: Format Data for Google Sheets
– Use a **Function** or **Set** node to convert all metrics from Facebook and Twitter into a unified array of objects.
– Example format:
“`json
[
{ “date”: “2024-06-01”, “platform”: “Facebook”, “metric”: “page_impressions”, “value”: 12345 },
{ “date”: “2024-06-01”, “platform”: “Twitter”, “metric”: “likes”, “value”: 678 }
]
“`
– This standardized format makes it easy for downstream nodes to write data.
—
### Step 5: Append Data to Google Sheets
– Add the **Google Sheets** node.
– Set the operation to **Append**.
– Select your spreadsheet and worksheet.
– Map the fields from the previous step to the correct columns.
—
### Step 6: Error Handling & Notifications (Optional but Recommended)
– Add a **IF** node to check if API responses contain errors.
– Implement retry logic by connecting error outputs to a **Wait** node and retry.
– For persistent failures, connect to an **Email** or **Slack** node to notify your team.
—
## Common Errors and Troubleshooting
– **API Rate Limits:** Social media APIs often enforce rate limits. Use n8n’s **Wait** node to pause between requests if you approach limits.
– **Invalid Credentials:** Ensure tokens are up-to-date and properly scoped.
– **Time Zone Issues:** Align API request time parameters with UTC or the platform’s preferred format.
– **Data Schema Changes:** Social platforms update APIs; monitor changelogs and update nodes accordingly.
## Scaling and Adaptations
– **Add More Platforms:** Extend workflow to LinkedIn, TikTok, etc., by adding corresponding HTTP nodes.
– **More Granular Metrics:** Fetch hourly or post-level data by adjusting API calls.
– **Database Integration:** Instead of Sheets, use SQL or NoSQL databases for large-scale analytics.
– **Dashboard Automation:** Combine with visualization tools by auto-updating BI dashboards.
## Summary
Automating daily social media metric collection with n8n boosts operational efficiency for data & analytics teams by eliminating manual data gathering. This tutorial outlined how to use n8n’s scheduler, HTTP Request nodes, and Google Sheets integration to build a robust workflow connecting Facebook, Instagram, and Twitter APIs. Emphasizing error handling and scalable design prepares your automation for production readiness and future growth.
## Bonus Tip
Leverage n8n’s **Credentials** management to securely store API tokens and rotate them periodically using an automated secrets management tool. This enhances security without complicating your workflow.