{
  "id": "mxZxXNCnIWwyaO5a",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Cross-Channel Growth Tracker",
  "tags": [],
  "nodes": [
    {
      "id": "6a10854f-9ef6-459e-a92d-bcb1c3dfde67",
      "name": "When clicking \u2018Execute workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -1072,
        32
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "01b1816a-7c00-4421-919d-0c39ac9bd25e",
      "name": "Configure GPT-4o Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatAzureOpenAi",
      "position": [
        816,
        240
      ],
      "parameters": {
        "model": "gpt-4o",
        "options": {}
      },
      "credentials": {
        "azureOpenAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "2471b861-b399-43a2-b8ef-920c987d6ea1",
      "name": "Fetch Twitter Metrics (X API)1",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -752,
        -96
      ],
      "parameters": {
        "url": "https://api.x.com/2/users/by/username/marveldcclub?user.fields=public_metrics",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "twitterOAuth2Api"
      },
      "credentials": {
        "twitterOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "86e9c424-0bee-4541-8947-832312ae4124",
      "name": "Fetch Facebook Page Metrics (Graph API)",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        -752,
        192
      ],
      "parameters": {
        "url": "https://graph.facebook.com/v18.0/230476031170639?fields=name,followers_count,fan_count",
        "options": {},
        "authentication": "predefinedCredentialType",
        "nodeCredentialType": "facebookGraphApi"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5ee82890-20a4-4bd0-b314-263004de1c34",
      "name": "Merge Platform Responses",
      "type": "n8n-nodes-base.merge",
      "position": [
        -368,
        16
      ],
      "parameters": {},
      "typeVersion": 3.2
    },
    {
      "id": "920654bc-4ccc-40ee-89a4-97a08712a5a4",
      "name": " Validate API Response Integrity",
      "type": "n8n-nodes-base.if",
      "position": [
        -80,
        16
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e2adb005-2b3c-4d1e-8445-442df1fe925a",
              "operator": {
                "type": "object",
                "operation": "notEmpty",
                "singleValue": true
              },
              "leftValue": "={{ $json.data }}",
              "rightValue": ""
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "270dc82a-628c-4e42-bd54-a13f0f5c62e5",
      "name": "Log Errors in Google Sheets",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        160,
        608
      ],
      "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": "576f825c-3490-47a1-9fa2-f542ca5c7a33",
      "name": " Normalize & Format Social Data (JavaScript)",
      "type": "n8n-nodes-base.code",
      "position": [
        256,
        0
      ],
      "parameters": {
        "jsCode": "// Twitter (first item)\nconst twitterData = items[0].json;\n\n// Facebook (second item)\nconst facebookData = items[1].json;\n\n// Merge both into one clean object\nconst merged = {\n  twitter: {\n    name: twitterData.data.name,\n    username: twitterData.data.username,\n    followers: twitterData.data.public_metrics.followers_count,\n    following: twitterData.data.public_metrics.following_count,\n    tweets: twitterData.data.public_metrics.tweet_count,\n    likes: twitterData.data.public_metrics.like_count,\n    media: twitterData.data.public_metrics.media_count\n  },\n  facebook: {\n    name: facebookData.name,\n    followers: facebookData.followers_count,\n    likes: facebookData.fan_count,\n    id: facebookData.id\n  }\n};\n\n// Return single unified JSON\nreturn [{ json: merged }];\n"
      },
      "typeVersion": 2
    },
    {
      "id": "264c81c4-cc25-4396-9117-1cb4a2d1a374",
      "name": "Generate HTML Social Performance Report (AI)",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        816,
        0
      ],
      "parameters": {
        "text": "=Generate an HTML email summary comparing social media performance across platforms.\n\nInput data:\nTwitter:\n- Name: {{$json.twitter.name}}\n- Username: {{$json.twitter.username}}\n- Followers: {{$json.twitter.followers}}\n- Following: {{$json.twitter.following}}\n- Tweets: {{$json.twitter.tweets}}\n- Likes: {{$json.twitter.likes}}\n- Media Posts: {{$json.twitter.media}}\n\nFacebook:\n- Page Name: {{$json.facebook.name}}\n- Followers: {{$json.facebook.followers}}\n- Likes: {{$json.facebook.likes}}\n\nNow analyze the data and generate a professional HTML report that includes:\n1. Overview section summarizing total reach and activity.\n2. Platform-wise performance breakdown (Twitter, Facebook).\n3. Highlight growth or decline with short insights.\n4. Use tables, simple inline CSS, and emojis for readability.\n5. End with a motivational closing line.\n\nOutput only valid HTML (no markdown).\n",
        "options": {
          "systemMessage": "=You are a social media analytics assistant specialized in crafting performance reports.\n\nYour goal is to transform raw metrics into engaging, data-driven summaries.\n\nGuidelines:\n- Write in a confident, analytical tone.\n- Present key metrics in HTML tables with subtle color cues.\n- Highlight positive performance with green, weak metrics with orange/red.\n- Avoid marketing fluff; focus on clarity and visual readability.\n- Use emojis to make sections visually distinct (\ud83d\udcca, \ud83d\udc26, \ud83d\udcd8, \ud83d\udcc8).\n- Include a short conclusion motivating the user to keep improving.\n"
        },
        "promptType": "define"
      },
      "typeVersion": 2.1
    },
    {
      "id": "92c1e648-f2c8-44e4-af2d-d0cbed1dc182",
      "name": "Save Report to Notion Database",
      "type": "n8n-nodes-base.notion",
      "position": [
        528,
        -592
      ],
      "parameters": {
        "title": "={{ $json.twitter }}",
        "simple": false,
        "options": {},
        "resource": "databasePage",
        "databaseId": {
          "__rl": true,
          "mode": "list",
          "value": "2a1802b9-1fa0-8011-b891-fe29c9244ac0",
          "cachedResultUrl": "https://www.notion.so/2a1802b91fa08011b891fe29c9244ac0",
          "cachedResultName": "Growth Chart"
        },
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "twitter name |title",
              "title": "={{ $json.twitter.name }}"
            },
            {
              "key": "username|rich_text",
              "textContent": "={{ $json.twitter.username }}"
            },
            {
              "key": "likes|rich_text",
              "textContent": "={{ $json.twitter.likes }}"
            },
            {
              "key": "following|rich_text",
              "textContent": "={{ $json.twitter.following.toString() }}"
            },
            {
              "key": "followers |rich_text",
              "textContent": "={{ $json.twitter.followers }}"
            },
            {
              "key": "facebook|rich_text",
              "textContent": "={{ $json.facebook.name }}"
            },
            {
              "key": "likes|rich_text",
              "textContent": "={{ $json.facebook.likes.toString() }}\n"
            },
            {
              "key": "followers |rich_text",
              "textContent": "={{ $json.facebook.followers.toString() }}\n"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "070f471b-f231-488a-ae64-2584a58655b6",
      "name": " Send Email Summary to Marketing Team",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1520,
        352
      ],
      "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": "ee3396ce-91eb-4d57-8459-fc91dc48807b",
      "name": "Announce Summary in Slack",
      "type": "n8n-nodes-base.slack",
      "position": [
        1504,
        -368
      ],
      "parameters": {
        "text": "=\ud83d\udce2 *Social Media Performance Report*\n\n\ud83d\udc26 *Twitter \u2014 *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.name }}\n\u2022 Username: `{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.username }}`\n\u2022 Followers: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.followers }}*\n\u2022 Following: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.following }}*\n\u2022 Tweets: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.tweets }}*\n\u2022 Likes: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.likes }}*\n\u2022 Media Posts: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.twitter.media }}*\n\n\ud83d\udcd8 *Facebook \u2014 {{ $(' Normalize & Format Social Data (JavaScript)').item.json.facebook.name }}*\n\u2022 Followers: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.facebook.followers }}*\n\u2022 Likes: *{{ $(' Normalize & Format Social Data (JavaScript)').item.json.facebook.likes }}*\n\n\ud83d\udcca *Summary Insight:*\n{{ \n  $json.twitter.followers > $json.facebook.followers \n    ? \"\ud83d\ude80 Twitter shows stronger engagement this week!\" \n    : \"\u26a0\ufe0f Facebook performance is lagging, needs attention.\"\n}}\n\n\ud83d\uddd3\ufe0f _Auto-generated by Social Analytics Bot at {{ $now }}_\n",
        "user": {
          "__rl": true,
          "mode": "list",
          "value": "U09HMPVD466",
          "cachedResultName": "newscctv22"
        },
        "select": "user",
        "otherOptions": {}
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.3
    },
    {
      "id": "5bd4dedd-90eb-4c1e-a0a2-1b3a3b0ee544",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1888,
        -736
      ],
      "parameters": {
        "width": 624,
        "height": 496,
        "content": "## Cross-Platform Growth Tracker \ud83d\ude80  \nThis workflow automatically tracks and reports weekly follower and engagement growth across Twitter (X) and Facebook.\n\nIt aggregates key metrics, generates a styled HTML summary via GPT-4o, logs data to Notion for historical tracking, and posts performance updates to Slack and email.\n\n### Key Highlights:\n1\ufe0f\u20e3 Fetches follower and like counts from both platforms.  \n2\ufe0f\u20e3 Validates data integrity and logs any errors to Google Sheets.  \n3\ufe0f\u20e3 Normalizes metrics into unified JSON (Twitter + Facebook).  \n4\ufe0f\u20e3 Generates a professional HTML summary report.  \n5\ufe0f\u20e3 Updates Notion \u201cGrowth Chart\u201d database for archival tracking.  \n6\ufe0f\u20e3 Sends report via Gmail and posts summary to Slack.\n\n### Setup Checklist:\n- Connect all credentials: Twitter, Facebook Graph, Notion, Azure OpenAI, Gmail, Google Sheets, Slack.  \n- Update Notion Database ID and email recipients.  \n- Customize Slack user/channel if needed.  \n- Schedule to run automatically (weekly or daily).\n"
      },
      "typeVersion": 1
    },
    {
      "id": "48f3dd13-9d84-4f49-bb91-015af6510f18",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -816,
        -416
      ],
      "parameters": {
        "color": 7,
        "height": 896,
        "content": "## Data Fetching Layer  \nFetches live analytics data from Twitter (X) and Facebook Graph API.  \nCaptures follower count, likes, tweets/posts, and media uploads for both platforms.  \nProvides the raw input for normalization and comparison.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "c1ea7ae8-8da6-45b8-852d-1d512ddfc046",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -464,
        -160
      ],
      "parameters": {
        "color": 7,
        "width": 272,
        "height": 368,
        "content": "## Dataset Merging  \nMerges Twitter and Facebook API responses into a unified dataset.  \nMaintains key engagement fields and creates a standardized structure ready for validation.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "996b1f09-7a63-4281-838b-bdfcd713364f",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -144,
        -208
      ],
      "parameters": {
        "color": 7,
        "height": 400,
        "content": "## Data Validation Layer  \nEnsures both API responses contain valid data.  \nIf missing or invalid, logs the issue to Google Sheets and prevents incomplete processing.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "cdb1e0dc-adac-4b12-83a9-8f9bbe8fb968",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        176,
        -240
      ],
      "parameters": {
        "color": 7,
        "height": 464,
        "content": "## Normalization & Formatting  \nCleans, renames, and structures merged data into JSON objects under `twitter` and `facebook` keys.  \nEnsures consistent field naming and metric availability for AI summarization.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "8c0c7a1c-bef7-47eb-b0f9-e0f531b2be6e",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        752,
        -304
      ],
      "parameters": {
        "color": 7,
        "width": 352,
        "height": 704,
        "content": "## AI Report Generation (GPT-4o)  \nGPT-4o transforms normalized data into a visually styled HTML email summary.  \nIncludes:\n- Total reach overview  \n- Platform comparison tables  \n- Emoji-based insights  \n- Growth trends & improvement suggestions  \nOutput is formatted with inline CSS for Gmail compatibility.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "09a9fef7-458e-4d49-8572-15c300fdccbb",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        448,
        -848
      ],
      "parameters": {
        "color": 7,
        "height": 480,
        "content": "## Data Storage in Notion  \nSaves structured Twitter and Facebook metrics in the \u201cGrowth Chart\u201d Notion database.  \nCreates historical records for growth visualization and long-term trend tracking.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "b8065c12-da97-4f59-9ebc-6f7f7d34415f",
      "name": "Sticky Note7",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1424,
        -656
      ],
      "parameters": {
        "color": 7,
        "height": 512,
        "content": "## Slack Announcement  \nPosts a summary message to the Slack user/channel with weekly metrics and platform comparison.  \nIncludes emoji-based insights such as \u201c\ud83d\ude80 Twitter shows stronger engagement\u201d or \u201c\u26a0\ufe0f Facebook performance is lagging.\u201d\n"
      },
      "typeVersion": 1
    },
    {
      "id": "4795aadb-4ca8-40c2-a7f7-0fab9ef6773c",
      "name": "Sticky Note8",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1456,
        32
      ],
      "parameters": {
        "color": 7,
        "height": 576,
        "content": "## Email Dispatch  \nSends the HTML performance report to the marketing team via Gmail.  \nSubject: \u201c\ud83d\udcca Weekly Social Media Performance Report \u2014 Twitter & Facebook Overview.\u201d  \nEnsures consistent delivery of visually formatted weekly summaries.\n"
      },
      "typeVersion": 1
    },
    {
      "id": "df7f5541-09cd-4cad-b05f-62076ae80104",
      "name": "Sticky Note9",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        96,
        336
      ],
      "parameters": {
        "color": 7,
        "height": 544,
        "content": "## Error Logging  \nCaptures workflow or API errors and logs them into Google Sheets.  \nAllows ongoing monitoring of API response reliability and workflow health.\n"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "7b0d44bf-c5c1-4b6c-a9ec-f7a47d96c334",
  "connections": {
    "Configure GPT-4o Model": {
      "ai_languageModel": [
        [
          {
            "node": "Generate HTML Social Performance Report (AI)",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Merge Platform Responses": {
      "main": [
        [
          {
            "node": " Validate API Response Integrity",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Announce Summary in Slack": {
      "main": [
        []
      ]
    },
    "Fetch Twitter Metrics (X API)1": {
      "main": [
        [
          {
            "node": "Merge Platform Responses",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    " Validate API Response Integrity": {
      "main": [
        [
          {
            "node": " Normalize & Format Social Data (JavaScript)",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Log Errors in Google Sheets",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Execute workflow\u2019": {
      "main": [
        [
          {
            "node": "Fetch Twitter Metrics (X API)1",
            "type": "main",
            "index": 0
          },
          {
            "node": "Fetch Facebook Page Metrics (Graph API)",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Fetch Facebook Page Metrics (Graph API)": {
      "main": [
        [
          {
            "node": "Merge Platform Responses",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    " Normalize & Format Social Data (JavaScript)": {
      "main": [
        [
          {
            "node": "Generate HTML Social Performance Report (AI)",
            "type": "main",
            "index": 0
          },
          {
            "node": "Save Report to Notion Database",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Generate HTML Social Performance Report (AI)": {
      "main": [
        [
          {
            "node": " Send Email Summary to Marketing Team",
            "type": "main",
            "index": 0
          },
          {
            "node": "Announce Summary in Slack",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}