{
  "name": "fb_ad_Competitive_product_analysis",
  "nodes": [
    {
      "parameters": {},
      "type": "n8n-nodes-base.manualTrigger",
      "typeVersion": 1,
      "position": [
        -464,
        320
      ],
      "id": "ee598d43-80a3-4e11-a0fd-2e88b4e34cc9",
      "name": "When clicking ‘Execute workflow’"
    },
    {
      "parameters": {
        "amount": 3
      },
      "type": "n8n-nodes-base.wait",
      "typeVersion": 1.1,
      "position": [
        2464,
        640
      ],
      "id": "618ca317-9c72-4c9d-8af6-d59b0a1dbfed",
      "name": "Wait1",
      "webhookId": "1cda7407-6321-4d8d-b532-19f42514eb63"
    },
    {
      "parameters": {
        "options": {}
      },
      "type": "n8n-nodes-base.splitInBatches",
      "typeVersion": 3,
      "position": [
        304,
        320
      ],
      "id": "67a6e68a-d2b9-4ecc-80d1-eed019c08859",
      "name": "Loop Over Image Ads"
    },
    {
      "parameters": {
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI"
        },
        "messages": {
          "values": [
            {
              "content": "=你是一個專業的競品廣告情報分析師。\n\n輸入：一筆從 Facebook 廣告庫抓取的廣告資料（JavaScript 物件格式）。\n\n分析這則廣告，以合法 JSON 格式輸出，不附加任何說明文字：\n\n{\n  \"summary\": \"廣告文案的核心策略摘要，包含目標受眾、主要賣點、情緒鉤子、CTA 手法。100-150字，分析性語氣，繁體中文。\",\n  \"rewrittenAdCopy\": \"忠實重現原廣告文案，保留原本的語氣、節奏與策略意圖，語言與原廣告相同，去除格式雜訊。\"\n}\n\n若輸入資料不完整，依現有資訊盡力推斷，不回傳錯誤。",
              "role": "system"
            },
            {
              "content": "=以下是一則 Facebook 廣告的完整資料：\n\n【廣告 JSON 資料】\n{{ $('Loop Over Image Ads').item.json.toJsonString() }}\n\n【廣告圖片描述】\n{{ $json.choices[0].message.content }}\n\n請根據以上資料進行分析並輸出 JSON。"
            }
          ]
        },
        "jsonOutput": true,
        "options": {
          "temperature": 0.7
        }
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        1008,
        208
      ],
      "id": "74f71946-0eab-49c3-bd19-52f1cf6a1738",
      "name": "圖片總結",
      "credentials": {
        "openAiApi": {
          "id": "bYZZzx3mE6NTZyjW",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "resource": "image",
        "operation": "analyze",
        "modelId": {
          "__rl": true,
          "value": "gpt-4o-mini",
          "mode": "list",
          "cachedResultName": "GPT-4O-MINI"
        },
        "text": "這張圖裡有什麼？請描述",
        "inputType": "base64",
        "simplify": false,
        "options": {}
      },
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "typeVersion": 1.8,
      "position": [
        848,
        208
      ],
      "id": "3ce40dd3-dccf-46c5-ba79-722f70eecceb",
      "name": "分析圖片",
      "credentials": {
        "openAiApi": {
          "id": "bYZZzx3mE6NTZyjW",
          "name": "OpenAi account"
        }
      }
    },
    {
      "parameters": {
        "content": "##圖片\n",
        "height": 864,
        "width": 2448,
        "color": 5
      },
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        160,
        -16
      ],
      "typeVersion": 1,
      "id": "1078d71b-4bdc-464a-8163-1dedd9b231aa",
      "name": "Sticky Note1"
    },
    {
      "parameters": {
        "functionCode": "const ad = $json;\n\n// 判斷是不是有效圖片網址\nfunction isValidImageUrl(value) {\n  return (\n    typeof value === 'string' &&\n    value.startsWith('http') &&\n    !value.includes('video') // 排除影片網址\n  );\n}\n\n// 遞迴找圖\nfunction findImageUrl(obj) {\n  if (!obj || typeof obj !== 'object') return '';\n\n  // 優先找這些欄位\n  const preferredKeys = [\n    'original_image_url',\n    'resized_image_url',\n    'watermarked_resized_image_url',\n    'image_url'\n  ];\n\n  // 先檢查本層優先欄位\n  for (const key of preferredKeys) {\n    if (isValidImageUrl(obj[key])) {\n      return obj[key];\n    }\n  }\n\n  // 再往下遞迴找\n  if (Array.isArray(obj)) {\n    for (const item of obj) {\n      const found = findImageUrl(item);\n      if (found) return found;\n    }\n  } else {\n    for (const key of Object.keys(obj)) {\n      const found = findImageUrl(obj[key]);\n      if (found) return found;\n    }\n  }\n\n  return '';\n}\n\nconst image_url = findImageUrl(ad);\n\nreturn [\n  {\n    json: {\n      ad_archive_id: ad.ad_archive_id || '',\n      page_name: ad.snapshot?.page_name || ad.page_name || '',\n      title: ad.snapshot?.title || ad.title || '',\n      text: ad.snapshot?.body?.text || ad.body?.text || '',\n      link_url: ad.snapshot?.link_url || ad.link_url || '',\n      image_original: image_url,\n      ad_library_url: ad.ad_library_url || ''\n    }\n  }\n];"
      },
      "id": "b5fc64b6-dd66-48f3-8b06-13d5236f8bb8",
      "name": "Parse Ad JSON",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        496,
        320
      ]
    },
    {
      "parameters": {
        "functionCode": "const drive = $json;\nconst file_id = drive.id || drive.fileId;\n\n\nconst direct_link = \"https://drive.google.com/thumbnail?id=\" + file_id + \"&sz=w1000\";\n\nconst prev = $items(\"Parse Ad JSON\").at($itemIndex).json;\n\nreturn [\n  {\n    json: {\n      ad_archive_id: prev.ad_archive_id,\n      page_name: prev.page_name,\n      title: prev.title,\n      text: prev.text,\n      link_url: prev.link_url,\n      image_original: prev.image_original,\n      image_drive: direct_link,\n      thumbnail: '=IMAGE(\"' + direct_link + '\")',\n      ad_library_url: prev.ad_library_url\n    }\n  }\n];\n\n\n\n"
      },
      "id": "022b2b80-d2b3-41a8-bebe-ac25192d3f01",
      "name": "Prepare Sheet Row",
      "type": "n8n-nodes-base.function",
      "typeVersion": 1,
      "position": [
        1088,
        384
      ]
    },
    {
      "parameters": {
        "url": "={{ $json.image_original }}",
        "responseFormat": "file",
        "options": {
          "fullResponse": false,
          "followAllRedirects": true
        }
      },
      "id": "51cc9893-41db-4443-bcee-f2b052e9ef80",
      "name": "Download Image",
      "type": "n8n-nodes-base.httpRequest",
      "typeVersion": 1,
      "position": [
        656,
        320
      ]
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "23dc3498-2431-4732-9de3-234dc92c1ded",
              "name": "write",
              "value": "={{ $json.message.content.rewrittenAdCopy }}",
              "type": "string"
            },
            {
              "id": "b55124c2-3272-4668-9b42-62c602a084d5",
              "name": "point",
              "value": "={{ $json.message.content.summary }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1296,
        208
      ],
      "id": "a06409ea-6f8c-4dfd-b12c-8fb954d9d3f6",
      "name": "Edit Fields"
    },
    {
      "parameters": {
        "assignments": {
          "assignments": [
            {
              "id": "6a13e3ce-f011-42d2-afa9-fb3fd25e4d4a",
              "name": "ad_archive_id",
              "value": "={{ $json.ad_archive_id }}",
              "type": "string"
            },
            {
              "id": "6abe6f22-3db7-4328-ba53-8b303bb52c37",
              "name": "page_name",
              "value": "={{ $json.page_name }}",
              "type": "string"
            },
            {
              "id": "da875477-cbdd-4d35-a27a-9269d0f25f49",
              "name": "text",
              "value": "={{ $json.text }}",
              "type": "string"
            },
            {
              "id": "c221fb75-4e53-4685-9995-868afe7022a6",
              "name": "thumbnail",
              "value": "={{ $json.thumbnail }}",
              "type": "string"
            },
            {
              "id": "94ebf344-9f3e-4dfc-8284-5f9c3220ddbe",
              "name": "ad_library_url",
              "value": "={{ $json.ad_library_url }}",
              "type": "string"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.set",
      "typeVersion": 3.4,
      "position": [
        1280,
        368
      ],
      "id": "a7162c8e-7b10-4b47-906c-11cc69c9699c",
      "name": "Edit Fields1"
    },
    {
      "parameters": {
        "fieldsToAggregate": {
          "fieldToAggregate": [
            {
              "fieldToAggregate": "write"
            },
            {
              "fieldToAggregate": "ad_archive_id"
            },
            {
              "fieldToAggregate": "page_name"
            },
            {
              "fieldToAggregate": "text"
            },
            {
              "fieldToAggregate": "thumbnail"
            },
            {
              "fieldToAggregate": "ad_library_url"
            }
          ]
        },
        "options": {}
      },
      "type": "n8n-nodes-base.aggregate",
      "typeVersion": 1,
      "position": [
        1648,
        288
      ],
      "id": "f2286072-6d12-49b3-87d1-15d259361403",
      "name": "Aggregate1"
    },
    {
      "parameters": {},
      "type": "n8n-nodes-base.merge",
      "typeVersion": 3.2,
      "position": [
        1504,
        272
      ],
      "id": "ff1f6fef-053a-4848-a3ae-b1ae09afff16",
      "name": "Merge1"
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "d9bbf6f3-3daa-4488-ba3d-c03974b25cc6",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "二型膠原蛋白",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "膠原",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    },
                    "id": "47bb128a-f14f-4105-8ce5-b732b6d4090b"
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "eca0a58c-eb83-41ee-9446-ef8fec5bef4c",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "美白",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "ba469f54-3f63-4058-89e6-b3fe9c0daa91",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "皮膚",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "7e94a1b2-0c59-4acf-bf91-ffcefa0b166a",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "神經醯胺",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3a712918-367b-4811-8d56-fbb28aed8387",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "穀胱甘肽",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "fd92b7b7-592a-4ae6-b12e-ddcbdc31e7ca",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "芝麻",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "91563c37-f0b9-410b-bc9f-8f96d61d4f79",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "gaba",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "49ab39b8-de96-4998-87c6-cc7bbee7010a",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "好眠",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "37c84aa7-7a5e-48f1-8196-d21bb12a866f",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "幫助入睡",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "5d1e2327-c1d8-4ee1-83a6-3cd305bfac96",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "色胺酸",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "9c4ba5bc-6b38-403a-af20-85534e7694f7",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "失眠",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "458c215d-bb06-4a7a-ba0a-59ebd9282740",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "關節",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "e559fa49-b0ee-4557-a8c0-444eb7028a77",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "膝蓋",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "3be338d2-71ce-4d96-b06a-3d856d002682",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "運動",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "ffd52542-ceee-4d23-bdb8-e4e0b94fc50a",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "靈活",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "0722b911-86f3-4890-ab94-3308b079a3a3",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "UCll",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "e548885f-0233-43d6-a310-518ff442e333",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "UC-ll",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "23a60ab9-7afb-4fbd-8d47-9393c088c289",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "水分",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 3
                },
                "conditions": [
                  {
                    "id": "06f1501f-3923-4434-bf18-1ef96b8889c5",
                    "leftValue": "={{ $json.text[0] }}",
                    "rightValue": "肌膚",
                    "operator": {
                      "type": "string",
                      "operation": "contains"
                    }
                  }
                ],
                "combinator": "and"
              }
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.4,
      "position": [
        1824,
        32
      ],
      "id": "378a1881-52c6-4e4a-b263-de5e729054aa",
      "name": "Switch4"
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM",
          "mode": "list",
          "cachedResultName": "FB ADS",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": "gid=0",
          "mode": "list",
          "cachedResultName": "工作表1",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit#gid=0"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ad_archive_id": "={{ $json.ad_archive_id[0] }}",
            "type": "image",
            "date_added": "={{ $now }}",
            "page_name": "={{ $json.page_name[0] }}",
            "thumbnail": "={{ $json.thumbnail[0] }}",
            "image_url": "={{ $json.ad_library_url[0] }}",
            "rewritten_ad_copy": "={{ $json.text[0] }}",
            "summary": "={{ $json.text[0] }}",
            "point": "={{ $('Edit Fields').item.json.point }}"
          },
          "matchingColumns": [
            "ad_archive_id"
          ],
          "schema": [
            {
              "id": "ad_archive_id",
              "displayName": "ad_archive_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "type",
              "displayName": "type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date_added",
              "displayName": "date_added",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "page_name",
              "displayName": "page_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "rewritten_ad_copy",
              "displayName": "rewritten_ad_copy",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "thumbnail",
              "displayName": "thumbnail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "point",
              "displayName": "point",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "image_url",
              "displayName": "image_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        2064,
        176
      ],
      "id": "e3408d77-e797-4a09-84a0-ae96a652b431",
      "name": "美麗",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ceNNZyk6FUNcakOW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM",
          "mode": "list",
          "cachedResultName": "FB ADS",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1716801756,
          "mode": "list",
          "cachedResultName": "工作表2",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit#gid=1716801756"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ad_archive_id": "={{ $json.ad_archive_id[0] }}",
            "type": "image",
            "date_added": "={{ $now }}",
            "page_name": "={{ $json.page_name[0] }}",
            "thumbnail": "={{ $json.thumbnail[0] }}",
            "image_url": "={{ $json.ad_library_url[0] }}",
            "summary": "={{ $json.text }}",
            "rewritten_ad_copy": "={{ $json.text[0] }}",
            "point": "={{ $('Edit Fields').item.json.point }}"
          },
          "matchingColumns": [
            "ad_archive_id"
          ],
          "schema": [
            {
              "id": "ad_archive_id",
              "displayName": "ad_archive_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "type",
              "displayName": "type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date_added",
              "displayName": "date_added",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "page_name",
              "displayName": "page_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "rewritten_ad_copy",
              "displayName": "rewritten_ad_copy",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "thumbnail",
              "displayName": "thumbnail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "point",
              "displayName": "point",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "image_url",
              "displayName": "image_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        2080,
        352
      ],
      "id": "cb1e3b4e-03fb-4b93-a761-bf5f17a3cb5f",
      "name": "睡眠",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ceNNZyk6FUNcakOW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM",
          "mode": "list",
          "cachedResultName": "FB ADS",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1053227897,
          "mode": "list",
          "cachedResultName": "工作表3",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit#gid=1053227897"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ad_archive_id": "={{ $json.ad_archive_id[0] }}",
            "type": "image",
            "date_added": "={{ $now }}",
            "page_name": "={{ $json.page_name[0] }}",
            "thumbnail": "={{ $json.thumbnail[0] }}",
            "image_url": "={{ $json.ad_library_url[0] }}",
            "summary": "={{ $json.text }}",
            "rewritten_ad_copy": "={{ $json.text[0] }}",
            "point": "={{ $('Edit Fields').item.json.point }}"
          },
          "matchingColumns": [
            "ad_archive_id"
          ],
          "schema": [
            {
              "id": "ad_archive_id",
              "displayName": "ad_archive_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "type",
              "displayName": "type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date_added",
              "displayName": "date_added",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "page_name",
              "displayName": "page_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "rewritten_ad_copy",
              "displayName": "rewritten_ad_copy",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "thumbnail",
              "displayName": "thumbnail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "point",
              "displayName": "point",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "image_url",
              "displayName": "image_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        2080,
        512
      ],
      "id": "29f25243-af6e-4589-a7ae-1b8a9a80e638",
      "name": "uc2",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ceNNZyk6FUNcakOW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "operation": "append",
        "documentId": {
          "__rl": true,
          "value": "1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM",
          "mode": "list",
          "cachedResultName": "FB ADS",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit?usp=drivesdk"
        },
        "sheetName": {
          "__rl": true,
          "value": 1711646280,
          "mode": "list",
          "cachedResultName": "工作表4",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1aGCkjzPnJhxMCHVy2EGI2ZcYSNltD4JRhRtLE4dF_XM/edit#gid=1711646280"
        },
        "columns": {
          "mappingMode": "defineBelow",
          "value": {
            "ad_archive_id": "={{ $json.ad_archive_id[0] }}",
            "type": "image",
            "date_added": "={{ $now }}",
            "page_name": "={{ $json.page_name[0] }}",
            "thumbnail": "={{ $json.thumbnail[0] }}",
            "image_url": "={{ $json.ad_library_url[0] }}",
            "summary": "={{ $json.text }}",
            "rewritten_ad_copy": "={{ $json.text[0] }}",
            "point": "={{ $('Edit Fields').item.json.point }}"
          },
          "matchingColumns": [
            "ad_archive_id"
          ],
          "schema": [
            {
              "id": "ad_archive_id",
              "displayName": "ad_archive_id",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "type",
              "displayName": "type",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "date_added",
              "displayName": "date_added",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "page_name",
              "displayName": "page_name",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "displayName": "summary",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "rewritten_ad_copy",
              "displayName": "rewritten_ad_copy",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "thumbnail",
              "displayName": "thumbnail",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "point",
              "displayName": "point",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            },
            {
              "id": "image_url",
              "displayName": "image_url",
              "required": false,
              "defaultMatch": false,
              "display": true,
              "type": "string",
              "canBeUsedToMatch": true,
              "removed": false
            }
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {}
      },
      "type": "n8n-nodes-base.googleSheets",
      "typeVersion": 4.6,
      "position": [
        2064,
        672
      ],
      "id": "b7d72ea9-7e8f-4eb3-941b-68901c80abaf",
      "name": "none",
      "credentials": {
        "googleSheetsOAuth2Api": {
          "id": "ceNNZyk6FUNcakOW",
          "name": "Google Sheets account"
        }
      }
    },
    {
      "parameters": {
        "content": "##  by Level UP升級志\n\n我是 Level UP的 Yuzen\n有 n8n 問題可以一起討論><\n\n- [我們的官網](https://levelupdiary.com/)\n- [n8n 模板分享網站](https://n8n.template.levelupdiary.com/)\n\n### 社群social media:\n[Threads](https://www.threads.com/@levelup.daily_lab)\n[Instagram](https://www.instagram.com/levelup.daily_lab/)\n![](https://pub-dfed2b7a97c243fbabeaf6f058d4adb3.r2.dev/logo%20(1).png)",
        "height": 420,
        "width": 360,
        "color": 7
      },
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        -384,
        512
      ],
      "id": "5a55c536-9fbd-4bdb-bfb9-66683e96ff4c",
      "name": "Sticky Note5"
    },
    {
      "parameters": {
        "operation": "Run actor and get dataset",
        "actorSource": "store",
        "actorId": {
          "__rl": true,
          "value": "XtaWFhbtfxyzqrFmd",
          "mode": "list",
          "cachedResultName": "Facebook Ad Library Scraper (curious_coder/facebook-ads-library-scraper)",
          "cachedResultUrl": "https://console.apify.com/actors/XtaWFhbtfxyzqrFmd/input"
        },
        "customBody": "{\n    \"count\": 18,\n    \"limitPerSource\": 2,\n    \"scrapeAdDetails\": false,\n    \"scrapePageAds.activeStatus\": \"all\",\n    \"scrapePageAds.countryCode\": \"ALL\",\n    \"scrapePageAds.sortBy\": \"impressions_desc\",\n    \"urls\": [\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=105662602252260\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=483142608724566\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=904446416371679\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=223859621447410\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=100328735273777\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=460583077313238\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&q=%E5%A4%A7%E7%A0%94%E7%94%9F%E9%86%ABDaiken%20Bio&search_type=keyword_unordered&sort_data[direction]=desc&sort_data[mode]=total_impressions\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=276421236267721\"\n        },\n        {\n            \"url\": \"https://www.facebook.com/ads/library/?active_status=active&ad_type=all&country=TW&is_targeted_country=false&media_type=all&search_type=page&sort_data[direction]=desc&sort_data[mode]=total_impressions&view_all_page_id=386922944690398\"\n        }\n    ]\n}",
        "memory": 2048
      },
      "type": "@apify/n8n-nodes-apify.apify",
      "typeVersion": 1,
      "position": [
        -272,
        320
      ],
      "id": "4b15dd77-2557-4716-a3f6-c706b86d877a",
      "name": "抓取廣告",
      "credentials": {
        "apifyApi": {
          "id": "nf8BPvjWqziyB2do",
          "name": "Apify account"
        }
      }
    },
    {
      "parameters": {
        "rules": {
          "values": [
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "leftValue": "={{ $json.snapshot?.videos?.[0]?.video_hd_url || $json.snapshot?.videos?.[0]?.video_sd_url }}",
                    "rightValue": "=https://video-",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    },
                    "id": "9dbbe6e7-fd80-44ab-88f0-ab438cfd997e"
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "Video"
            },
            {
              "conditions": {
                "options": {
                  "caseSensitive": true,
                  "leftValue": "",
                  "typeValidation": "strict",
                  "version": 2
                },
                "conditions": [
                  {
                    "id": "102b7af0-2950-463e-9f89-b9ed507d0467",
                    "leftValue": "={{ $json.snapshot?.image_crops?.original_image_url || $json.snapshot?.images?.[0]?.resized_image_url || $json.snapshot?.cards?.[0]?.resized_image_url }}",
                    "rightValue": "=",
                    "operator": {
                      "type": "string",
                      "operation": "notEmpty",
                      "singleValue": true
                    }
                  }
                ],
                "combinator": "and"
              },
              "renameOutput": true,
              "outputKey": "image"
            }
          ]
        },
        "options": {
          "fallbackOutput": "extra",
          "renameFallbackOutput": "Text"
        }
      },
      "type": "n8n-nodes-base.switch",
      "typeVersion": 3.2,
      "position": [
        0,
        304
      ],
      "id": "1abfbf60-a50b-4404-9804-48e28b1f0e90",
      "name": "分類"
    },
    {
      "parameters": {
        "binaryData": true,
        "name": "=={{ $json[\"ad_archive_id\"] }}_{{ $itemIndex }}.jpg\n",
        "parents": [
          "1VEEFZ--dn8YpPEtoYVsJe8O1iKmgbHqj"
        ],
        "options": {}
      },
      "id": "0db1def3-ffbb-4da2-9cd2-8efb22a7c88d",
      "name": "上傳雲端硬碟",
      "type": "n8n-nodes-base.googleDrive",
      "typeVersion": 2,
      "position": [
        848,
        368
      ],
      "credentials": {
        "googleDriveOAuth2Api": {
          "id": "YSnLVHjxUqIw2iod",
          "name": "Google Drive account"
        }
      }
    }
  ],
  "pinData": {},
  "connections": {
    "When clicking ‘Execute workflow’": {
      "main": [
        [
          {
            "node": "抓取廣告",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Wait1": {
      "main": [
        [
          {
            "node": "Loop Over Image Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Loop Over Image Ads": {
      "main": [
        [],
        [
          {
            "node": "Parse Ad JSON",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "分析圖片": {
      "main": [
        [
          {
            "node": "圖片總結",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Parse Ad JSON": {
      "main": [
        [
          {
            "node": "Download Image",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare Sheet Row": {
      "main": [
        [
          {
            "node": "Edit Fields1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Download Image": {
      "main": [
        [
          {
            "node": "分析圖片",
            "type": "main",
            "index": 0
          },
          {
            "node": "上傳雲端硬碟",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "圖片總結": {
      "main": [
        [
          {
            "node": "Edit Fields",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Edit Fields1": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Edit Fields": {
      "main": [
        [
          {
            "node": "Merge1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge1": {
      "main": [
        [
          {
            "node": "Aggregate1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Aggregate1": {
      "main": [
        [
          {
            "node": "Switch4",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "美麗": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch4": {
      "main": [
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "睡眠",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "uc2",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "美麗",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "none",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "睡眠": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "uc2": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "none": {
      "main": [
        [
          {
            "node": "Wait1",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "抓取廣告": {
      "main": [
        [
          {
            "node": "分類",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "分類": {
      "main": [
        [],
        [
          {
            "node": "Loop Over Image Ads",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "上傳雲端硬碟": {
      "main": [
        [
          {
            "node": "Prepare Sheet Row",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  },
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "55739b8d-3b28-4b08-a98c-2c1f1d7fc075",
  "meta": {
    "templateCredsSetupCompleted": true,
    "instanceId": "9b0e7206dbdd8b286cc505a590e367911160782c95a38db4767c9caf6ba5bf9d"
  },
  "id": "hzGnaKx5uwdluREm",
  "tags": []
}