{
  "name": "Send a weekly campaign report of new B2B website visitors with Webmetic, OpenAI and Outlook",
  "nodes": [
    {
      "id": "a4efa24f-fe63-5446-9245-0fb2cb6ddcb3",
      "name": "Overview",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -560,
        0
      ],
      "parameters": {
        "content": "## Show which campaigns bring which companies\n\nWhich campaign brought which companies? Every Monday, this workflow collects the companies that visited your website for the first time last week, groups them by source and campaign, lets OpenAI write a short report and e-mails it to marketing and sales with Microsoft Outlook.\n\n### Who's it for\nB2B marketing teams who want to show which campaigns bring real companies, not just clicks.\n\n### How it works\n1. **Get new visits** returns the companies Webmetic identified for the first time in the last 7 days.\n2. Each company gets the source and campaign of its first visit, from the UTM parameters.\n3. Companies are counted per source and campaign, best lead scores first.\n4. OpenAI writes the report: summary, table, notable companies per paid campaign and a budget tip.\n5. Outlook sends it to the recipients in **Settings**.\n\n### Setup\n1. Copy the **Visitor Intelligence** API key from [Webmetic API keys](https://app.webmetic.de/?menu=api_details).\n2. Fill in **Settings**: domain, recipients and report language.\n3. Connect OpenAI and Microsoft Outlook. About 5 minutes.\n\n### Requirements\n- A Webmetic account. This workflow uses no credits.\n- The Webmetic node, verified by n8n, on n8n Cloud or self-hosted.\n- OpenAI and an e-mail account.\n\n### Customize\nChange day and time in **Every Monday at 8**, or swap Outlook for Gmail or Teams. Campaign names come from the UTM parameters of your ads.\n\n[More Webmetic workflows](https://webmetic.de/n8n)",
        "height": 940,
        "width": 500
      }
    },
    {
      "id": "74e1de9f-4599-5084-9e04-f04ade367320",
      "name": "Section: new companies",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -40,
        100
      ],
      "parameters": {
        "content": "## 1. New companies of the week\nFirst visits in the last 7 days",
        "height": 340,
        "width": 600,
        "color": 7
      }
    },
    {
      "id": "a36910b6-188a-5d9e-886d-23182f89f8fb",
      "name": "Section: count",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        600,
        100
      ],
      "parameters": {
        "content": "## 2. Count per source and campaign\nSource and campaign of the first visit",
        "height": 340,
        "width": 840,
        "color": 7
      }
    },
    {
      "id": "41c57d3b-23c2-59ef-88b0-d6f2cddee23d",
      "name": "Section: report",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1460,
        100
      ],
      "parameters": {
        "content": "## 3. AI report by e-mail\nSummary, table and budget tip",
        "height": 560,
        "width": 580,
        "color": 7
      }
    },
    {
      "id": "096dfb98-6148-518b-bb59-e57e52c013a1",
      "name": "Every Monday at 8",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.3,
      "position": [
        0,
        240
      ],
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      }
    },
    {
      "id": "84900a97-ceb3-56a7-b8d0-299a8ceaacfe",
      "name": "Settings",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        220,
        240
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "909516f9-89e0-5783-bd30-a4ed6476d613",
              "name": "domain",
              "value": "example.com",
              "type": "string"
            },
            {
              "id": "38f63c5f-2cfb-55af-9946-b5eb9a4d67ad",
              "name": "reportTo",
              "value": "marketing@example.com, sales@example.com",
              "type": "string"
            },
            {
              "id": "794caaec-4b0e-5e8e-9acf-8ab3ec9ae66a",
              "name": "language",
              "value": "English",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "5584a722-a1fe-5a99-821f-91568bc1ae9d",
      "name": "Get new visits",
      "type": "n8n-nodes-webmetic.webmetic",
      "typeVersion": 2,
      "position": [
        440,
        240
      ],
      "parameters": {
        "resource": "newVisits",
        "operation": "get",
        "domain": "={{ $json.domain }}",
        "additionalFields": {
          "from_date": "-7 days",
          "to_date": "now"
        }
      }
    },
    {
      "id": "cd9b1b2a-9c34-5bf7-b103-916eefadbe5d",
      "name": "Add source and campaign",
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        660,
        240
      ],
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "172c0486-bed0-5db4-897f-16fbb9fe68af",
              "name": "company",
              "value": "={{ $json.company_name }}",
              "type": "string"
            },
            {
              "id": "65da0aa9-a491-50dc-ad62-6449678e507a",
              "name": "leadScore",
              "value": "={{ $json.lead_score ?? 0 }}",
              "type": "number"
            },
            {
              "id": "f871231f-3fd6-5442-a046-602c89ac83fc",
              "name": "source",
              "value": "={{ [$json.utm_source, $json.utm_medium].filter(Boolean).join(' / ') || '(direct)' }}",
              "type": "string"
            },
            {
              "id": "5c76fe50-0037-5643-83f8-fedda6c3fae1",
              "name": "campaign",
              "value": "={{ $json.utm_campaign || '(none)' }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "fa67ecfe-687f-5f7d-85f6-fd62afb58795",
      "name": "Sort by lead score",
      "type": "n8n-nodes-base.sort",
      "typeVersion": 1,
      "position": [
        880,
        240
      ],
      "parameters": {
        "type": "simple",
        "sortFieldsUi": {
          "sortField": [
            {
              "fieldName": "leadScore",
              "order": "descending"
            }
          ]
        },
        "options": {}
      }
    },
    {
      "id": "c57a18b4-7e22-5a5d-9cf4-ab3ee02319f0",
      "name": "Count per source and campaign",
      "type": "n8n-nodes-base.summarize",
      "typeVersion": 1.1,
      "position": [
        1100,
        240
      ],
      "parameters": {
        "fieldsToSummarize": {
          "values": [
            {
              "aggregation": "count",
              "field": "company"
            },
            {
              "aggregation": "concatenate",
              "field": "company",
              "separateBy": ", "
            }
          ]
        },
        "fieldsToSplitBy": "source,campaign",
        "options": {}
      }
    },
    {
      "id": "15e00ac4-1d5c-5ca9-8ba2-534658429add",
      "name": "Collect into one list",
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1320,
        240
      ],
      "parameters": {
        "aggregate": "aggregateAllItemData",
        "destinationFieldName": "rows",
        "options": {}
      }
    },
    {
      "id": "0569ce64-4826-50ff-b5ba-16bfc29f228a",
      "name": "Write the report",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 3.1,
      "position": [
        1540,
        240
      ],
      "parameters": {
        "promptType": "define",
        "text": "=Write a short weekly report about the companies that visited our website for the first time in the last 7 days.\n\nDATA\n- New companies in total: {{ $('Get new visits').all().length }}\n- One row per traffic source and campaign. count_company is the number of companies, concatenated_company lists them, best lead score first:\n{{ JSON.stringify($json.rows) }}\n\nWRITE\n1. Summary in two sentences: how many companies, and which source and campaign brought the most.\n2. A table with source, campaign and number of companies. Use readable names: google / cpc = Google Ads, bing / cpc = Microsoft Ads, linkedin = LinkedIn, facebook or instagram with cpc or paid = Meta Ads, organic = organic search, (direct) = direct.\n3. For each paid campaign, up to 5 of its companies.\n4. One recommendation for next week's budget.\n\nRULES: Write in {{ $('Settings').first().json.language }}. No filler. Output simple HTML using only h3, p, table, tr, th, td, ul and li.",
        "options": {}
      }
    },
    {
      "id": "e82aee71-dbb2-52b6-b328-bb6ee3df591f",
      "name": "OpenAI Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.3,
      "position": [
        1560,
        460
      ],
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-5-mini"
        },
        "options": {}
      }
    },
    {
      "id": "d02ef6fd-44fb-5504-a9f6-807851fa6cd7",
      "name": "Send the report",
      "type": "n8n-nodes-base.microsoftOutlook",
      "typeVersion": 2,
      "position": [
        1880,
        240
      ],
      "parameters": {
        "resource": "message",
        "operation": "send",
        "toRecipients": "={{ $('Settings').first().json.reportTo }}",
        "subject": "=New companies on your website: {{ $('Get new visits').all().length }} last week",
        "bodyContent": "={{ $json.output }}",
        "additionalFields": {
          "bodyContentType": "html"
        }
      }
    }
  ],
  "connections": {
    "OpenAI Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Write the report",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday at 8": {
      "main": [
        [
          {
            "node": "Settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Settings": {
      "main": [
        [
          {
            "node": "Get new visits",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get new visits": {
      "main": [
        [
          {
            "node": "Add source and campaign",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Add source and campaign": {
      "main": [
        [
          {
            "node": "Sort by lead score",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Sort by lead score": {
      "main": [
        [
          {
            "node": "Count per source and campaign",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Count per source and campaign": {
      "main": [
        [
          {
            "node": "Collect into one list",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Collect into one list": {
      "main": [
        [
          {
            "node": "Write the report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the report": {
      "main": [
        [
          {
            "node": "Send the report",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1"
  },
  "pinData": {},
  "meta": {
    "templateCredsSetupCompleted": false
  }
}
