Weekly leads by source, compared with last week
Every Monday, see how many leads each channel brought this week versus last week, on Slack.
How it works
Trigger: Schedule — Mondays at 9:00
- Read the Leads sheet (date, source).
- Count this week's and last week's leads by source.
- Post the comparison to your marketing channel.
Diagram
Trigger App Code
Code
JavaScript used in the Code step — already included in the template below.
// Leads sheet columns: date (YYYY-MM-DD) | name | source (utm_source, "instagram", "referral"…) | stage
// Counts last week's leads by source, compared with the week before.
const DAY = 24 * 60 * 60 * 1000;
const day = (n) => new Date(Date.now() - n * DAY).toISOString().slice(0, 10);
const [thisStart, lastStart] = [day(7), day(14)];
const count = { now: {}, before: {} };
for (const { json: l } of $input.all()) {
const d = String(l.date).slice(0, 10);
const src = String(l.source || "direct").trim().toLowerCase();
if (d >= thisStart) count.now[src] = (count.now[src] || 0) + 1;
else if (d >= lastStart) count.before[src] = (count.before[src] || 0) + 1;
}
const sources = [...new Set([...Object.keys(count.now), ...Object.keys(count.before)])]
.sort((a, b) => (count.now[b] || 0) - (count.now[a] || 0));
const total = Object.values(count.now).reduce((a, b) => a + b, 0);
const lines = sources.map((s) => {
const n = count.now[s] || 0;
const diff = n - (count.before[s] || 0);
return `• ${s}: ${n} (${diff >= 0 ? "+" : ""}${diff} vs last week)`;
});
return [{ json: { message: `📊 Leads this week: ${total}\n${lines.join("\n") || "No leads."}` } }];Build it
Pick your tool — same automation, step by step.
Copy and paste straight into an n8n canvas (Ctrl+V), or download and use Import from File. Then connect your own credentials and replace every YOUR_… placeholder.
Show code (140 lines)
{
"name": "Weekly leads by source, compared with last week (Flowngn)",
"nodes": [
{
"parameters": {
"content": "## Weekly leads by source, compared with last week\nEvery Monday, see how many leads each channel brought this week versus last week, on Slack.\n\n**Setup**\n1. Open each node and connect your own credentials.\n2. Replace every YOUR_… placeholder.\n3. Test once, then activate.\n\nFree template from Flowngn",
"height": 260,
"width": 340
},
"id": "3f36aaf0-8bb5-49c1-a1a3-cee797bcfadd",
"name": "Setup notes",
"type": "n8n-nodes-base.stickyNote",
"typeVersion": 1,
"position": [
-420,
-60
]
},
{
"parameters": {
"rule": {
"interval": [
{
"field": "cronExpression",
"expression": "0 9 * * 1"
}
]
}
},
"id": "3f36aaf0-8bb5-49c1-a1a3-cee797bcfadd",
"name": "Mondays 9:00",
"type": "n8n-nodes-base.scheduleTrigger",
"typeVersion": 1.2,
"position": [
0,
0
]
},
{
"parameters": {
"operation": "read",
"documentId": {
"__rl": true,
"value": "YOUR_SPREADSHEET_ID",
"mode": "id"
},
"sheetName": {
"__rl": true,
"value": "Leads",
"mode": "name"
},
"options": {}
},
"id": "3f36aaf0-8bb5-49c1-a1a3-cee797bcfadd",
"name": "Read leads",
"type": "n8n-nodes-base.googleSheets",
"typeVersion": 4.5,
"position": [
300,
0
]
},
{
"parameters": {
"jsCode": "// Leads sheet columns: date (YYYY-MM-DD) | name | source (utm_source, \"instagram\", \"referral\"…) | stage\n// Counts last week's leads by source, compared with the week before.\nconst DAY = 24 * 60 * 60 * 1000;\nconst day = (n) => new Date(Date.now() - n * DAY).toISOString().slice(0, 10);\nconst [thisStart, lastStart] = [day(7), day(14)];\n\nconst count = { now: {}, before: {} };\nfor (const { json: l } of $input.all()) {\n const d = String(l.date).slice(0, 10);\n const src = String(l.source || \"direct\").trim().toLowerCase();\n if (d >= thisStart) count.now[src] = (count.now[src] || 0) + 1;\n else if (d >= lastStart) count.before[src] = (count.before[src] || 0) + 1;\n}\n\nconst sources = [...new Set([...Object.keys(count.now), ...Object.keys(count.before)])]\n .sort((a, b) => (count.now[b] || 0) - (count.now[a] || 0));\nconst total = Object.values(count.now).reduce((a, b) => a + b, 0);\nconst lines = sources.map((s) => {\n const n = count.now[s] || 0;\n const diff = n - (count.before[s] || 0);\n return `• ${s}: ${n} (${diff >= 0 ? \"+\" : \"\"}${diff} vs last week)`;\n});\n\nreturn [{ json: { message: `📊 Leads this week: ${total}\\n${lines.join(\"\\n\") || \"No leads.\"}` } }];"
},
"id": "3f36aaf0-8bb5-49c1-a1a3-cee797bcfadd",
"name": "Count by source",
"type": "n8n-nodes-base.code",
"typeVersion": 2,
"position": [
600,
0
]
},
{
"parameters": {
"select": "channel",
"channelId": {
"__rl": true,
"value": "#marketing",
"mode": "name"
},
"text": "={{ $json.message }}",
"otherOptions": {}
},
"id": "3f36aaf0-8bb5-49c1-a1a3-cee797bcfadd",
"name": "Post to marketing",
"type": "n8n-nodes-base.slack",
"typeVersion": 2.2,
"position": [
900,
0
]
}
],
"connections": {
"Mondays 9:00": {
"main": [
[
{
"node": "Read leads",
"type": "main",
"index": 0
}
]
]
},
"Read leads": {
"main": [
[
{
"node": "Count by source",
"type": "main",
"index": 0
}
]
]
},
"Count by source": {
"main": [
[
{
"node": "Post to marketing",
"type": "main",
"index": 0
}
]
]
}
},
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"meta": {
"templateCredsSetupCompleted": false
},
"tags": []
}In Make, create a new scenario and add these modules in order:
- Schedule the scenario: Mondays 9:00
- Google Sheets › Search Rows
- Tools › Set variable / Iterator + Array aggregator (same logic as the Code step)
- Slack › Create a Message
- Every module run uses Make operations — the free plan includes a monthly quota.
- Make's built-in functions (map, sum, formatDate…) can replace most Code steps; for complex logic use a code module.
- Module and step names can differ slightly as Make and Zapier update their apps.
In Zapier, create a new Zap and add these steps in order:
- Schedule by Zapier — Mondays 9:00
- Google Sheets — Lookup Spreadsheet Rows (or Code by Zapier)
- Code by Zapier — Run JavaScript (paste the code from the Code section)
- Slack — Send Channel Message
- Zaps with more than two steps need a paid Zapier plan.
- Webhooks, Filters/Paths and Code by Zapier are premium features on some Zapier plans.
- Code by Zapier runs JavaScript: reuse the code shown above, reading inputs from inputData instead of $json.
- Module and step names can differ slightly as Make and Zapier update their apps.
Tips
- Save utm_source from every form so the source column fills itself.
Related flows
MarketingEasy
Facebook Lead Ads → Google Sheets + Slack
Every new lead from your Facebook or Instagram ads lands in a sheet and pings your team.
Facebook Lead Ads → Google Sheets → Slack6h/mo
MarketingAdvanced
Competitor price change monitor
Check public product pages daily and get notified when a price changes.
HTTP Request → Google Sheets → Gmail5h/mo
MarketingEasy
Reddit brand mention alerts
Get a Slack message whenever someone mentions your brand or keyword on Reddit.
RSS → Slack3h/mo