{
  "name": "AdSpy - Monitoramento Semanal de Concorrentes",
  "projectId": "wIDTxGIAD0mMkTyy",
  "nodes": [
    {
      "parameters": {
        "rule": {
          "interval": [
            {
              "triggerAtHour": 10,
              "triggerAtMinute": 0,
              "weekday": "Monday"
            }
          ]
        }
      },
      "id": "trigger-schedule",
      "name": "Trigger - Segunda-feira 7h BRT",
      "type": "n8n-nodes-base.scheduleTrigger",
      "typeVersion": 1.1,
      "position": [
        100,
        300
      ]
    },
    {
      "parameters": {
        "jsCode": "var clientes = [\n  {\n    nome: \"Belleviva\",\n    concorrentes: [\"Ultraformer Brasil\", \"Venus Concept Brasil\", \"StraitheHair Brasil\", \"Cl\u00ednica Joice Lira\", \"Est\u00e9tica Advanced\", \"Beleza Pure\", \"Skin Clinic SP\", \"Derma Club\"],\n    sheetTab: \"Belleviva Ads\"\n  },\n  {\n    nome: \"Idole\",\n    concorrentes: [\"Sal\u00e3o das Minas\", \"Depila\u00e7\u00e3o Zero\", \"Espa\u00e7o Nanda\", \"Cl\u00ednica Plena\", \"Beleza Laser SP\", \"Est\u00e9tica Corporate\", \"L\u00e2mina Laser\", \"Beauty One\"],\n    sheetTab: \"Idole Ads\"\n  },\n  {\n    nome: \"Pro Est\u00e9tica Tatuape\",\n    concorrentes: [\"Cl\u00ednica Est\u00e9tica Tatuap\u00e9\", \"Centro Belezac\", \"Estetika Tatuap\u00e9\", \"Sorrisus Dental\", \"Cl\u00ednica Rebeca Borges\", \"Beleza Real SP\"],\n    sheetTab: \"ProEstetica Tatuape Ads\"\n  },\n  {\n    nome: \"Pro Est\u00e9tica Santos\",\n    concorrentes: [\"Cl\u00ednica Est\u00e9tica Santos\", \"Beleza Costa\", \"Estetika Santos\", \"Cl\u00ednica Milena Est\u00e9tica\", \"Espa\u00e7o VIP Beleza\", \"Donna Belle Santos\"],\n    sheetTab: \"ProEstetica Santos Ads\"\n  }\n];\n\n\nvar items = [];\nfor (var i = 0; i < clientes.length; i++) {\n  var cliente = clientes[i];\n  for (var j = 0; j < cliente.concorrentes.length; j++) {\n    items.push({\n      json: {\n        cliente: cliente.nome,\n        concorrente: cliente.concorrentes[j],\n        sheetTab: cliente.sheetTab\n      }\n    });\n  }\n}\n\nreturn items;"
      },
      "id": "definir-concorrentes",
      "name": "Code - Definir Clientes e Concorrentes",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        320,
        300
      ]
    },
    {
      "parameters": {
        "method": "POST",
        "url": "https://api.apify.com/v2/acts/datleo~meta-ad-library-scraper/run-sync-get-dataset-items",
        "authentication": "genericCredentialType",
        "genericAuthType": "httpHeaderAuth",
        "sendHeaders": true,
        "headerParameters": {
          "parameters": [
            {
              "name": "Content-Type",
              "value": "application/json"
            }
          ]
        },
        "sendBody": true,
        "bodyParameters": {
          "parameters": [
            {
              "name": "searchFor",
              "value": "={{ $json.concorrente }}"
            },
            {
              "name": "country",
              "value": "BR"
            },
            {
              "name": "requestedRecords",
              "value": 20
            },
            {
              "name": "adType",
              "value": "all"
            },
            {
              "name": "mediumType",
              "value": "all"
            }
          ]
        },
        "options": {
          "timeout": 30000
        }
      },
      "id": "apify-scrape",
      "name": "HTTP Request - Apify Meta Ad Library",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 4.1,
      "position": [
        540,
        300
      ],
      "continueOnFail": true
    },
    {
      "parameters": {
        "jsCode": "var rawData = $input.all();\nvar cliente = '';\nvar sheetTab = '';\n\ntry {\n  var firstItem = $('Definir Clientes e Concorrentes').first().json;\n  cliente = firstItem.cliente;\n  sheetTab = firstItem.sheetTab;\n} catch(e) {}\n\n\nvar resultados = [];\n\nfor (var i = 0; i < rawData.length; i++) {\n  var ad = rawData[i].json;\n  if (!ad || !ad.pageName) continue;\n  \n  var screenshotUrl = '';\n  if (ad.screenshotUrls && ad.screenshotUrls.length > 0) {\n    screenshotUrl = ad.screenshotUrls[0];\n  } else if (ad.screenshotUrl) {\n    screenshotUrl = ad.screenshotUrl;\n  }\n\n\n  resultados.push({\n    json: {\n      data_coleta: new Date().toISOString().split('T')[0],\n      cliente_monitorado: cliente,\n      pagina_anunciante: ad.pageName || '',\n      corpo_anuncio: (ad.adBody || ad.adCreativeBody || '').substring(0, 500),\n      headline: ad.adCreativeHeadline || ad.headline || '',\n      descricao_link: ad.adCreativeLinkDescription || '',\n      url_link: ad.adLinkUrl || '',\n      tipo_midia: ad.mediaType || ad.mediumType || 'unknown',\n      url_imagem: screenshotUrl,\n      primeira_vez_visto: ad.firstSeen || ad.activeStatus || '',\n      status_ativo: ad.activeStatus || 'unknown',\n      sheetTab: sheetTab\n    }\n  });\n}\n\nif (resultados.length === 0) {\n  resultados.push({ json: { skip: true } });\n}\n\nreturn resultados;"
      },
      "id": "transformar-dados",
      "name": "Code - Transformar Dados",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        760,
        300
      ]
    },
    {
      "parameters": {
        "operation": "append",
        "sheetId": "1k0dPmvJ3zszRAi1pRGdiNVoUJ8cyTpzeWuI9lCAlL0Q",
        "range": "A1",
        "options": {
          "valueInputMode": "USER_ENTERED"
        }
      },
      "id": "sheets-write",
      "name": "Google Sheets - Salvar Ads",
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.4,
      "position": [
        980,
        300
      ]
    },
    {
      "parameters": {
        "chatId": "-1003854112886",
        "text": "\ud83d\udcca *AdSpy - Minera\u00e7\u00e3o Semanal Conclu\u00edda*\n\nCliente: {{ $json.cliente }}\nConcorrente: {{ $json.concorrente }}\nAds coletados: {{ $json.count }}",
        "additionalFields": {
          "message_thread_id": 5
        }
      },
      "id": "telegram-notify",
      "name": "Telegram - Notificar Resumo",
      "type": "n8n-nodes-base.telegram",
      "typeVersion": 1.2,
      "position": [
        1200,
        300
      ]
    },
    {
      "parameters": {
        "delay": 2,
        "unit": "seconds"
      },
      "id": "delay-rate-limit",
      "name": "Delay - Rate Limit 2s",
      "type": "n8n-nodes-base.delay",
      "typeVersion": 1.1,
      "position": [
        430,
        300
      ]
    }
  ],
  "connections": {
    "Trigger - Segunda-feira 7h BRT": {
      "main": [
        [
          {
            "node": "Code - Definir Clientes e Concorrentes",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Code - Definir Clientes e Concorrentes": {
      "main": [
        [
          {
            "node": "Delay - Rate Limit 2s",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Delay - Rate Limit 2s": {
      "main": [
        [
          {
            "node": "HTTP Request - Apify Meta Ad Library",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "HTTP Request - Apify Meta Ad Library": {
      "main": [
        [
          {
            "node": "Code - Transformar Dados",
            "type": "main",
            "index": 0
          }
        ]
      ],
      "error": [
        []
      ]
    },
    "Code - Transformar Dados": {
      "main": [
        [
          {
            "node": "Google Sheets - Salvar Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Sheets - Salvar Ads": {
      "main": [
        [
          {
            "node": "Telegram - Notificar Resumo",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "settings": {
    "executionOrder": "v1",
    "saveManualExecutions": true,
    "timezone": "America/Sao_Paulo"
  },
  "staticData": null,
  "tags": [
    "adspy",
    "meta-ads",
    "monitoramento",
    "semanal"
  ],
  "triggerCount": 1,
  "updatedAt": "2026-04-28T20:10:00.000Z",
  "versionId": "1",
  "id": "adspy-concorrentes"
}