{
  "id": "5yT7sA01kGAY5Teu",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Lighthouse Report",
  "tags": [],
  "nodes": [
    {
      "id": "9d96468e-d03c-4180-8e2b-71e60ab7c3f5",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        -192,
        96
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "minutes"
            }
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "be628d83-99c4-4f70-ac3c-a0fc3c008f3a",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        656,
        272
      ],
      "parameters": {
        "options": {}
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6e16b71b-65d0-40cd-91ca-469935fe9dbf",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        512,
        -32
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "or",
          "conditions": [
            {
              "id": "0ac8b99f-03f3-4ce5-bee3-0bdb85764dad",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['first-contentful-paint'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "f230a71d-c8ee-47e8-970e-1ebb2c0d5324",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['speed-index'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "b49040c6-eea1-4df8-b8ec-bccbff9dcbc8",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['largest-contentful-paint'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "015ac9bd-2dd4-4cac-a3ea-e8999efd4f68",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['cumulative-layout-shift'].score }}",
              "rightValue": 0.95
            },
            {
              "id": "843fe25a-a1a4-474f-a5b7-53501f7dfe65",
              "operator": {
                "type": "number",
                "operation": "lt"
              },
              "leftValue": "={{ $json.cwv['total-blocking-time'].score }}",
              "rightValue": 0.95
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "640a72fd-312b-4c67-b78a-4ff90eb25df9",
      "name": "Send Notification",
      "type": "n8n-nodes-base.telegram",
      "position": [
        720,
        -128
      ],
      "parameters": {
        "text": "=Reminder: One of the Core Web Vitals has a score below 0.95!\n\nPage: Home\n\nFCP: {{ $json.cwv['first-contentful-paint'].value }}, Score: {{ $json.cwv['first-contentful-paint'].score }}\n\nSpeed Index: {{ $json.cwv['speed-index'].value }}, Score: {{ $json.cwv['largest-contentful-paint'].score }}\n\nTBT: {{ $json.cwv['total-blocking-time'].value }}, Score: {{ $json.cwv['total-blocking-time'].score }}\n\nInteractive: {{ $json.cwv.interactive.value }}, Score: {{ $json.cwv.interactive.score }}\n\nCLS: {{ $json.cwv['cumulative-layout-shift'].value }}, Score: {{ $json.cwv['cumulative-layout-shift'].score }}",
        "additionalFields": {}
      },
      "credentials": {
        "telegramApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "7ebc6e84-0192-45df-a2e3-4d5a01aa3bdc",
      "name": "call page speed insights",
      "type": "n8n-nodes-base.httpRequest",
      "position": [
        32,
        96
      ],
      "parameters": {
        "url": "https://www.googleapis.com/pagespeedonline/v5/runPagespeed",
        "options": {},
        "sendQuery": true,
        "queryParameters": {
          "parameters": [
            {
              "name": "url"
            },
            {
              "name": "key"
            },
            {
              "name": "strategy",
              "value": "mobile"
            }
          ]
        }
      },
      "typeVersion": 4.2
    },
    {
      "id": "242c0cb4-c313-4653-8c33-447968e5753c",
      "name": "processing data cwv and audits",
      "type": "n8n-nodes-base.code",
      "position": [
        352,
        96
      ],
      "parameters": {
        "jsCode": "const cwv = [\n'first-contentful-paint',\n'speed-index',\n'largest-contentful-paint',\n'total-blocking-time',\n'interactive',\n  'cumulative-layout-shift'\n]\n\nconst map = new Map();\n\ncwv.map((item) => {\n  map.set(item, {\n    value: $input.first().json.lighthouseResult.audits[item].displayValue,\n    score: $input.first().json.lighthouseResult.audits[item].score\n  })\n})\n\nconst obj = Object.fromEntries(map);\n\nconst audits = Object.keys($input.first().json.lighthouseResult.audits).filter((key) => !key.includes(cwv))\n\nlet auditsDesc = \"\"\n\naudits.forEach((key) => {\n  auditsDesc += $input.first().json.lighthouseResult.audits[key].title + $input.first().json.lighthouseResult.audits[key].description.replace(/\\[[^\\]]*\\]\\([^)]+\\)/g, '').replace(/\\s{2,}/g, ' ').trim()\n})\n\nreturn [\n  {\n    json: {\n      cwv: obj,\n      audits: auditsDesc\n    }\n  }\n]"
      },
      "typeVersion": 2
    },
    {
      "id": "60380b8b-ec37-44b4-9314-89c82c46a0e6",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -512,
        -208
      ],
      "parameters": {
        "width": 640,
        "height": 208,
        "content": "## Automate Lighthouse report generation to Telegram or other messenger and Google Sheets\n\nThis workflow is ideal for developers, SEO specialists, performance engineers, and digital agencies who want to automatically monitor and log website performance metrics like Core Web Vitals. It\u2019s also helpful for teams who want real-time alerts via Telegram and historical tracking in Google Sheets.\n\n"
      },
      "typeVersion": 1
    },
    {
      "id": "6687d507-bb75-4129-830c-a98fd936841a",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -80,
        288
      ],
      "parameters": {
        "color": 7,
        "content": "Use the PageSpeed Insights API\n\nFollow these guidelines \n\nhttps://developers.google.com/speed/docs/insights/v5/get-started"
      },
      "typeVersion": 1
    },
    {
      "id": "e8799b32-2704-486c-bfc2-b331758b75c3",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        256,
        288
      ],
      "parameters": {
        "color": 7,
        "content": "## Javascript code\n\nProcessing the API response to filter only Core Web Vitals and concatenating all the audit descriptions into one field."
      },
      "typeVersion": 1
    },
    {
      "id": "2e62b919-da7c-4e62-83ae-81dacb6bad16",
      "name": "summarize audit description",
      "type": "@n8n/n8n-nodes-langchain.chainSummarization",
      "position": [
        656,
        96
      ],
      "parameters": {
        "options": {
          "batching": {},
          "summarizationMethodAndPrompts": {
            "values": {
              "prompt": "Acting as a staff web engineer and core web vitals expert, you must create a insightful report to give use the action items for improving the web. Don't mention the role in output.\n\nWrite a concise summary of the following in the list of action items in bullets form without any introduction:\n\n\n\"{text}\"\n"
            }
          }
        },
        "chunkingMode": "advanced"
      },
      "typeVersion": 2.1
    },
    {
      "id": "71e7be4c-ac64-4dd5-a8c9-e70e46c38e8e",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        288,
        -224
      ],
      "parameters": {
        "color": 7,
        "content": "### Send the message only if at least one of the CWV scores is below the desired threshold."
      },
      "typeVersion": 1
    },
    {
      "id": "4eedeb48-cfb0-43aa-b1b0-c842f810c526",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        704,
        -320
      ],
      "parameters": {
        "color": 7,
        "content": "### You can change the messenger with your preference"
      },
      "typeVersion": 1
    },
    {
      "id": "675e51d4-bdec-4753-8dcb-202b786dd8f0",
      "name": "Append row in specific sheet ",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        1040,
        96
      ],
      "parameters": {
        "operation": "append",
        "sheetName": {
          "__rl": true,
          "mode": "name",
          "value": ""
        },
        "documentId": {
          "__rl": true,
          "mode": "url",
          "value": ""
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "6d4d54d3-e5a3-471a-9732-a0660efd44d7",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Send Notification",
            "type": "main",
            "index": 0
          }
        ],
        []
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "call page speed insights",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "summarize audit description",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "call page speed insights": {
      "main": [
        [
          {
            "node": "processing data cwv and audits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "summarize audit description": {
      "main": [
        [
          {
            "node": "Append row in specific sheet ",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "processing data cwv and audits": {
      "main": [
        [
          {
            "node": "summarize audit description",
            "type": "main",
            "index": 0
          },
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}