AutomationFlowsAI & RAG › Detect Viral Youtube Videos with AI Analysis and Email Reports

Detect Viral Youtube Videos with AI Analysis and Email Reports

Bygclbck @gclbck on n8n.io

This workflow automates the discovery and analysis of potentially viral YouTube videos. It searches for recent, popular videos based on a keyword, calculates a unique "Algorithmic Lift Score" to measure virality, and uses an AI agent to generate an insightful summary report that…

Event trigger★★★★☆ complexityAI-powered26 nodesAgentTool ThinkOpenAI ChatHTTP RequestGmail
AI & RAG Trigger: Event Nodes: 26 Complexity: ★★★★☆ AI nodes: yes Added:

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

This workflow follows the Agent → Gmail 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
{
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "nodes": [
    {
      "id": "ce85e8e4-9e2b-46cd-bc0d-1517049e1322",
      "name": "When clicking \u2018Test workflow\u2019",
      "type": "n8n-nodes-base.manualTrigger",
      "position": [
        -272,
        -448
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "62ca03a8-f032-43e2-95af-48bee0a58b53",
      "name": "CalculateMetrics",
      "type": "n8n-nodes-base.code",
      "position": [
        144,
        -144
      ],
      "parameters": {
        "mode": "runOnceForEachItem",
        "jsCode": "\nconst views = Number($json.ViewCount || 0);\nconst likes = Number($json.likeCount || 0);\nconst comments = Number($json.commentCount || 0);\n\nconst publishedAt = $json.publishedAt || '';\nconst publishTime = new Date (publishedAt).getTime();\nconst now = Date.now();\nconst hoursSincePublish = (now - publishTime) / (1000 * 60 * 60); // Convert millisecond\n\nconst likeRate = views > 0 ? (likes / views) * 100 : 0; // Like percentage \nconst commentRate = views > 0 ? (comments / views) * 100 : 0; // Comment percentage \nconst viewsPerHour = hoursSincePublish > 0 ? views / hoursSincePublish: 0; // Views per\n\nconst title = $json.title || '';\nconst videoID = $json.videoId || '';\nconst youtubeURL = `https://www.youtube.com/watch?v=${videoID}`;\n\nconst channelId = $json.channelID;\nconst channelOpenDate = $json.channelOpenDate;\nconst channelTotalViewCount= $json.channelTotalViewCount;\nconst subscriberCount= $json.subscriberCount ;\nconst categoryID= $json.categoryID;\nconst channelName= $json.channelName;\nconst categoryName= $json.categoryName;\nreturn { \n  title, \n  youtubeURL,  \n  categoryID, \n  categoryName,\n  channelId,\n  channelName,\n  channelOpenDate,\n  channelTotalViewCount,\n  subscriberCount,\n  publishedAt, \n  views,\n  likes, \n  comments, \n  likeRate, \n  commentRate, \n  viewsPerHour\n};"
      },
      "typeVersion": 2
    },
    {
      "id": "584d47e4-3ade-4041-a18d-8f272f12d1fb",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        880,
        -144
      ],
      "parameters": {
        "text": "=json: {{$('Aggregate').item.json.data.toJsonString() }}\n",
        "options": {
          "systemMessage": "=You are an expert YouTube video analyst. Your task is to review a JSON array containing data for {{$('Setup').item.json.maxResult}} YouTube videos, including calculated virality metrics like \"algorithmicLiftScore\", \"viewsPerSubscriber\", and \"relativeEngagementRate\".\n\nYour goal is to provide a concise, insightful summary that highlights the most important findings and patterns.\n\n**Output Requirements:**\n\n1.  **Overall Virality Trend:** Briefly describe the general range of \"algorithmicLiftScore\" and identify if there are any exceptionally viral videos based on this score.\n2.  **Top 3 Most Viral Videos:** List the top 3 videos by \"algorithmicLiftScore\". For each, include:\n    *   Title\n    *   youtubeURL\n    *   Channel Name and Subscriber Count\n    *   views\n    *   viewsPerHour\n    *   Algorithmic Lift Score\n    *   Key reason for high score (e.g., \"extremely high views per subscriber,\" \"exceptional engagement rate for its size,\" \"very rapid view growth\").\n3.  **Key Statistics Averages/Ranges (across all 20 videos):**\n    *   Average `algorithmicLiftScore`\n    *   Average `viewsPerSubscriber`\n    *   Average `relativeEngagementRate`\n    *   Top 3 most common `categoryName` (with count/percentage if possible).\n4.  **Noteworthy Observations/Patterns:**\n    *   Any interesting correlations between `categoryName` and virality.\n    *   Any channels that appear multiple times or show consistent performance.\n    *   Any videos with surprisingly high or low `likeRate` or `commentRate` compared to their `views`.\n    *   General sentiment or common themes in the titles (e.g., \"AI,\" \"shorts,\" \"comedy\").\n5.  **Conciseness:** Keep the summary to a maximum of 300 words. Use bullet points or short paragraphs for readability.\n\n\n**JSON Input example:**\n\"\"\"\n[\n  {\n    \"title\": \"\ud83c\udf1fGuess Who #kpop #kpopdemonhunters #sussie #ai\",\n    \"youtubeURL\": \"https://www.youtube.com/watch?v=dfgrtgrrt4t\",\n    \"categoryID\": \"24\",\n    \"categoryName\": \"Entertainment\",\n    \"channelId\": \"UCYCBxphosvertg_ZOmAvdsfvsd\",\n    \"channelName\": \"krytoi oker\",\n    \"channelOpenDate\": \"2025-08-26T12:11:27.987819Z\",\n    \"channelTotalViewCount\": 25715501,\n    \"subscriberCount\": 6650,\n    \"publishedAt\": \"2025-09-06T13:22:10Z\",\n    \"views\": 2646019,\n    \"likes\": 9249,\n    \"comments\": 15,\n    \"likeRate\": 0.0034954397530781145,\n    \"commentRate\": 0.000005668893534022243,\n    \"viewsPerHour\": 65672.62637656713,\n    \"algorithmicLiftScore\": 239.3253287501648,\n    \"relativeEngagementRate\": 0.35011086466121366,\n    \"logViewsPerHour\": 4.817390997890299,\n    \"hoursSincePublished\": 40.29104888888889,\n    \"viewsPerSubscriber\": 397.8975939849624\n  },\n  {\n    \"title\": \"New York help PLEASE! \ud83d\ude4f #funny #baby #ai #cute #reels #comedy #shorts #trending\",\n    \"youtubeURL\": \"https://www.youtube.com/watch?v=NLKm8HM5453gs\",\n    \"categoryID\": \"24\",\n    \"categoryName\": \"Entertainment\",\n    \"channelId\": \"UCu22ALsY7fvsfvsdrgtsg\",\n    \"channelName\": \"Yazt Creationz\",\n    \"channelOpenDate\": \"2022-11-25T06:58:20.821126Z\",\n    \"channelTotalViewCount\": 21190181,\n    \"subscriberCount\": 30800,\n    \"publishedAt\": \"2025-09-06T12:33:13Z\",\n    \"views\": 937872,\n    \"likes\": 8387,\n    \"comments\": 25,\n    \"likeRate\": 0.008942584915638808,\n    \"commentRate\": 0.000026656089530341027,\n    \"viewsPerHour\": 22815.449610843752,\n    \"algorithmicLiftScore\": 18.975135803015906,\n    \"relativeEngagementRate\": 0.896924100516915,\n    \"logViewsPerHour\": 4.358248066270673,\n    \"hoursSincePublished\": 41.106882222222225,\n    \"viewsPerSubscriber\": 30.45038961038961\n  }\n]"
        },
        "promptType": "define"
      },
      "typeVersion": 1.9
    },
    {
      "id": "2ed02259-c6b8-4568-bf17-306b53685efd",
      "name": "Think",
      "type": "@n8n/n8n-nodes-langchain.toolThink",
      "position": [
        1008,
        -272
      ],
      "parameters": {},
      "typeVersion": 1
    },
    {
      "id": "76a2b5f9-fa21-4f20-a7cb-8f643575e9a8",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        864,
        -272
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4o-mini"
        },
        "options": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "73c079e8-1cef-48f7-9904-c95fa479d0a8",
      "name": "Sort",
      "type": "n8n-nodes-base.sort",
      "position": [
        448,
        -144
      ],
      "parameters": {
        "options": {},
        "sortFieldsUi": {
          "sortField": [
            {
              "order": "descending",
              "fieldName": "algorithmicLiftScore"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "141a3525-0575-4ec8-ae72-36e5a8f50cd5",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -272,
        -256
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 13
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "b53a3146-f068-4be3-8821-6a54962db65c",
      "name": "GetChannelInfo",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        640,
        -624
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/channels?",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "={{ $('Setup').item.json.GoogleAPIkey }}"
            },
            {
              "name": "part",
              "value": "snippet, statistics, topicDetails"
            },
            {
              "name": "id",
              "value": "={{ $json['items.snippet.channelId'] }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "d54b9774-3c20-4804-b41b-978b59603bc1",
      "name": "SearchVideos",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        96,
        -448
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/search?",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "={{ $('Setup').item.json.GoogleAPIkey }}"
            },
            {
              "name": "part",
              "value": "snippet"
            },
            {
              "name": "order",
              "value": "=viewCount"
            },
            {
              "name": "type",
              "value": "video"
            },
            {
              "name": "publishedAfter",
              "value": "={{ $now.minus({ days: $('Setup').item.json.daysback }).toUTC().toISO() }}"
            },
            {
              "name": "q",
              "value": "={{ $('Setup').item.json.query }}"
            },
            {
              "name": "maxResults",
              "value": "={{ $('Setup').item.json.maxResult }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "c6c2bbe2-1a6c-4a46-a859-6c7ccf5dbd25",
      "name": "Split Out1",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        256,
        -448
      ],
      "parameters": {
        "include": "selectedOtherFields",
        "options": {},
        "fieldToSplitOut": "items",
        "fieldsToInclude": "videoId,channelId, publishedAt, "
      },
      "typeVersion": 1
    },
    {
      "id": "2d29fd18-f796-4e40-aeb0-4af21a4939b5",
      "name": "Split Out2",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        416,
        -448
      ],
      "parameters": {
        "include": "selectedOtherFields",
        "options": {},
        "fieldToSplitOut": "items.snippet.channelId",
        "fieldsToInclude": "items.snippet.channelId, items.snippet.publishedAt, items.id.videoId"
      },
      "typeVersion": 1
    },
    {
      "id": "32b9f4a4-87cc-4638-a67e-8cf1b2a6e334",
      "name": "GetVidStats",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        640,
        -448
      ],
      "parameters": {
        "url": "https://www.googleapis.com/youtube/v3/videos?",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "key",
              "value": "={{ $('Setup').item.json.GoogleAPIkey }}"
            },
            {
              "name": "part",
              "value": "snippet,statistics"
            },
            {
              "name": "id",
              "value": "={{ $json['items.id.videoId'] }}"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "5c09783e-2f84-4705-ab5d-e14b3bf32a80",
      "name": "ChannelInfo",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        -624
      ],
      "parameters": {
        "jsCode": "const output = [];\n\n\nfor (const item of items) {\n  \n  const channelData = item.json;\n\n  \n  if (channelData.items && channelData.items.length > 0) {\n    const channel = channelData.items[0];\n    output.push({\n      channelName: channel.snippet.title,\n      channelID: channel.id,\n      channelOpenDate: channel.snippet.publishedAt,\n      channelTotalViewCount: parseInt(channel.statistics.viewCount,10),\n      subscriberCount: parseInt(channel.statistics.subscriberCount,10),\n    });\n  }\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "fc0823b9-890b-4f0f-beb2-03a18b5e7a97",
      "name": "VidStats",
      "type": "n8n-nodes-base.code",
      "position": [
        832,
        -448
      ],
      "parameters": {
        "jsCode": "const output = [];\n\n\nconst youtubeCategories = {\n  \"1\": \"Film & Animation\",\n  \"2\": \"Autos & Vehicles\",\n  \"10\": \"Music\",\n  \"15\": \"Pets & Animals\",\n  \"17\": \"Sports\",\n  \"18\": \"Short Movies\",\n  \"19\": \"Travel & Events\",\n  \"20\": \"Gaming\",\n  \"21\": \"Videoblogging\",\n  \"22\": \"People & Blogs\",\n  \"23\": \"Comedy\",\n  \"24\": \"Entertainment\",\n  \"25\": \"News & Politics\",\n  \"26\": \"Howto & Style\",\n  \"27\": \"Education\",\n  \"28\": \"Science & Technology\",\n  \"29\": \"Nonprofits & Activism\",\n  \"30\": \"Movies\",\n  \"31\": \"Anime/Animation\",\n  \"32\": \"Action/Adventure\",\n  \"33\": \"Classics\",\n  \"34\": \"Comedy\",\n  \"35\": \"Documentary\",\n  \"36\": \"Drama\",\n  \"37\": \"Family\",\n  \"38\": \"Foreign\", // Note: YouTube's own categories can have overlaps or changes\n  \"39\": \"Horror\",\n  \"40\": \"Sci-Fi/Fantasy\",\n  \"41\": \"Thriller\",\n  \"42\": \"Shorts\",\n  \"43\": \"Shows\",\n  \"44\": \"Trailers\"\n};\n\nfor (const item of items) {\n\n  const videoData = item.json;\n\n  if (videoData.items && videoData.items.length > 0) {\n    const video = videoData.items[0]; \n    output.push({\n      title:video.snippet.title,      \n      videoId:video.id,\n      channelID: video.snippet.channelId,\n      categoryID: video.snippet.categoryId,\n      categoryName: youtubeCategories[video.snippet.categoryId] || \"Unknown Category\",\n\n      ViewCount: parseInt(video.statistics.viewCount,10),\n      favoriteCount: parseInt(video.statistics.favoriteCount,10),\n      likeCount: parseInt(video.statistics.likeCount,10),\n      commentCount: parseInt(video.statistics.commentCount,10),\n      publishedAt:video.snippet.publishedAt,\n\n    });\n  }\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "a543b4f8-19fb-44fd-af5d-d4dd506814d8",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1088,
        -464
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "fieldsToMatchString": "channelID"
      },
      "typeVersion": 3.2
    },
    {
      "id": "f77017ff-a348-4011-8e6d-d3471ba527c0",
      "name": "AlgorithmicLiftScore",
      "type": "n8n-nodes-base.code",
      "position": [
        304,
        -144
      ],
      "parameters": {
        "jsCode": "const output = [];\nconst currentTimestamp = Date.now(); // Get current timestamp in milliseconds\n\nfor (const item of items) {\n  \n  const videoData = item.json;\n\n  const channelId = videoData.channelId; \n  const subscriberCount = Number(videoData.subscriberCount || 0);\n  const videoViews = Number(videoData['views'] || 0); \n  const numberOfLikes = Number(videoData['likes'] || 0); \n  const numberOfComments = Number(videoData['comments'] || 0);\n  const videoPublishedAt = videoData.publishedAt; \n\n\n  // --- 1. Calculate hoursSincePublished ---\n  let hoursSincePublished;\n  try {\n    const publishedDate = new Date(videoPublishedAt);\n    if (isNaN(publishedDate.getTime())) {\n      throw new Error(`Invalid videoPublishedAt date: \"${videoPublishedAt}\"`);\n    }\n    hoursSincePublished = (currentTimestamp - publishedDate.getTime()) / (1000 * 60 * 60);\n    \n    hoursSincePublished = Math.max(1, hoursSincePublished);\n  } catch (e) {\n    \n    hoursSincePublished = 1; // Default to 1 hour if date is invalid or missing\n  }\n  \n\n  // --- 2. Calculate viewsPerHour ---\n  const viewsPerHour = videoViews / hoursSincePublished;\n  \n  // --- 3. Handle effectiveSubscriberCount ---\n  const effectiveSubscriberCount = Math.max(1, subscriberCount); // Avoid division by zero\n  \n  // --- 4. Calculate Views_Per_Subscriber ---\n  const viewsPerSubscriber = videoViews / effectiveSubscriberCount;\n\n  // --- 5. Calculate Relative_Engagement_Rate ---\n  let likeRate = 0;\n  let commentRate = 0;\n  if (videoViews > 0) { // Only calculate rates if there are views to avoid division by zero\n    likeRate = numberOfLikes / videoViews;\n    commentRate = numberOfComments / videoViews;\n  }\n  const relativeEngagementRate = (likeRate + commentRate) * 100;\n\n\n  // --- 6. Calculate Log_Views_Per_Hour (for Normalized_Views_Per_Hour) ---\n  const logViewsPerHour = Math.log10(viewsPerHour + 1); // Add 1 to handle 0 gracefully\n  \n\n  // --- 7. Calculate Algorithmic_Lift_Score (ALS) ---\n  const W1 = 0.6; // Weight for Views_Per_Subscriber\n  const W2 = 0.3; // Weight for Relative_Engagement_Rate\n  const W3 = 0.1; // Weight for Log_Views_Per_Hour\n\n  const algorithmicLiftScore =\n    (W1 * viewsPerSubscriber) +\n    (W2 * relativeEngagementRate) +\n    (W3 * logViewsPerHour);\n\n  // Add the calculated score and other relevant data to the output\n  output.push({\n    json: {\n      ...videoData, // Keep all original data\n      algorithmicLiftScore: algorithmicLiftScore,\n      relativeEngagementRate: relativeEngagementRate,\n      logViewsPerHour: logViewsPerHour,\n      hoursSincePublished: hoursSincePublished,\n      viewsPerHour: viewsPerHour,\n      viewsPerSubscriber: viewsPerSubscriber,\n      likeRate: likeRate,\n      commentRate: commentRate\n    },\n  });\n}\n\nreturn output;"
      },
      "typeVersion": 2
    },
    {
      "id": "12fab598-4dcc-4b5a-8de0-f282dfe912e1",
      "name": "Setup",
      "type": "n8n-nodes-base.set",
      "position": [
        -64,
        -448
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "c052c179-7918-467f-9fa8-4a4d0e2a1df0",
              "name": "query",
              "type": "string",
              "value": "AIvideo"
            },
            {
              "id": "a40f07ae-3312-4118-b1b1-05bca0b43dd1",
              "name": "GoogleAPIkey",
              "type": "string",
              "value": ""
            },
            {
              "id": "3157a6c2-172e-4a1c-93c0-c99a527d4fc0",
              "name": "daysback",
              "type": "number",
              "value": 3
            },
            {
              "id": "33364ded-dc2e-441c-9cdf-3be3dcecac56",
              "name": "maxResult",
              "type": "number",
              "value": 20
            },
            {
              "id": "6dbb8d3a-e95e-4c1e-8b03-45c7f26408f9",
              "name": "email",
              "type": "string",
              "value": ""
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "28bf5ada-6880-4de8-a9ec-a1a3aad7ab31",
      "name": "Remove_Duplicates",
      "type": "n8n-nodes-base.removeDuplicates",
      "position": [
        -48,
        -144
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 2
    },
    {
      "id": "1ded0269-047c-4c4d-a923-d36e2c4ef6f4",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -400,
        -1136
      ],
      "parameters": {
        "color": 4,
        "width": 416,
        "height": 480,
        "content": "### **Main Overview**\n\n\n> #### \ud83d\ude80 **YouTube Viral Video Detector** \ud83d\ude80\n>\n> Welcome! This workflow automates the discovery and analysis of potentially viral YouTube videos for any niche.\n>\n> **How it works:**\n> 1.  **Searches** for recent, popular YouTube videos based on your keyword.\n> 2.  **Gathers stats** for each video and its channel.\n> 3.  **Calculates** an \"Algorithmic Lift Score\" to identify videos with high viral potential.\n> 4.  **Uses an AI agent** to analyze the top 5 videos and generate an insightful summary.\n> 5.  **Sends you an email** with the AI-powered analysis.\n\n> You may also schedule a trigger \n( default: once daily )\n\n\n\n> **\u27a1\ufe0f To get started, follow the 3 setup steps in the other sticky notes!**\n\n**author: gclbck**"
      },
      "typeVersion": 1
    },
    {
      "id": "a66fd69c-4657-4dd5-8ffc-0388823bfb1f",
      "name": "Limit",
      "type": "n8n-nodes-base.limit",
      "position": [
        592,
        -144
      ],
      "parameters": {
        "maxItems": 5
      },
      "typeVersion": 1
    },
    {
      "id": "9631c00a-9440-42e7-aaae-15fb11163292",
      "name": "Aggregate",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        720,
        -144
      ],
      "parameters": {
        "options": {},
        "aggregate": "aggregateAllItemData"
      },
      "typeVersion": 1
    },
    {
      "id": "c2a0b8d8-a7b3-4b7e-a9ba-e4ac319bbfa7",
      "name": "Markdown",
      "type": "n8n-nodes-base.markdown",
      "position": [
        1232,
        -144
      ],
      "parameters": {
        "mode": "markdownToHtml",
        "options": {},
        "markdown": "={{ $json.output }}"
      },
      "typeVersion": 1
    },
    {
      "id": "db2e6eb2-24ca-4cf7-895e-4fba6f70b33c",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        32,
        -1136
      ],
      "parameters": {
        "width": 656,
        "height": 480,
        "content": "### **1- Setup Node Configuration**\n\n> #### \u2699\ufe0f **Configure Your Search** \u2699\ufe0f\n>\n> Double-click the **'Setup'** node to define your search parameters.\n>\n> *   **`query`**: The keyword or niche you want to search for (e.g., \"AI\", \"Marketing\", \"Productivity\").\n> *   **`GoogleAPIkey`**: Your Google API key is required to use the YouTube Data API.\n>     *   **How to get a key:**\n>         1.  Go to the [Google Cloud Console](https://console.cloud.google.com/).\n>         2.  Create a new project.\n>         3.  In the API Library, find and enable the **\"YouTube Data API v3\"**.\n>         4.  Go to \"Credentials\" and create a new **\"API key\"**.\n> *   **`daysback`**: How many days in the past to search for videos (e.g., `3` for the last 3 days).\n> *   **`maxResult`**: The number of videos to retrieve for analysis (e.g., `20`). ( avoid higher than `50` considering rateLimits )\n> *   **`e-mail`**: The e-mail address you want the report to be sent.\n>\n> **ACTION:** Update these fields with your search criteria and your Google API key."
      },
      "typeVersion": 1
    },
    {
      "id": "98a83c31-aaf3-489a-9209-85747dc67ecd",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -1136
      ],
      "parameters": {
        "width": 656,
        "height": 480,
        "content": "### **2- AI Model Setup**\n\n\n> #### \ud83e\udd16 **Connect Your AI Model** \ud83e\udd16\n>\n> This workflow uses an AI model to analyze the video data and generate a summary. This template is pre-configured to use **OpenAI**.\n>\n> **ACTION:**\n> 1.  Click on the **'OpenAI Chat Model'** node.\n> 2.  Under 'Credential', select **'Create New'**.\n> 3.  Enter your **OpenAI API key** to connect your account.\n>\n> **Note on Google Generative AI:**\n> If you prefer to use Google's Generative AI (like Gemini), you must replace the `'OpenAI Chat Model'` node with a `'Google Generative AI Chat Model'` node and then add your Google Generative AI API key to its credentials."
      },
      "typeVersion": 1
    },
    {
      "id": "f57223a9-f021-4dd5-9bc9-b59ef73188df",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1376,
        -1136
      ],
      "parameters": {
        "width": 656,
        "height": 480,
        "content": "### **3- Gmail Account Setup**\n\n\n> #### \ud83d\udce7 **Set Up Email Notifications** \ud83d\udce7\n>\n> This final step sends the AI-generated analysis to your email address using Gmail.\n>\n> **ACTION:**\n> 1.  Click on the **'Send Mail'** node.\n> 2.  Under 'Credential', select **'Create New'** to connect your Gmail account. You will be prompted to sign in with Google and grant n8n the necessary permissions.\n> 3.  In the **'Send To'** field, replace the placeholder email with the address where you want to receive the report.\n>\n> **\u2705 Once these 3 steps are complete, you are ready to activate the workflow!**"
      },
      "typeVersion": 1
    },
    {
      "id": "dd7a3947-55e0-4077-8f99-dacb48f9a123",
      "name": "Send_Report",
      "type": "n8n-nodes-base.gmail",
      "position": [
        1440,
        -144
      ],
      "parameters": {
        "sendTo": "={{$('Setup').item.json.email}}",
        "message": "={{ $json.data }}",
        "options": {
          "appendAttribution": false
        },
        "subject": "=Virality analysis of the last {{ $('Setup').item.json.daysback }} days for keyword: \"{{ $('Setup').item.json.query }}\""
      },
      "credentials": {
        "gmailOAuth2": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.1
    }
  ],
  "connections": {
    "Sort": {
      "main": [
        [
          {
            "node": "Limit",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Limit": {
      "main": [
        [
          {
            "node": "Aggregate",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Remove_Duplicates",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Setup": {
      "main": [
        [
          {
            "node": "SearchVideos",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Think": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "AI Agent": {
      "main": [
        [
          {
            "node": "Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Markdown": {
      "main": [
        [
          {
            "node": "Send_Report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "VidStats": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Aggregate": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out1": {
      "main": [
        [
          {
            "node": "Split Out2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out2": {
      "main": [
        [
          {
            "node": "GetChannelInfo",
            "type": "main",
            "index": 0
          },
          {
            "node": "GetVidStats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ChannelInfo": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetVidStats": {
      "main": [
        [
          {
            "node": "VidStats",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send_Report": {
      "main": [
        []
      ]
    },
    "SearchVideos": {
      "main": [
        [
          {
            "node": "Split Out1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GetChannelInfo": {
      "main": [
        [
          {
            "node": "ChannelInfo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CalculateMetrics": {
      "main": [
        [
          {
            "node": "AlgorithmicLiftScore",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Setup",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Remove_Duplicates": {
      "main": [
        [
          {
            "node": "CalculateMetrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "AlgorithmicLiftScore": {
      "main": [
        [
          {
            "node": "Sort",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "When clicking \u2018Test workflow\u2019": {
      "main": [
        [
          {
            "node": "Setup",
            "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

This workflow automates the discovery and analysis of potentially viral YouTube videos. It searches for recent, popular videos based on a keyword, calculates a unique "Algorithmic Lift Score" to measure virality, and uses an AI agent to generate an insightful summary report that…

Source: https://n8n.io/workflows/8368/ — 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

This n8n workflow is designed for e-commerce businesses, digital marketers, and content creators who want to automatically generate professional 3D product videos from product images. It's perfect for

Form Trigger, Google Drive, HTTP Request +9
AI & RAG

E-mail Assistant Agent. Uses gmailTrigger, textClassifier, gmail, lmChatOpenAi. Event-driven trigger; 29 nodes.

Gmail Trigger, Text Classifier, Gmail +6
AI & RAG

Marketing, growth, and analytics teams who want a decision-ready GA4 summary—automatically calculated, clearly color-coded, and emailed as a polished HTML report. Get Client (Form Trigger) collects GA

OpenAI Chat, Tool Calculator, Agent +4
AI & RAG

🎯 Create viral TikToks, Shorts, Reels, podcasts, and ASMR videos in minutes — all on autopilot.

OpenAI, HTTP Request, Form Trigger +7
AI & RAG

Generate AI viral videos with NanoBanana & VEO3, shared on socials via Blotato 2. Uses @blotato/n8n-nodes-blotato, googleSheets, lmChatOpenAi, toolThink. Event-driven trigger; 94 nodes.

@Blotato/N8N Nodes Blotato, Google Sheets, OpenAI Chat +9