{
  "id": "MGOnqM23N4in-dto9pS_O",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Autonomous Traffic Spike Reporting: Databox, AI & Slack",
  "tags": [],
  "nodes": [
    {
      "id": "7e82b8dd-cf18-4fda-b160-de9c120cbd25",
      "name": "Hourly Traffic Monitor1",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -1568,
        2736
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10
            }
          ]
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "e1f9d565-9daf-4c35-86f0-1cfd95147810",
      "name": "GPT-4o Model1",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        208,
        2896
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {},
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "retryOnFail": true,
      "typeVersion": 1.3,
      "waitBetweenTries": 5000
    },
    {
      "id": "c4e3bb9f-4b1d-4196-8fd4-f99d13060d71",
      "name": "Format Slack Report2",
      "type": "n8n-nodes-base.set",
      "position": [
        560,
        2736
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "id-1",
              "name": "report_text",
              "type": "string",
              "value": "={{ $json.output }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "9d37b88f-8c35-48b2-9b06-2823d10364d7",
      "name": "Send Investigation Report1",
      "type": "n8n-nodes-base.slack",
      "position": [
        784,
        2736
      ],
      "parameters": {
        "text": "={{ $json.report_text }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ATWRVRR27",
          "cachedResultName": "databox-traffic-spike"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "eada3a90-4ae3-44d7-a4b0-d6e27ccd3d59",
      "name": "Merge1",
      "type": "n8n-nodes-base.merge",
      "position": [
        -528,
        2640
      ],
      "parameters": {
        "numberInputs": 8
      },
      "executeOnce": true,
      "typeVersion": 3.2
    },
    {
      "id": "ca04449f-757d-4b44-8ab6-e755685ac9e1",
      "name": "Code in JavaScript4",
      "type": "n8n-nodes-base.code",
      "position": [
        -16,
        2736
      ],
      "parameters": {
        "jsCode": "// Access the first (and only) item from the Aggregate node\nconst input = $input.first().json;\nconst content = input.content;\n\n// Helper to navigate that specific double-array structure\nconst getValue = (index) => {\n  try {\n    // The path is now: content[index][0].text...\n    return content[index][0].text.results[0].data_points[0].value;\n  } catch (e) {\n    return 0;\n  }\n};\n\nreturn [{\n  json: {\n    sessions: {\n      previous: getValue(0),\n      current: getValue(1)\n    },\n    new_users: {\n      previous: getValue(2),\n      current: getValue(3)\n    },\n    ads_cost: {\n      previous: getValue(4),\n      current: getValue(5)\n    },\n    ads_clicks: {\n      previous: getValue(6),\n      current: getValue(7)\n    }\n  }\n}];"
      },
      "executeOnce": true,
      "typeVersion": 2
    },
    {
      "id": "e8e79f54-fada-4521-8fec-8a3ed5daa349",
      "name": "Aggregate1",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -240,
        2736
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "content"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "50c8b1fc-70ea-447b-becd-6b4259466d3b",
      "name": "Traffic Investigation Agent1",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        208,
        2736
      ],
      "parameters": {
        "text": "=Client name:\n{{ $('Loop Over Items1').item.json.client }}\n\nData:\n{{ JSON.stringify($json, null, 2) }}",
        "options": {
          "systemMessage": "=**Role**: Senior Digital Forensic & Growth Strategist.\n**Objective**: Transform raw multi-period traffic JSON into an elite, high-signal \"Intelligence Briefing\" for agency clients.\n\n**Core Principles**:\n1. **Data Primacy**: Use the provided 'Yesterday vs. Day Before' comparison as the absolute truth.\n2. **Zero-Invention**: Never hallucinate IDs or metrics. If data is missing, omit the section.\n3. **Autonomous Reasoning**: Your value is in the *correlation* (e.g., \"Clicks are up, but Cost is flat = High Efficiency\").\n\n\n**Advanced Diagnostic Framework**:\n- **[A] Viral Synergy**: Traffic spikes + New User surge + Flat Ad Spend + Social Search hits.\n- **[B] Scaling Efficiency**: Proportional spike in both Sessions and Ad Cost + improved Click-Through-Rate (CTR) logic.\n- **[C] Algorithmic Windfall**: Significant Session jump + Clicks flat + Ads flat (Indicates SEO/Discovery gain).\n- **[D] Systemic Anomaly**: Sessions jump with 0% New User growth (Indicative of Bot/Loop traffic).\n\n**Output Rules**:\n- Tone: Professional, authoritative, and fast-paced.\n- Visuals: Use the specific emoji-anchored headers provided below.\n- Limit: Max 400 words. Total focus on actionable insight.\n\n---\nDate and time now: {{ $now }}\n--\n\n### **REPORT TEMPLATE STRUCTURE (Slack-Ready)**\n\n*----- \ud83d\udee1\ufe0f STRATEGIC INTELLIGENCE BRIEF: [Client Name] -----*\n\n\ud83d\udcca *PERFORMANCE DELTA (Yesterday vs. Baseline)*\n- *Traffic*: [Sessions % Change] ([Current] vs [Previous])\n- *Acquisition*: [New Users % Change]\n- *Media Spend*: [Ad Cost % Change] at a [Clicks % Change] Clicks shift.\n\n\ud83d\udca1 *CORE INSIGHT: THE \"WHY\"*\n[A complex, 2-3 sentence analysis of the correlation. Example: \"We observed a decoupling of spend and traffic; while ad costs remained stagnant (+1.2%), organic sessions surged by 70%, suggesting a high-intent discovery event outside of paid channels.\"]\n\n\ud83d\udd75\ufe0f *FORENSIC INVESTIGATION*\n- *External Signals*: [Results from SERP API search. If skipped: \"No external mentions indexed in last 24h.\"]\n- *Pattern Match*: [Identify if it's 'Viral Synergy', 'Scaling Efficiency', etc.]\n\n\ud83c\udfaf *EXECUTIVE HYPOTHESIS*\n*[Bolded Conclusion]*: [One-sentence definitive cause based on data patterns.]\n\n\ud83d\udd25 *EFFICIENCY SCORE*\n[Select one]: \n\ud83d\udfe2 *OPTIMIZED* (High traffic growth, low cost growth)\n\ud83d\udfe1 *STABLE* (Growth tracking with spend)\n\ud83d\udd34 *WASTE ALERT* (High cost growth, low/negative traffic growth)\n\n\ud83d\ude80 *STRATEGIC ACTION ITEM*\n[One high-value directive. Example: \"Capitalize on current organic momentum by increasing Retargeting budgets by 15% to capture the new user surge.\"]\n\n*Analysis complete for: [Current Date]*"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "retryOnFail": true,
      "typeVersion": 3.1,
      "waitBetweenTries": 5000
    },
    {
      "id": "39d79e1a-17fc-40a7-ad04-7068ac41062d",
      "name": "Loop Over Items1",
      "type": "n8n-nodes-base.splitInBatches",
      "position": [
        -1056,
        2736
      ],
      "parameters": {
        "options": {}
      },
      "typeVersion": 3
    },
    {
      "id": "ac622928-eb52-458b-9e42-c364beddde1d",
      "name": "new users",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2560
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.new_users }}",
            "start_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_analytics_4_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "d1846977-cf1a-4a86-a20d-b9edd88c1a5d",
      "name": "ad costs",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2848
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.ad_cost }}",
            "start_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_search_console_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "5c55608f-be41-476e-b251-00a0a7ccd52e",
      "name": "clicks",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        3136
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.clicks }}",
            "start_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_search_console_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "4928fad6-1c2e-4df9-92bb-40b0ef7e0c16",
      "name": "cllicks2",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        3248
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.clicks }}",
            "start_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_search_console_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "9ab8a6c8-d10b-4d15-97ec-fd5590e9b76b",
      "name": "new users2",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2672
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.new_users }}",
            "start_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_analytics_4_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b738f395-1c20-412f-9c84-aa896a3421d8",
      "name": "sessions2",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2384
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.sessions }}",
            "start_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_analytics_4_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3101aaba-32d8-4683-9424-b23e9d4cc6ad",
      "name": "sessions",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2272
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.sessions }}",
            "start_date": "={{ $now.minus({ days: 2 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_analytics_4_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "050df608-2f6c-4678-a228-8901f95f8a0d",
      "name": "Aggregate2",
      "type": "n8n-nodes-base.aggregate",
      "position": [
        -848,
        1824
      ],
      "parameters": {
        "options": {},
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "message.text"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "75307fe5-384c-4604-a7de-fd76a2cce48a",
      "name": "GPT-4o Model2",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "position": [
        -624,
        1984
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "id",
          "value": "gpt-4o"
        },
        "options": {
          "temperature": 0.2
        },
        "builtInTools": {}
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.3
    },
    {
      "id": "14e70b49-0f04-46cb-ba7e-5dccba806059",
      "name": "Traffic Investigation Agent2",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        -624,
        1824
      ],
      "parameters": {
        "text": "={{ $json.text }}",
        "options": {
          "systemMessage": "=**Role**: Senior Operations Lead (Head of Paid Social).\n**Objective**: Transform raw multi-client performance data into a high-level executive briefing. \n\n**Core Protocol**:\n- You are processing an array of client data objects containing Yesterday vs. Day Before metrics.\n- Output exactly one condensed line per client. \n- Use reasoning to determine the \"Why\" behind the data without external tools.\n- Maintain strict Slack-compatible formatting (single asterisks for bold).\n\n**Internal Diagnostic Logic Examples**:\n- *[CRITICAL]*: Drop in Sessions + Spike in Spend = *\ud83d\udd34 BUDGET WASTE ALERT*. Priority 1.\n- *[EFFICIENT]*: Spike in Sessions + Flat Spend = *\ud83d\udfe2 ORGANIC/GHOST WIN*. Priority 2.\n- *[SCALING]*: Spike in Sessions + Spike in Spend = *\ud83d\udfe1 ACTIVE SCALING*. Priority 3.\n- *[DECAY]*: Drop in Sessions + Flat Spend = *\u26aa ENGAGEMENT DECAY*. Priority 4.\n\n**Output Structure (Slack-Ready)**:\n\n\ud83d\ude80 *DAILY MANAGER BRIEFING* \ud83d\ude80\n*Date*: {{ $today.toFormat('DDDD') }}\n\n---\n*CLIENT PERFORMANCE SUMMARIES:*\n- *[Client Name]*: [Emoji Status] [One-sentence insight covering the metric shift, the suspected cause, and the operational urgency].\n- *[Client Name]*: [Emoji Status] [One-sentence insight covering the metric shift, the suspected cause, and the operational urgency].\n\n---\n\ud83d\udca1 *SENIOR STRATEGY NOTE*:\n[A single high-level observation summarizing the aggregate trend across all provided clients to guide agency-wide tactical shifts].\n\n---\n*Operational Pulse Complete.*"
        },
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 3.1
    },
    {
      "id": "d2f91dfc-6b09-4da4-9c2b-ac18d7bb7769",
      "name": "Send Investigation Report2",
      "type": "n8n-nodes-base.slack",
      "position": [
        -272,
        1824
      ],
      "parameters": {
        "text": "={{ $json.output }}",
        "select": "channel",
        "channelId": {
          "__rl": true,
          "mode": "list",
          "value": "C0ATWRVRR27",
          "cachedResultName": "databox-traffic-spike"
        },
        "otherOptions": {
          "includeLinkToWorkflow": false
        }
      },
      "credentials": {
        "slackApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 2.4
    },
    {
      "id": "7ae063c9-ec96-4fe1-9bb4-530c5c2499ca",
      "name": "ad costs2",
      "type": "@n8n/n8n-nodes-langchain.mcpClient",
      "position": [
        -816,
        2960
      ],
      "parameters": {
        "tool": {
          "__rl": true,
          "mode": "list",
          "value": "load_metric_data",
          "cachedResultName": "load_metric_data"
        },
        "options": {},
        "parameters": {
          "value": {
            "end_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "metric_key": "={{ $json.metrics.ad_cost }}",
            "start_date": "={{ $now.minus({ days: 1 }).toFormat('yyyy-MM-dd') }}",
            "data_source_id": "={{ $json.google_search_console_data_source_id }}"
          },
          "schema": [
            {
              "id": "data_source_id",
              "type": "number",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "data_source_id",
              "defaultMatch": false
            },
            {
              "id": "metric_key",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "metric_key",
              "defaultMatch": false
            },
            {
              "id": "start_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "start_date",
              "defaultMatch": false
            },
            {
              "id": "end_date",
              "type": "string",
              "display": true,
              "removed": false,
              "required": true,
              "displayName": "end_date",
              "defaultMatch": false
            },
            {
              "id": "dimension",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "dimension",
              "defaultMatch": false
            },
            {
              "id": "granulation_time_unit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "granulation_time_unit",
              "defaultMatch": false
            },
            {
              "id": "is_whole_range",
              "type": "boolean",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "is_whole_range",
              "defaultMatch": false
            },
            {
              "id": "record_limit",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "record_limit",
              "defaultMatch": false
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "endpointUrl": "https://mcp.databox.com/mcp",
        "authentication": "mcpOAuth2Api"
      },
      "credentials": {
        "mcpOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3a2c991c-87d8-466a-bffa-e2eda59cb02f",
      "name": "Set client data",
      "type": "n8n-nodes-base.code",
      "position": [
        -1328,
        2736
      ],
      "parameters": {
        "jsCode": "return [\n  {\n    json: {\n      client: \"Acme Retail\",\n      google_analytics_4_data_source_id: 4952808,\n      google_search_console_data_source_id: 4952809,\n      metrics: {\n        sessions: \"GoogleAnalytics4@sessions\",\n        new_users: \"GoogleAnalytics4@new_users\",\n        ad_cost: \"GoogleAdwords@cost\",\n        clicks: \"GoogleAdwords@clicks\"\n      }\n    }\n  },\n  {\n    json: {\n      client: \"BlueWave Agency\",\n      google_analytics_4_data_source_id: 4952811,\n      google_search_console_data_source_id: 4952812,\n      metrics: {\n        sessions: \"GoogleAnalytics4@sessions\",\n        new_users: \"GoogleAnalytics4@new_users\",\n        ad_cost: \"GoogleAdwords@cost\",\n        clicks: \"GoogleAdwords@clicks\"\n      }\n    }\n  },\n  {\n    json: {\n      client: \"Nexus Health\",\n      google_analytics_4_data_source_id: 4952814,\n      google_search_console_data_source_id: 4952815,\n      metrics: {\n        sessions: \"GoogleAnalytics4@sessions\",\n        new_users: \"GoogleAnalytics4@new_users\",\n        ad_cost: \"GoogleAdwords@cost\",\n        clicks: \"GoogleAdwords@clicks\"\n      }\n    }\n  }\n];"
      },
      "typeVersion": 2
    },
    {
      "id": "852530a9-110e-4d1c-8bec-618edf5742c3",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -2448,
        1696
      ],
      "parameters": {
        "width": 672,
        "height": 1568,
        "content": "# Autonomous Traffic Spike Reporting: Databox, AI & Slack\n\nThis workflow gives PPC agencies and performance teams a daily traffic and performance check across multiple clients using Databox data.\n\nIt pulls yesterday\u2019s and day-before-yesterday\u2019s data for key metrics, compares changes, analyzes the results with AI, and sends both client-level and cross-client reports to Slack.\n\n## Who\u2019s it for\n\n* PPC agencies managing multiple client accounts\n* Performance marketing teams tracking daily traffic changes\n* Account managers who need fast visibility into client performance\n* Operations leads who want a daily cross-client summary\n\n## How it works\n\n* A daily trigger starts the workflow.\n* The first Code node stores the client list and Databox metric setup.\n* The loop processes each client one by one.\n* Databox pulls yesterday and day-before-yesterday data for:\n  * Sessions\n  * New users\n  * Ad cost\n  * Clicks\n* The workflow merges and formats the metric data.\n* AI checks for traffic spikes, drops, and unusual performance changes.\n* A client-level Slack report is sent for each client.\n* After all clients are processed, a second AI agent creates a leadership summary across all clients.\n* The final cross-client report is sent to Slack.\n\n## How to set up\n\n1. Connect the **Databox MCP Client Tool** with your endpoint and authentication headers.\n2. Add your clients in the first **Code** node, including:\n   * Client name\n   * Databox data source IDs\n   * Metric keys for sessions, new users, ad cost, and clicks\n3. Connect your **OpenAI** credentials.\n4. Connect the **Slack** nodes to the right channels.\n5. Adjust the daily schedule if needed.\n\nYou can ask **Databox Genie** to provide the correct data source IDs and metric keys for each client, then format them in the same structure as the example Code node.\n\n## Requirements\n\n* n8n 1.0+\n* Databox MCP access\n* Metrics available in Databox for each client\n* OpenAI credentials\n* Slack workspace\n\n## Output\n\nThe workflow sends two reports:\n\n* **Client-level report:** highlights daily traffic spikes, drops, and metric changes for each client.\n* **Leadership report:** summarizes performance changes and priority risks across all processed clients."
      },
      "typeVersion": 1
    },
    {
      "id": "52522f3e-3fe7-48ac-b1d0-d5390a793654",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -1696,
        2640
      ],
      "parameters": {
        "color": 7,
        "width": 804,
        "height": 300,
        "content": "## 1. Daily Client Data Setup\nRuns every day, loads the client list, and loops through each client one by one."
      },
      "typeVersion": 1
    },
    {
      "id": "a9276e83-1b7a-473f-94df-057bdcdb3be0",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -880,
        2128
      ],
      "parameters": {
        "color": 7,
        "width": 308,
        "height": 1288,
        "content": "## 2. Databox Metric Pull\nPulls yesterday and day-before-yesterday data from Databox for sessions, new users, ad cost, and clicks."
      },
      "typeVersion": 1
    },
    {
      "id": "6cd7afa2-d7f3-44fc-94dd-ee524251edc6",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -560,
        2512
      ],
      "parameters": {
        "color": 7,
        "width": 1600,
        "height": 612,
        "content": "## 3. Client-Level Traffic Report\nMerges and formats the metric data, then AI checks for traffic spikes, drops, and unusual performance changes for each client."
      },
      "typeVersion": 1
    },
    {
      "id": "3aa15d40-636a-4719-852c-2038c6aad589",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -944,
        1696
      ],
      "parameters": {
        "color": 7,
        "width": 876,
        "height": 396,
        "content": "## 4. Cross-Client Leadership Summary\nAfter all clients are processed, AI creates a combined daily overview and sends the final report to Slack."
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "availableInMCP": false,
    "executionOrder": "v1"
  },
  "versionId": "1fd96e79-a4ea-4fd6-b9f1-5e1f00dbcd7c",
  "connections": {
    "Merge1": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "clicks": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 6
          }
        ]
      ]
    },
    "ad costs": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 4
          }
        ]
      ]
    },
    "cllicks2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 7
          }
        ]
      ]
    },
    "sessions": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "ad costs2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 5
          }
        ]
      ]
    },
    "new users": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "sessions2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Code in JavaScript4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate2": {
      "main": [
        [
          {
            "node": "Traffic Investigation Agent2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "new users2": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 3
          }
        ]
      ]
    },
    "GPT-4o Model1": {
      "ai_languageModel": [
        [
          {
            "node": "Traffic Investigation Agent1",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "GPT-4o Model2": {
      "ai_languageModel": [
        [
          {
            "node": "Traffic Investigation Agent2",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Set client data": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Items1": {
      "main": [
        [
          {
            "node": "Aggregate2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "sessions",
            "type": "main",
            "index": 0
          },
          {
            "node": "sessions2",
            "type": "main",
            "index": 0
          },
          {
            "node": "new users",
            "type": "main",
            "index": 0
          },
          {
            "node": "new users2",
            "type": "main",
            "index": 0
          },
          {
            "node": "ad costs",
            "type": "main",
            "index": 0
          },
          {
            "node": "clicks",
            "type": "main",
            "index": 0
          },
          {
            "node": "cllicks2",
            "type": "main",
            "index": 0
          },
          {
            "node": "ad costs2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code in JavaScript4": {
      "main": [
        [
          {
            "node": "Traffic Investigation Agent1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Format Slack Report2": {
      "main": [
        [
          {
            "node": "Send Investigation Report1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Hourly Traffic Monitor1": {
      "main": [
        [
          {
            "node": "Set client data",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send Investigation Report1": {
      "main": [
        [
          {
            "node": "Loop Over Items1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Traffic Investigation Agent1": {
      "main": [
        [
          {
            "node": "Format Slack Report2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Traffic Investigation Agent2": {
      "main": [
        [
          {
            "node": "Send Investigation Report2",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}