{
  "name": "Monitor competitors' new ads on Meta, LinkedIn and Google ad libraries weekly with SocialTap and OpenAI",
  "nodes": [
    {
      "parameters": {
        "content": "## Get a weekly brief of your competitors' new ads\n\nEvery Monday it checks the public ad libraries of Meta (Facebook and Instagram), LinkedIn and Google for each competitor, keeps only the ads it hasn't seen before, and emails you what's new with a short brief on their angles and offers.\n\n### How it works\n1. The schedule runs every Monday.\n2. For each competitor, SocialTap finds its Meta page and gets its active ads, searches LinkedIn's Ad Library by advertiser, and gets the ads that lead to its website from Google's Ads Transparency Center.\n3. Ads seen on an earlier run are dropped.\n4. New ads are saved to the **Competitor ads** data table.\n5. OpenAI writes a brief per competitor: themes, offers, calls to action and what changed.\n6. Gmail sends the brief with links to every new ad.\n\nImage and video ads without text are listed with their links but not summarized.\n\n### Setup\n- Install the community node **n8n-nodes-socialtap** (Settings → Community nodes → Install). Tested with n8n 2.49.8 and n8n-nodes-socialtap 1.621.43. Until n8n verifies it, it runs on self-hosted n8n. [Install guide](https://socialtap.dev/docs/integrations/#n8n)\n- Add a **SocialTap API** credential: [create a free account](https://socialtap.dev/signup/?ref=n8n-competitor-ads) and paste its API key. Each operation shows its price, and failed requests are free.\n- Add an **OpenAI** credential to the model node and a **Gmail** credential to the email node.\n- In **Your settings**, list competitors as \"Name, domain\", one per line, and your email.\n\n### Customization\n- Add the TikTok Ad Library (ads shown in Europe) as a fourth branch.\n- Set a country on each ad library node.\n\n![The workflow](https://socialtap.dev/n8n/competitor-ads.svg)",
        "height": 920,
        "width": 600
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -640,
        0
      ],
      "id": "1eab768c-ea49-489a-b3a7-b96fab13628e",
      "name": "Overview"
    },
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "field": "weeks",
              "triggerAtDay": [
                1
              ],
              "triggerAtHour": 8
            }
          ]
        }
      },
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.2,
      "position": [
        0,
        360
      ],
      "id": "f5e153ff-a760-4b75-992a-859832f70fd0",
      "name": "Every Monday"
    },
    {
      "parameters": {
        "content": "## Your settings\nCompetitors as \"Name, domain\", one per line, and where to send the brief.",
        "height": 400,
        "width": 260,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        200,
        140
      ],
      "id": "82084bc4-f927-4a9d-a136-211f9c032b07",
      "name": "Settings note"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "815d636d-380f-4091-b6e2-1dee113a3d8e",
              "name": "competitors",
              "value": "Notion, notion.com\nAsana, asana.com",
              "type": "string"
            },
            {
              "id": "d873f077-eef6-4ac2-8ab4-698995b7afa5",
              "name": "email",
              "value": "you@example.com",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        260,
        360
      ],
      "id": "3015719a-feb4-4236-b186-9ee5e61ce2ad",
      "name": "Your settings"
    },
    {
      "parameters": {
        "resource": "table",
        "operation": "create",
        "tableName": "Competitor ads",
        "columns": {
          "column": [
            {
              "name": "seen_at",
              "type": "string"
            },
            {
              "name": "competitor",
              "type": "string"
            },
            {
              "name": "library",
              "type": "string"
            },
            {
              "name": "ad_id",
              "type": "string"
            },
            {
              "name": "url",
              "type": "string"
            },
            {
              "name": "advertiser",
              "type": "string"
            },
            {
              "name": "first_shown_at",
              "type": "string"
            },
            {
              "name": "headline",
              "type": "string"
            },
            {
              "name": "body",
              "type": "string"
            },
            {
              "name": "cta",
              "type": "string"
            },
            {
              "name": "link",
              "type": "string"
            }
          ]
        },
        "options": {
          "createIfNotExists": true
        }
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        500,
        360
      ],
      "id": "05f51eda-dfbd-4ef8-9e2a-4b0c300859f7",
      "name": "Create table",
      "executeOnce": true
    },
    {
      "parameters": {
        "jsCode": "// \"Name, domain\" per line: the name searches Meta and LinkedIn, the domain Google.\nreturn $('Your settings').first().json.competitors.split('\\n').map((l) => l.split(',').map((x) => x.trim()))\n  .filter(([name]) => name).map(([name, domain = '']) => ({ json: { name, domain } }));"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        720,
        360
      ],
      "id": "d791b11b-c779-4904-8510-df41587fa77c",
      "name": "One item per competitor"
    },
    {
      "parameters": {
        "content": "## 1. Read the ad libraries\nMeta: the page, then its active ads. LinkedIn: by advertiser name. Google: by website. A library that fails is skipped.",
        "height": 640,
        "width": 520,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        920,
        60
      ],
      "id": "8b6ea5dc-9148-41d4-89c5-85857c7290ac",
      "name": "Libraries"
    },
    {
      "parameters": {
        "resource": "facebook-ad-library",
        "operation": "facebook.search_advertisers",
        "query": "={{ $json.name }}",
        "limit": 1
      },
      "type": "n8n-nodes-socialtap.socialTap",
      "typeVersion": 1,
      "position": [
        980,
        160
      ],
      "id": "9f938061-cf81-43dc-8a2f-0ca9a7d6e804",
      "name": "Find the Meta page",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "facebook-ad-library",
        "operation": "facebook.ads",
        "handle": "={{ $json.id }}",
        "limit": 20,
        "additionalFields": {
          "status": "active",
          "sort": "newest"
        }
      },
      "type": "n8n-nodes-socialtap.socialTap",
      "typeVersion": 1,
      "position": [
        1220,
        160
      ],
      "id": "fffaf975-97c5-460c-937d-3dbba1f3c5ed",
      "name": "Meta ads",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "linkedin-ad-library",
        "operation": "linkedin.search_ads",
        "query": "={{ $json.name }}",
        "limit": 20,
        "additionalFields": {
          "search_by": "advertiser",
          "sort": "newest"
        }
      },
      "type": "n8n-nodes-socialtap.socialTap",
      "typeVersion": 1,
      "position": [
        1100,
        360
      ],
      "id": "1a698887-a554-4c3a-a432-32a01b595077",
      "name": "LinkedIn ads",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "resource": "google-ads-transparency",
        "operation": "google.search_ads",
        "query": "={{ $json.domain }}",
        "limit": 20,
        "additionalFields": {
          "sort": "newest"
        }
      },
      "type": "n8n-nodes-socialtap.socialTap",
      "typeVersion": 1,
      "position": [
        1100,
        560
      ],
      "id": "881bc029-624a-4620-b8c3-b1829e81c71f",
      "name": "Google ads",
      "onError": "continueRegularOutput"
    },
    {
      "parameters": {
        "numberInputs": 3
      },
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1500,
        360
      ],
      "id": "8b5bb08f-b256-4bbd-82f9-dace8a944fde",
      "name": "All ads"
    },
    {
      "parameters": {
        "jsCode": "// One row per ad with the competitor it was found for; failed lookups are dropped.\nconst seen_at = $now.toISO();\nconst libraries = { facebook: 'Meta', linkedin: 'LinkedIn', google: 'Google' };\nconst out = [];\n$input.all().forEach(({ json: a }, i) => {\n  if (!a.id || !a.platform) return;\n  const competitor = $('One item per competitor').itemMatching(i)?.json.name ?? '';\n  const advertiser = a.advertiser?.display_name ?? a.advertiser?.username ?? '';\n  // LinkedIn's advertiser search also returns similar names: keep the competitor's own ads.\n  const norm = (s) => s.toLowerCase().replace(/[^a-z0-9]/g, '');\n  if (a.platform === 'linkedin' && !norm(advertiser).includes(norm(competitor))) return;\n  const c = a.creatives?.[0] ?? {};\n  out.push({ json: {\n    seen_at,\n    competitor,\n    library: libraries[a.platform] ?? a.platform,\n    ad_id: a.platform + ':' + a.id,\n    url: a.url ?? '',\n    advertiser,\n    first_shown_at: a.first_shown_at ?? '',\n    headline: (c.title ?? '').slice(0, 300),\n    body: (c.body ?? '').slice(0, 1200),\n    cta: c.cta_text ?? '',\n    link: c.link_url ?? '',\n  } });\n});\nreturn out;"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1720,
        360
      ],
      "id": "ab6b19f4-cb51-41a4-98a3-9f4e51e047f4",
      "name": "Tag each ad"
    },
    {
      "parameters": {
        "operation": "removeItemsSeenInPreviousExecutions",
        "dedupeValue": "={{ $json.ad_id }}",
        "options": {}
      },
      "type": "n8n-nodes-base.removeDuplicates",
      "typeVersion": 2,
      "position": [
        1940,
        360
      ],
      "id": "78fc379b-0a8c-4134-ad8a-0e29a76a1b64",
      "name": "New ads only"
    },
    {
      "parameters": {
        "content": "## 2. Save and brief\nNew ads go to the Competitor ads data table, then OpenAI writes one brief for all competitors. No new ads, no email.",
        "height": 640,
        "width": 1160,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        2140,
        60
      ],
      "id": "0397d147-7dbd-4acd-bb33-19ad0373a23f",
      "name": "Brief"
    },
    {
      "parameters": {
        "resource": "row",
        "operation": "insert",
        "dataTableId": {
          "__rl": true,
          "mode": "id",
          "value": "={{ $('Create table').first().json.id }}"
        },
        "columns": {
          "mappingMode": "autoMapInputData",
          "value": {},
          "matchingColumns": [],
          "schema": [],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.dataTable",
      "typeVersion": 1.1,
      "position": [
        2200,
        360
      ],
      "id": "beae03a7-8a01-4bc7-baef-66eb9a211a58",
      "name": "Save to data table"
    },
    {
      "parameters": {
        "jsCode": "// The new ads as text for the model, grouped by competitor, at most 25 distinct ones each.\nconst by = {};\nfor (const { json: a } of $('New ads only').all()) (by[a.competitor] ??= []).push(a);\n// The same copy run as several ads (sizes, placements) counts once.\nconst lines = (ads) => {\n  const n = {};\n  for (const a of ads) {\n    const line = '- [' + a.library + '] ' + [a.headline, a.body, a.cta && 'CTA: ' + a.cta, a.link && 'Link: ' + a.link].filter(Boolean).join(' | ');\n    n[line] = (n[line] ?? 0) + 1;\n  }\n  return n;\n};\nconst text = Object.entries(by).map(([name, ads]) => {\n  const worded = ads.filter((a) => a.headline || a.body);\n  const silent = ads.length - worded.length;\n  return '## ' + name + ' (' + ads.length + ' new' + (silent ? ', ' + silent + ' of them image or video ads without text' : '') + ')\\n'\n    + Object.entries(lines(worded)).slice(0, 25).map(([line, n]) => line + (n > 1 ? ' (' + n + ' variants)' : '')).join('\\n');\n}).join('\\n\\n');\nreturn [{ json: { text, count: $('New ads only').all().length } }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2420,
        360
      ],
      "id": "0fad00eb-cb4e-4f37-a819-61ea0bebe777",
      "name": "Group by competitor",
      "executeOnce": true
    },
    {
      "parameters": {
        "promptType": "define",
        "text": "={{ $json.text }}",
        "hasOutputParser": false,
        "messages": {
          "messageValues": [
            {
              "message": "You are a competitive analyst. Below are the new ads each competitor started running, from Meta's, LinkedIn's and Google's public ad libraries. For each competitor write:\n- Themes: the angles and messages they push\n- Offers: discounts, trials, launches or events, quoted exactly\n- Calls to action and where they send people\n- One line on what this suggests about their strategy\nBe specific and quote the ads. Never invent an ad. Use simple Markdown: ## per competitor, - bullets."
            }
          ]
        }
      },
      "type": "@n8n/n8n-nodes-langchain.chainLlm",
      "typeVersion": 1.7,
      "position": [
        2640,
        360
      ],
      "id": "a8111df6-82ec-4360-b1d1-68daa4863d64",
      "name": "Write the brief"
    },
    {
      "parameters": {
        "model": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-mini",
          "cachedResultName": "gpt-4.1-mini"
        },
        "options": {
          "temperature": 0.4
        }
      },
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1.2,
      "position": [
        2620,
        580
      ],
      "id": "8e23ab9b-c1f1-4b3b-978e-fab03c17497e",
      "name": "OpenAI"
    },
    {
      "parameters": {
        "jsCode": "const esc = (s) => String(s ?? '').replace(/[&<>\"]/g, (c) => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '\"': '&quot;' })[c]);\nconst md = (s) => {\n  let out = '';\n  let list = false;\n  for (const raw of String(s).split('\\n')) {\n    const l = raw.trim();\n    const li = l.match(/^[-*•]\\s+(.*)$/);\n    if (li) { if (!list) { out += '<ul>'; list = true; } out += '<li>' + esc(li[1]).replace(/\\*\\*(.+?)\\*\\*/g, '<b>$1</b>') + '</li>'; continue; }\n    if (list) { out += '</ul>'; list = false; }\n    if (!l) continue;\n    const h = l.match(/^#+\\s+(.*)$/);\n    out += h ? '<h3>' + esc(h[1]) + '</h3>' : '<p>' + esc(l).replace(/\\*\\*(.+?)\\*\\*/g, '<b>$1</b>') + '</p>';\n  }\n  return out + (list ? '</ul>' : '');\n};\nconst ads = $('New ads only').all().map((i) => i.json);\nconst links = ads.map((a) => '<li>' + esc(a.competitor) + ' · ' + esc(a.library) + ': <a href=\"' + esc(a.url) + '\">' + esc(a.headline || a.body.slice(0, 80) || a.ad_id) + '</a></li>').join('');\nreturn [{ json: {\n  subject: ads.length + ' new competitor ad' + (ads.length === 1 ? '' : 's') + ', week of ' + $now.toFormat('LLL d'),\n  html: '<div style=\"font-family:sans-serif\">' + md($input.first().json.text) + '<h3>Every new ad</h3><ul>' + links + '</ul></div>',\n} }];"
      },
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        2960,
        360
      ],
      "id": "fff7a50a-dbae-4d90-9a25-dff673174f1d",
      "name": "Write the email"
    },
    {
      "parameters": {
        "sendTo": "={{ $('Your settings').first().json.email }}",
        "subject": "={{ $json.subject }}",
        "emailType": "html",
        "message": "={{ $json.html }}",
        "options": {
          "appendAttribution": false
        }
      },
      "type": "n8n-nodes-base.gmail",
      "typeVersion": 2.1,
      "position": [
        3180,
        360
      ],
      "id": "1451e103-fa7d-48f3-affe-53744dcd0e0b",
      "name": "Email me",
      "webhookId": "414f1384-9793-4bbe-a727-4700b2e61681"
    }
  ],
  "pinData": {},
  "connections": {
    "OpenAI": {
      "ai_languageModel": [
        [
          {
            "node": "Write the brief",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Every Monday": {
      "main": [
        [
          {
            "node": "Your settings",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Your settings": {
      "main": [
        [
          {
            "node": "Create table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create table": {
      "main": [
        [
          {
            "node": "One item per competitor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "One item per competitor": {
      "main": [
        [
          {
            "node": "Find the Meta page",
            "type": "main",
            "index": 0
          },
          {
            "node": "LinkedIn ads",
            "type": "main",
            "index": 0
          },
          {
            "node": "Google ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find the Meta page": {
      "main": [
        [
          {
            "node": "Meta ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Meta ads": {
      "main": [
        [
          {
            "node": "All ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "LinkedIn ads": {
      "main": [
        [
          {
            "node": "All ads",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Google ads": {
      "main": [
        [
          {
            "node": "All ads",
            "type": "main",
            "index": 2
          }
        ]
      ]
    },
    "All ads": {
      "main": [
        [
          {
            "node": "Tag each ad",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Tag each ad": {
      "main": [
        [
          {
            "node": "New ads only",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "New ads only": {
      "main": [
        [
          {
            "node": "Save to data table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Save to data table": {
      "main": [
        [
          {
            "node": "Group by competitor",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Group by competitor": {
      "main": [
        [
          {
            "node": "Write the brief",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the brief": {
      "main": [
        [
          {
            "node": "Write the email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Write the email": {
      "main": [
        [
          {
            "node": "Email me",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "meta": {
    "templateCredsSetupCompleted": false
  },
  "tags": []
}