AutomationFlowsAI & RAG › Generate Weekly Twitter & Facebook Performance Reports with Gpt-4o Analysis

Generate Weekly Twitter & Facebook Performance Reports with Gpt-4o Analysis

ByRahul Joshi @rahul08 on n8n.io

Automate your weekly cross-platform social media analytics workflow with AI-powered insights. 📊🤖 This system retrieves real-time Twitter (X) and Facebook data, validates and merges the metrics, formats them via custom JavaScript, generates a visual HTML summary with GPT-4o,…

Event trigger★★★★☆ complexityAI-powered22 nodesLm Chat Azure Open AiGmailHTTP RequestFacebook Graph ApiGoogle SheetsAgent
AI & RAG Trigger: Event Nodes: 22 Complexity: ★★★★☆ AI nodes: yes Added:

This workflow corresponds to n8n.io template #10556 — we link there as the canonical source.

This workflow follows the Agent → Facebookgraphapi recipe pattern — see all workflows that pair these two integrations.

The workflow JSON

Copy or download the full n8n JSON below. Paste it into a new n8n workflow, add your credentials, activate. Full import guide →

Download .json
{
  "id": "vZEJiFN02HkHE0m6",
  "name": "Top Content Type Analyzer",
  "tags": [],
  "nodes": [
    {
      "id": "fc16dc5b-5176-4ec8-960f-f3d8018a731a",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -896,
        0
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "635c5b6e-06cd-4a8b-8085-a5113e1e3ba0",
      "name": "Configure GPT-4o Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        1216,
        240
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "f853763c-7fed-4340-96ff-e1025458cae2",
      "name": " Send Email Summary to Marketing Team",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1648,
        0
      ],
      "parameters": {
        "sendTo": "=newscctv22@gmail.com",
        "message": "={{ $json.output }}",
        "options": {},
        "subject": "=\ud83d\udcca Weekly Social Media Performance Report \u2014 Twitter & Facebook Overview"
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    },
    {
      "id": "736d973b-c9be-4969-854a-97d039d0e5be",
      "name": "Fetch Recent Tweets",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -544,
        -192
      ],
      "parameters": {
        "url": "https://api.x.com/2/users/1380391508860268549/tweets?max_results=20&tweet.fields=created_at,public_metrics,attachments,entities,source&expansions=attachments.media_keys&media.fields=media_key,type,url,preview_image_url",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "twitterOAuth2Api"
      },
      "credentials": {
        "twitterOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "8b6d38a1-4351-4606-8f66-2a13bd987e44",
      "name": " Fetch Recent Facebook Posts ",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        -544,
        208
      ],
      "parameters": {
        "edge": "posts",
        "node": "230476031170639",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,message,story,created_time,permalink_url,full_picture,attachments{media_type,media,url,description},shares,likes.limit(100).summary(true){id,name},comments.limit(100).summary(true){id,from,message,created_time,like_count,comment_count,reactions.summary(true)},reactions.limit(100).summary(true){type,id,name},from{id,name,category}"
              }
            ]
          }
        },
        "graphApiVersion": "v23.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4c3f7314-3218-486d-8952-eb3a417273e1",
      "name": "Format Facebook Post Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -208,
        208
      ],
      "parameters": {
        "jsCode": "// Input: Facebook Graph API response\nconst posts = $json.data || [];\nreturn posts.map(post => {\n  return {\n    id: post.id,\n    message: post.message || \"\",\n    created_time: post.created_time,\n    image: post.full_picture || \"\",\n    post_url: post.permalink_url,\n    likes: post.likes?.summary?.total_count || 0,\n    comments: post.comments?.summary?.total_count || 0,\n    reactions: post.reactions?.summary?.total_count || 0,\n    author: post.from?.name || \"\",\n    category: post.from?.category || \"\"\n  };\n});\n"
      },
      "typeVersion": 2
    },
    {
      "id": "62027814-4521-47e0-9a68-df7f91d968ad",
      "name": "Format Twitter Post Data",
      "type": "n8n-nodes-base.code",
      "position": [
        -208,
        -192
      ],
      "parameters": {
        "jsCode": "const tweets = $json[\"data\"] || [];\nconst media = ($json[\"includes\"] && $json[\"includes\"][\"media\"]) || [];\n\nconst mediaMap = {};\nfor (const m of media) mediaMap[m.media_key] = m;\n\nconst formatted = tweets.map(t => {\n  const urls = t.entities?.urls?.map(u => u.expanded_url).join(', ') || '';\n  const hashtags = t.entities?.hashtags?.map(h => `#${h.tag}`).join(' ') || '';\n  const mediaUrls = (t.attachments?.media_keys || [])\n    .map(k => mediaMap[k]?.url || mediaMap[k]?.preview_image_url)\n    .filter(Boolean)\n    .join(', ');\n\n  return {\n    id: t.id,\n    text: t.text,\n    created_at: t.created_at,\n    hashtags,\n    retweets: t.public_metrics?.retweet_count || 0,\n    likes: t.public_metrics?.like_count || 0,\n    impressions: t.public_metrics?.impression_count || 0,\n    media: mediaUrls,\n    urls,\n  };\n});\n\nreturn formatted.map(f => ({ json: f }));\n"
      },
      "typeVersion": 2
    },
    {
      "id": "3bfa8c4a-7450-4967-b67e-265aac99f569",
      "name": " Merge Platform Datasets",
      "type": "n8n-nodes-base.merge",
      "position": [
        240,
        0
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "cd7c4788-e94c-4c8f-b4ff-c29e9ae06458",
      "name": " Validate API Response Integrity",
      "type": "n8n-nodes-base.if",
      "position": [
        592,
        0
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e2adb005-2b3c-4d1e-8445-442df1fe925a",
              "operator": {
                "type": "string",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.id }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "708d4343-fd71-4b37-a7c9-5d3ae24f2e22",
      "name": "Log Errors in Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        864,
        656
      ],
      "parameters": {
        "columns": {
          "value": {},
          "schema": [
            {
              "id": "error_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "error_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "error",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "error",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "error_id"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1338537721,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Uldk_4BxWbdZTDZxFUeohIfeBmGHHqVEl9Ogb0l6R8Y/edit#gid=1338537721",
          "cachedResultName": "error log sheet"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1Uldk_4BxWbdZTDZxFUeohIfeBmGHHqVEl9Ogb0l6R8Y",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1Uldk_4BxWbdZTDZxFUeohIfeBmGHHqVEl9Ogb0l6R8Y/edit?usp=drivesdk",
          "cachedResultName": "Interviewer Brief Pack "
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "4eca9420-5e41-4a7a-a0db-804706200de3",
      "name": "Consolidate Social Data Summary ",
      "type": "n8n-nodes-base.code",
      "position": [
        928,
        0
      ],
      "parameters": {
        "jsCode": "// Combine all incoming data from Twitter + Facebook into one single item\nconst allItems = $input.all().map(item => item.json);\n\n// Structure data by platform\nconst twitterPosts = allItems.filter(i => i.text).map(t => ({\n  id: t.id,\n  text: t.text,\n  created_at: t.created_at,\n  hashtags: t.hashtags,\n  retweets: t.retweets,\n  likes: t.likes,\n  impressions: t.impressions,\n  media: t.media,\n  urls: t.urls\n}));\n\nconst facebookPosts = allItems.filter(i => i.message).map(f => ({\n  id: f.id,\n  message: f.message,\n  created_time: f.created_time,\n  image: f.image,\n  post_url: f.post_url,\n  likes: f.likes,\n  comments: f.comments,\n  reactions: f.reactions,\n  author: f.author,\n  category: f.category\n}));\n\n// Single combined JSON item\nreturn [\n  {\n    json: {\n      summary: {\n        total_twitter_posts: twitterPosts.length,\n        total_facebook_posts: facebookPosts.length\n      },\n      twitter_data: twitterPosts,\n      facebook_data: facebookPosts\n    }\n  }\n];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "24aa8084-cddd-4806-b08a-cf1775500c6e",
      "name": " Generate HTML Social Performance Report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        1216,
        0
      ],
      "parameters": {
        "text": "=Analyze the provided social media performance data and generate a clean, responsive HTML report styled for email \u2014 modern, readable, and visually balanced. \nInclude compact tables, soft separators, muted backgrounds, and accent color highlights.\n\nSections required:\n1. Header section with report title and subheading.\n2. Platform Overview Summary \u2014 use subtle background and color-coded engagement highlights.\n3. Top-Performing Posts (Ranked) \u2014 use table with color rows and bold insights.\n4. Engagement Trend Insights \u2014 concise paragraph section with emphasis.\n5. Content Gaps & Opportunities \u2014 side-by-side platform-wise sections (Twitter vs Facebook).\n6. Recommendations \u2014 bullet format with icons or styled emphasis.\n7. Footer note \u2014 small text with timestamp.\n\nAll output must be clean HTML with inline CSS (suitable for Gmail/Outlook rendering).\n\nInput Data:\n{{JSON.stringify($json)}}\n",
        "options": {
          "systemMessage": "=You are an analytics-focused HTML report generator. \nYour task is to create email-ready HTML with balanced spacing, aligned typography, and data-driven clarity.\n\nStyling guidelines:\n- Font: system or Arial, 14px base.\n- Colors: #1E1E1E (text), #1263FF (primary accent), #F6F8FA (background), #EAECEF (borders).\n- Headings: bold, #1263FF.\n- Table headers: shaded background (#F2F4F7).\n- Positive metrics: green (#22C55E), Negative: red (#EF4444).\n- Use soft shadows, 12px rounded corners, and section dividers.\n- Maintain consistent left alignment.\n- Avoid unnecessary borders; use padding and spacing for clarity.\n\nEnsure HTML renders cleanly inside Gmail (no external CSS or scripts).\nUse subtle section transitions (<hr> or gradient separators).\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "8c499ca6-07b2-4e2f-89f6-e22b3ae59afe",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1424,
        -736
      ],
      "parameters": {
        "width": 624,
        "height": 464,
        "content": "## Weekly Social Media Performance Reporter \ud83d\udcca  \nThis workflow automatically collects, analyzes, and summarizes weekly performance from Twitter (X) and Facebook into a visually formatted HTML report, then emails it to the marketing team.\n\n### Core Steps:\n1\ufe0f\u20e3 Fetch latest posts from both platforms  \n2\ufe0f\u20e3 Format and normalize post data (likes, comments, reactions)  \n3\ufe0f\u20e3 Merge both datasets for joint analytics  \n4\ufe0f\u20e3 Validate response integrity and log errors  \n5\ufe0f\u20e3 Generate a consolidated performance summary  \n6\ufe0f\u20e3 Use GPT-4o to create a polished HTML email report  \n7\ufe0f\u20e3 Deliver the report to marketing automatically  \n\n### Setup Notes:\n- Connect: Twitter OAuth, Facebook Graph API, Azure OpenAI, Gmail, Google Sheets  \n- Verify Facebook page ID & Twitter user ID  \n- Update email recipients and Google Sheet URLs  \n- Test run before scheduling automation (e.g., every Monday morning)\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c51468a6-44a6-4a38-9f4d-2daafa4f6687",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -608,
        -464
      ],
      "parameters": {
        "color": 7,
        "height": 944,
        "content": "## Data Fetching Layer  \nRetrieves the most recent 20 tweets and recent Facebook posts from the configured pages/accounts.  \nPulls engagement metrics, media, and timestamps to serve as input for analysis.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "0d54bd36-0da6-43fe-b0b7-5e561e3dcdaf",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -528
      ],
      "parameters": {
        "color": 7,
        "height": 496,
        "content": "## Data Formatting \u2014 Twitter  \nProcesses raw tweet data into structured fields:  \n- Expands hashtags, links, and media  \n- Calculates impressions, likes, and retweets  \n- Ensures consistent JSON formatting for analysis  \nPrepares data for merging with Facebook results.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "bbf29eb3-cb32-4451-861d-79269a59f732",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -272,
        -16
      ],
      "parameters": {
        "color": 7,
        "height": 432,
        "content": "## Data Formatting \u2014 Facebook  \nCleans Facebook API response, extracting message, reactions, image, shares, and engagement stats.  \nOutputs structured post objects ready for aggregation and reporting.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "1d722c71-59af-4fc2-a06c-09841ff0fe0b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -224
      ],
      "parameters": {
        "color": 7,
        "height": 480,
        "content": "## Dataset Merging  \nCombines Twitter and Facebook formatted outputs into one unified data stream.  \nEnables comparative engagement analytics and joint trend detection.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "a19bf4c8-3141-46ec-a997-f0650de9c234",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        528,
        -240
      ],
      "parameters": {
        "color": 7,
        "height": 544,
        "content": "## Data Validation  \nEnsures API responses are valid and contain the required fields before continuing.  \nIf missing or malformed data is found, errors are logged to Google Sheets automatically.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b2f588e1-b8bc-49e6-a103-bd9f47c561e6",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        848,
        -288
      ],
      "parameters": {
        "color": 7,
        "height": 576,
        "content": "## Data Consolidation  \nAggregates merged data into a single structured summary object containing:  \n- Total post counts per platform  \n- Raw post arrays (Twitter + Facebook)  \nThis object is used as the AI input for report generation.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c6d3acbc-549c-4a3a-b515-6176a19d1bd2",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1168,
        -320
      ],
      "parameters": {
        "color": 7,
        "width": 304,
        "height": 736,
        "content": "## AI HTML Report Generation  \nGPT-4o converts structured JSON into a professional, responsive HTML email report.  \nSections include:  \n- Platform overview  \n- Top performing posts  \n- Engagement trends & insights  \n- Content gaps & recommendations  \nStyled using inline CSS, optimized for Gmail/Outlook rendering.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "90a0cba6-aa09-40b8-b0c8-0fb29ac9341a",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1584,
        -256
      ],
      "parameters": {
        "color": 7,
        "height": 544,
        "content": "## Email Dispatch  \nAutomatically sends the final HTML report via Gmail with subject:  \n\u201c\ud83d\udcca Weekly Social Media Performance Report \u2014 Twitter & Facebook Overview\u201d  \nEnsures timely delivery of actionable insights.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "2de766ff-5dd1-4a23-a959-77dda8e71b6b",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        800,
        400
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 448,
        "content": "## Error Handling & Logging  \nLogs failed API responses or empty datasets into the configured Google Sheet.  \nProvides visibility into integration reliability and API uptime.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7deed0c3-b6fe-449f-988d-0eabe16ed99f",
  "connections": {
    "Fetch Recent Tweets": {
      "main": [
        [
          {
            "node": "Format Twitter Post Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Configure GPT-4o Model": {
      "ai_languageModel": [
        [
          {
            "node": " Generate HTML Social Performance Report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    " Merge Platform Datasets": {
      "main": [
        [
          {
            "node": " Validate API Response Integrity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Twitter Post Data": {
      "main": [
        [
          {
            "node": " Merge Platform Datasets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Facebook Post Data": {
      "main": [
        [
          {
            "node": " Merge Platform Datasets",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    " Fetch Recent Facebook Posts ": {
      "main": [
        [
          {
            "node": "Format Facebook Post Data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    " Validate API Response Integrity": {
      "main": [
        [
          {
            "node": "Consolidate Social Data Summary ",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Errors in Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Consolidate Social Data Summary ": {
      "main": [
        [
          {
            "node": " Generate HTML Social Performance Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Fetch Recent Tweets",
            "type": "main",
            "index": 0
          },
          {
            "node": " Fetch Recent Facebook Posts ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    " Generate HTML Social Performance Report": {
      "main": [
        [
          {
            "node": " Send Email Summary to Marketing Team",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

Credentials you'll need

Each integration node will prompt for credentials when you import. We strip credential IDs before publishing — you'll add your own.

Pro

For the full experience including quality scoring and batch install features for each workflow upgrade to Pro

About this workflow

Automate your weekly cross-platform social media analytics workflow with AI-powered insights. 📊🤖 This system retrieves real-time Twitter (X) and Facebook data, validates and merges the metrics, formats them via custom JavaScript, generates a visual HTML summary with GPT-4o,…

Source: https://n8n.io/workflows/10556/ — original creator credit. Request a take-down →

More AI & RAG workflows → · Browse all categories →

Related workflows

Workflows that share integrations, category, or trigger type with this one. All free to copy and import.

AI & RAG

Gain real-time audience intelligence with this cross-platform AI Sentiment Analyzer for Twitter (X) and Facebook. 📊🧠 This workflow consolidates mentions and comments, performs GPT-4o-powered sentiment

Lm Chat Azure Open Ai, HTTP Request, Facebook Graph Api +3
AI & RAG

This workflow is designed for marketers, content creators, agencies, and solo founders who want to publish long‑form posts with visuals on autopilot using n8n and AI agents. ​

Tool Http Request, Agent, HTTP Request +27
AI & RAG

Automate your weekly social media analytics with this end-to-end AI reporting workflow. 📊🤖 This system collects real-time Twitter (X) and Facebook metrics, merges and validates data, formats it with J

Lm Chat Azure Open Ai, HTTP Request, Google Sheets +4
AI & RAG

This workflow automates the employee onboarding process by creating Jira accounts, generating Notion onboarding checklists, crafting AI-generated welcome messages, and sending personalized welcome ema

HTTP Request, Google Sheets, Notion +3
AI & RAG

Description:

Agent, YouTube, HTTP Request +4