{
  "id": "YrhmqkmhYl2ghAKN",
  "meta": {
    "templateCredsSetupCompleted": true
  },
  "name": "Ads Analysis",
  "tags": [
    {
      "id": "tITAFvUSOpVVIBvI",
      "name": "MetaAds",
      "createdAt": "2025-07-05T02:24:26.705Z",
      "updatedAt": "2025-07-05T02:24:26.705Z"
    },
    {
      "id": "8ZOxg8cY0fPL8g0s",
      "name": "ReadyToUse",
      "createdAt": "2025-07-10T04:08:19.089Z",
      "updatedAt": "2025-07-10T04:08:19.089Z"
    }
  ],
  "nodes": [
    {
      "id": "02512611-49a2-4319-9423-2a8c84cda262",
      "name": "Schedule Trigger",
      "type": "n8n-nodes-base.scheduleTrigger",
      "position": [
        0,
        -432
      ],
      "parameters": {
        "rule": {
          "interval": [
            {}
          ]
        }
      },
      "typeVersion": 1.2
    },
    {
      "id": "46d2cd63-dd9b-41de-a050-a7b0106ec6c7",
      "name": "Get Ads",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        672,
        -544
      ],
      "parameters": {
        "edge": "ads",
        "node": "={{ $json.campaign_id ?? $('Set parameters').item.json.campaign_id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "=id,name,adset_id,creative{id,object_story_id,object_type,image_url,video_id,object_story_spec{video_data{video_id,image_url}}}"
              }
            ]
          }
        },
        "graphApiVersion": "v22.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "90adc41b-f6bf-4a03-894d-3ae50067f64d",
      "name": "Get Insights",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        1120,
        -480
      ],
      "parameters": {
        "edge": "insights",
        "node": "={{ $json.id }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "ad_id,ad_name,adset_id,campaign_id,spend,impressions,clicks,reach,frequency,actions,action_values,video_p25_watched_actions,video_p50_watched_actions,video_p75_watched_actions,video_p100_watched_actions"
              }
            ]
          }
        },
        "graphApiVersion": "v22.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "e9ef5bb7-b017-4068-abe2-937c077d9630",
      "name": "Ads Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        896,
        -544
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "executeOnce": false,
      "typeVersion": 1
    },
    {
      "id": "bdff8dcb-4319-484a-b7b9-6a25c3a957df",
      "name": "Insights Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        1344,
        -480
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "data"
      },
      "typeVersion": 1
    },
    {
      "id": "a4b5eb06-0a3b-4092-b682-dbb77ef9f7a6",
      "name": "Set Metrics",
      "type": "n8n-nodes-base.set",
      "position": [
        1792,
        -672
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "8bb35599-d421-4f61-a4c7-f77c60233ba9",
              "name": "spend",
              "type": "string",
              "value": "={{ $json.spend }}"
            },
            {
              "id": "28321e91-fd2f-49e7-92e1-c45a89f67702",
              "name": "impressions",
              "type": "string",
              "value": "={{ $json.impressions }}"
            },
            {
              "id": "0c9319e6-b233-456b-878b-d30515473326",
              "name": "link_click",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('link_click'))?.value || 0 }}"
            },
            {
              "id": "52248e0e-c428-4d5d-a593-5c43d84398ee",
              "name": "app_installs",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('app_install'))?.value || 0 }}"
            },
            {
              "id": "0e8282f2-a9cd-4209-87f7-1f10d794b65b",
              "name": "complete_registration",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('complete_registration'))?.value || 0 }}"
            },
            {
              "id": "709915f4-b44b-434e-9193-39ea390ccbb0",
              "name": "add_to_cart",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('add_to_cart'))?.value || 0 }}"
            },
            {
              "id": "62420b81-8f39-4c88-ae1e-8a20c4d1a13f",
              "name": "initiate_checkout",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('initiate_checkout'))?.value || 0 }}"
            },
            {
              "id": "9bc0b5fe-6639-4b6d-b31d-924b25b6818d",
              "name": "purchase",
              "type": "string",
              "value": "={{ $json.actions.find(action => action.action_type.includes('purchase'))?.value || 0 }}"
            },
            {
              "id": "96859718-a1f3-4678-8b40-110e0e38964f",
              "name": "value",
              "type": "string",
              "value": "={{ $json.action_values ? $json.action_values.find(action => action.action_type.includes('purchase'))?.value || 0 : 0 }}"
            },
            {
              "id": "82193e6a-e80c-429c-9066-56ac3985647f",
              "name": "ad_id",
              "type": "string",
              "value": "={{ $json.ad_id }}"
            },
            {
              "id": "04316c4e-1417-46d5-9368-5335f9899dd6",
              "name": "ad_name",
              "type": "string",
              "value": "={{ $json.ad_name }}"
            },
            {
              "id": "114d6153-66ff-4087-b82e-df19abbd52dc",
              "name": "campaign_id",
              "type": "string",
              "value": "={{ $json.campaign_id }}"
            },
            {
              "id": "58d3f46a-ecd5-4590-9194-76cfe4541dc3",
              "name": "adset_id",
              "type": "string",
              "value": "={{ $json.adset_id }}"
            },
            {
              "id": "fa3c43ea-17f4-41ab-94e5-d75d9b386c23",
              "name": "video_image_url",
              "type": "string",
              "value": "={{ $json.creative.object_story_spec.video_data.image_url }}"
            },
            {
              "id": "000a2f08-6fca-4790-bcaf-d0937c2b70f0",
              "name": "image_url",
              "type": "string",
              "value": "={{ $json.creative.image_url }}"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "f891f10b-02c3-4eab-ad22-e01f8c6d3e20",
      "name": "Set parameters",
      "type": "n8n-nodes-base.set",
      "position": [
        224,
        -432
      ],
      "parameters": {
        "options": {},
        "assignments": {
          "assignments": [
            {
              "id": "a2f4de51-3c9b-41dd-94bd-cdab162261ba",
              "name": "source",
              "type": "string",
              "value": "Sheets"
            },
            {
              "id": "3c3bb838-3411-4347-b98c-f05d1ff60a8d",
              "name": "campaign_id",
              "type": "string",
              "value": ""
            },
            {
              "id": "418cf02d-3573-4f78-8495-553b5a0f47e3",
              "name": "benchmarks_data",
              "type": "string",
              "value": "=Ad ID,Ad name,Ad delivery,Frequency,Reach,Impressions,CTR (link click-through rate),\"CPM (cost per 1,000 impressions) (USD)\",Link clicks,CPC (cost per link click) (USD),IPM,App Installs,Cost per App Install (USD),CR install to reg,Registrations completed,Cost per registration completed (USD),Results,Result indicator,Cost per results,Amount spent (USD),Adds to cart,Cost per add to cart (USD),Checkouts initiated,Cost per checkout initiated (USD),Purchases,Searches,Checkouts initiated conversion value\n120222559945080510,How-to-fly-earn.mp4,not_delivering,2.253171,1312196,2956602,0.787593,2.876305,23286,0.365202,5.80598944,17166,0.495403,0.25381568,4357,1.951822,4357,actions:app_custom_event.fb_mobile_complete_registration,1.95182235,8504.09,515,16.512796,136,62.530074,,19042,7666249.29\n120227998563210510,EASY JUNE 13.jpg,active,2.044556,892309,1824376,1.141212,2.786471,20820,0.244168,3.96354699,7231,0.703024,0.19941917,1442,3.525361,82,actions:app_custom_event.fb_mobile_initiated_checkout,61.9947561,5083.57,360,14.121028,83,61.247831,,9336,4367509.01\n120218673707160510,EASY MARCH ITALY - 1.jpg,not_delivering,1.800396,818312,1473286,0.84505,1.963522,12450,0.232356,2.63356877,3880,0.745575,0.23840206,925,3.127384,925,actions:app_custom_event.fb_mobile_complete_registration,3.12738378,2892.83,194,14.911495,61,47.423443,,5721,2333824.7\n120216673487350510,Flying20Private.mp4,not_delivering,1.915076,301010,576457,0.468899,2.564927,2703,0.547011,2.84496502,1640,0.901567,0.28414634,466,3.172897,459,actions:app_custom_event.fb_mobile_complete_registration,3.2212854,1478.57,121,12.219587,35,42.244857,,2904,1238511.1\n120226828283920510,DJoPkbKzfcU.mp4,not_delivering,1.713265,517876,887259,0.837636,2.505728,7432,0.299143,4.41133874,3914,0.56802,0.25038324,980,2.268602,980,actions:app_custom_event.fb_mobile_complete_registration,2.26860204,2223.23,110,20.211182,29,76.663103,,4559,1405339.92\n120215360661600510,EASY-1 New.jpg,inactive,1.796525,382927,687938,0.715035,2.079548,4919,0.290831,1.89697327,1305,1.096245,0.27126437,354,4.041243,354,actions:app_custom_event.fb_mobile_complete_registration,4.04124294,1430.6,75,19.074667,29,49.331034,,2295,688904.04"
            }
          ]
        }
      },
      "typeVersion": 3.4
    },
    {
      "id": "423b6343-a63c-42b3-9804-4088e8e1694a",
      "name": "If",
      "type": "n8n-nodes-base.if",
      "position": [
        448,
        -432
      ],
      "parameters": {
        "options": {},
        "conditions": {
          "options": {
            "version": 2,
            "leftValue": "",
            "caseSensitive": true,
            "typeValidation": "strict"
          },
          "combinator": "and",
          "conditions": [
            {
              "id": "e682854e-6f62-4016-8406-897dc46e2837",
              "operator": {
                "name": "filter.operator.equals",
                "type": "string",
                "operation": "equals"
              },
              "leftValue": "={{ $json.source }}",
              "rightValue": "Meta"
            }
          ]
        }
      },
      "typeVersion": 2.2
    },
    {
      "id": "104f7e12-094c-4f7f-8ec4-420866771334",
      "name": "Get Ad Details",
      "type": "n8n-nodes-base.facebookGraphApi",
      "position": [
        896,
        -288
      ],
      "parameters": {
        "node": "={{ $json.AdID }}",
        "options": {
          "fields": {
            "field": [
              {
                "name": "id,name,adset_id,creative{id,object_story_id,object_type,image_url,video_id,object_story_spec{video_data{video_id,image_url}}}"
              }
            ]
          }
        },
        "graphApiVersion": "v22.0"
      },
      "credentials": {
        "facebookGraphApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b1111c61-bb8a-4f7d-958f-8a09dc75c910",
      "name": "Merge",
      "type": "n8n-nodes-base.merge",
      "position": [
        1568,
        -480
      ],
      "parameters": {
        "mode": "combine",
        "options": {},
        "advanced": true,
        "mergeByFields": {
          "values": [
            {
              "field1": "id",
              "field2": "ad_id"
            }
          ]
        }
      },
      "typeVersion": 3.2
    },
    {
      "id": "b5b5eb35-4402-471e-a15c-7b6f38a46c18",
      "name": "Split Out",
      "type": "n8n-nodes-base.splitOut",
      "position": [
        2416,
        -480
      ],
      "parameters": {
        "options": {},
        "fieldToSplitOut": "message.content.creatives"
      },
      "typeVersion": 1
    },
    {
      "id": "2a067c01-1113-41f1-8165-484f83e2c86c",
      "name": "Structured Output Parser",
      "type": "@n8n/n8n-nodes-langchain.outputParserStructured",
      "position": [
        2224,
        64
      ],
      "parameters": {
        "jsonSchemaExample": "{\n  \"ad_id\": \"9847213\",\n  \"evaluation\": \"high\",\n  \"significance\": \"yes\",\n  \"summary\": \"CTR and CPC are significantly better than benchmarks, with a strong funnel down to Checkouts Initiated.\",\n  \"recommendation\": \"scale\"\n}"
      },
      "typeVersion": 1.3
    },
    {
      "id": "62321b02-c786-4397-96dd-c86532968664",
      "name": "Google Gemini Chat Model",
      "type": "@n8n/n8n-nodes-langchain.lmChatGoogleGemini",
      "position": [
        2032,
        48
      ],
      "parameters": {
        "options": {
          "temperature": 0.4
        }
      },
      "credentials": {
        "googlePalmApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "b599b087-9f76-4183-8b39-c15cba123e0c",
      "name": "Prepare CSV for OpenAI",
      "type": "n8n-nodes-base.code",
      "position": [
        1792,
        -480
      ],
      "parameters": {
        "jsCode": "// \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 CSV \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a.\nconst header = \"ad_name,ad_id,spend,impressions,clicks,app_installs,registrations,purchases,purchase_value\";\n\n// \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c .map() \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u041a\u0410\u0416\u0414\u041e\u0413\u041e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\n// \u041c\u0435\u0442\u043e\u0434 .map() \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u0439 \u0436\u0435 \u0434\u043b\u0438\u043d\u044b, \u0447\u0442\u043e \u0438 items\nreturn items.map(item => {\n  // \u0412\u043d\u0443\u0442\u0440\u0438 .map() \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043e\u0434\u043d\u0438\u043c 'item' \u0437\u0430 \u0440\u0430\u0437.\n  // \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e json-\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\n  const currentJson = item.json;\n\n  // \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0422\u0415\u041a\u0423\u0429\u0415\u0413\u041e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n  const row = [\n    `\"${currentJson.name.replace(/\"/g, '\"\"')}\"`, // \u042d\u043a\u0440\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0432\u044b\u0447\u043a\u0438\n    currentJson.ad_id || 0,\n    currentJson.spend || 0,\n    currentJson.impressions || 0,\n    currentJson.clicks || 0,\n    currentJson.actions?.find(a => a.action_type.includes('app_install'))?.value || 0,\n    currentJson.actions?.find(a => a.action_type.includes('complete_registration'))?.value || 0,\n    currentJson.actions?.find(a => a.action_type.includes('purchase'))?.value || 0,\n    currentJson.action_values?.find(a => a.action_type.includes('purchase'))?.value || 0\n  ].join(',');\n\n  // \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0422\u0415\u041a\u0423\u0429\u0415\u0413\u041e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.\n  // \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 + \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 CSV.\n  return {\n    json: {\n      ...currentJson, // \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n      creative_csv_data: `${header}\\n${row}` // \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 CSV\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "5dac1e5f-a814-48a7-beaf-b0657d1ff926",
      "name": "Prepare CSV for Gemini",
      "type": "n8n-nodes-base.code",
      "position": [
        1808,
        -160
      ],
      "parameters": {
        "jsCode": "// \u041e\u043f\u0440\u0435\u0434\u0435\u043b\u044f\u0435\u043c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 CSV \u043e\u0434\u0438\u043d \u0440\u0430\u0437, \u043e\u043d\u0438 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b\u043c\u0438 \u0434\u043b\u044f \u0432\u0441\u0435\u0445 \u0441\u0442\u0440\u043e\u043a.\nconst header = \"ad_name,ad_id,spend,impressions,clicks,app_installs,registrations,purchases,purchase_value\";\n\n// \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c .map() \u0434\u043b\u044f \u043f\u0440\u0435\u043e\u0431\u0440\u0430\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u041a\u0410\u0416\u0414\u041e\u0413\u041e \u0432\u0445\u043e\u0434\u044f\u0449\u0435\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\n// \u041c\u0435\u0442\u043e\u0434 .map() \u0432\u0435\u0440\u043d\u0435\u0442 \u043d\u043e\u0432\u044b\u0439 \u043c\u0430\u0441\u0441\u0438\u0432 \u0442\u043e\u0439 \u0436\u0435 \u0434\u043b\u0438\u043d\u044b, \u0447\u0442\u043e \u0438 items\nreturn items.map(item => {\n  // \u0412\u043d\u0443\u0442\u0440\u0438 .map() \u043c\u044b \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u043c \u0441 \u043e\u0434\u043d\u0438\u043c 'item' \u0437\u0430 \u0440\u0430\u0437.\n  // \u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0435\u0433\u043e json-\u0441\u043e\u0434\u0435\u0440\u0436\u0438\u043c\u043e\u0435\n  const currentJson = item.json;\n\n  // \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0434\u043b\u044f \u0422\u0415\u041a\u0423\u0429\u0415\u0413\u041e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u044f \u0441\u0442\u0440\u043e\u043a\u0443 \u0441\u043e \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u044f\u043c\u0438\n  const row = [\n    `\"${currentJson.name.replace(/\"/g, '\"\"')}\"`, // \u042d\u043a\u0440\u0430\u043d\u0438\u0440\u0443\u0435\u043c \u043a\u0430\u0432\u044b\u0447\u043a\u0438\n    currentJson.ad_id || 0,\n    currentJson.spend || 0,\n    currentJson.impressions || 0,\n    currentJson.clicks || 0,\n    currentJson.actions?.find(a => a.action_type.includes('app_install'))?.value || 0,\n    currentJson.actions?.find(a => a.action_type.includes('complete_registration'))?.value || 0,\n    currentJson.actions?.find(a => a.action_type.includes('purchase'))?.value || 0,\n    currentJson.action_values?.find(a => a.action_type.includes('purchase'))?.value || 0\n  ].join(',');\n\n  // \u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u043e\u0432\u0443\u044e \u0441\u0442\u0440\u0443\u043a\u0442\u0443\u0440\u0443 \u0434\u043b\u044f \u0422\u0415\u041a\u0423\u0429\u0415\u0413\u041e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430.\n  // \u041e\u043d\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c \u0432\u0441\u0435 \u0441\u0442\u0430\u0440\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 + \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 CSV.\n  return {\n    json: {\n      ...currentJson, // \u0421\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c \u0432\u0441\u0435 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435\n      creative_csv_data: `${header}\\n${row}` // \u0414\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u043d\u043e\u0432\u043e\u0435 \u043f\u043e\u043b\u0435 \u0441 CSV\n    }\n  };\n});"
      },
      "typeVersion": 2
    },
    {
      "id": "9d019e72-f72f-4e52-8ec2-cdf83fb57700",
      "name": "Ad data from Gemini",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2432,
        -160
      ],
      "parameters": {
        "columns": {
          "value": {
            "AdID": "={{ $json.output.ad_id }}",
            "summary G": "={{ $json.output.summary }}",
            "evaluation G": "={{ $json.output.evaluation }}",
            "significance G": "={{ $json.output.significance }}",
            "recommendation G": "={{ $json.output.recommendation }}"
          },
          "schema": [
            {
              "id": "FileName",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "FileName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CreativeID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "CreativeID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Type",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "campaign_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "campaign_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdsetID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AdsetID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AdID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Image",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Impressions",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Impressions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "spend",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "spend",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "link_click",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "link_click",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "app_install",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "app_install",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "complete_registration",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "complete_registration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "add_to_cart",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "add_to_cart",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "initiate_checkout",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "initiate_checkout",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "purchase",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "purchase",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "value",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "value",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "evaluation",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "evaluation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "significance",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "significance",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "recommendation",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "recommendation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "evaluation G",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "evaluation G",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "significance G",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "significance G",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary G",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "summary G",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "recommendation G",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "recommendation G",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "AdID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw/edit#gid=0",
          "cachedResultName": "Creatives"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "4214e518-1d16-4d4f-83c1-271fe0ab4e61",
      "name": "Ad data from OpenAI",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2640,
        -480
      ],
      "parameters": {
        "columns": {
          "value": {
            "AdID": "={{ $json.ad_id }}",
            "summary": "={{ $json.summary }}",
            "evaluation": "={{ $json.evaluation }}",
            "significance": "={{ $json.significance }}",
            "recommendation": "={{ $json.recommendation }}"
          },
          "schema": [
            {
              "id": "FileName",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "FileName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CreativeID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "CreativeID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Type",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "campaign_id",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "campaign_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdsetID",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "AdsetID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AdID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Image",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Impressions",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Impressions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "spend",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "spend",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "link_click",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "link_click",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "app_install",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "app_install",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "complete_registration",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "complete_registration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "add_to_cart",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "add_to_cart",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "initiate_checkout",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "initiate_checkout",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "purchase",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "purchase",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "value",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "value",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "evaluation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "evaluation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "significance",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "significance",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "recommendation",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "recommendation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "row_number",
              "type": "number",
              "display": true,
              "removed": true,
              "readOnly": true,
              "required": false,
              "displayName": "row_number",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "AdID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "update",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw/edit#gid=0",
          "cachedResultName": "Creatives"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6,
      "alwaysOutputData": true
    },
    {
      "id": "bed8d683-fe25-4910-98c4-23ae96418579",
      "name": "Send data to 4.1-NANO",
      "type": "@n8n/n8n-nodes-langchain.openAi",
      "position": [
        2016,
        -480
      ],
      "parameters": {
        "modelId": {
          "__rl": true,
          "mode": "list",
          "value": "gpt-4.1-nano",
          "cachedResultName": "GPT-4.1-NANO"
        },
        "options": {
          "maxTokens": 6000,
          "temperature": 0.4
        },
        "messages": {
          "values": [
            {
              "role": "system",
              "content": "=You are the lead performance marketer at Digital Agency, a Meta Ads specialist.\nYour core strength is deep, objective analysis of creatives using funnel metrics (Impressions \u2192 Clicks \u2192 Installs \u2192 Registrations \u2192 Add to Cart \u2192 Checkouts Initiated).\nYou compare test creatives with internal benchmarks and give clear recommendations on whether to scale, keep testing, or stop a creative.\nYour goal is to help make decisions, not just repeat the data."
            },
            {
              "content": "=**BENCHMARKS_DATA (top-performing creatives with calculated metrics like CTR, CPC, CPA, ROAS, etc.)**\n*This is a CSV string with data from your top-performing creatives. All key metrics are pre-calculated here.*\n{{ $('Set parameters').item.json.benchmarks_data }}\n\n**ANALYSIS_DATA (raw test data without calculated metrics)**:\n\n{{ $json.creative_csv_data }}\n\n*Context*:\n\t\u2022\tEasyBusy is a business aggregator.\n\t\u2022\tDue to a long sales cycle (~30 days) and high average order value, there are no Purchases in the data.\n\t\u2022\tWe use Checkouts Initiated as a proxy conversion metric and also track the full funnel.\n\n**Your task**:\n\t1.\tCalculate the same metrics for the test creatives as in the benchmark data (CTR, CPC, CPA, ROAS, etc.).\n\t2.\tCompare each test creative against the benchmarks:\n\t\u2022\tMetric-by-metric (e.g. higher CTR but worse CPC)\n\t\u2022\tFunnel quality (is there drop-off or strength at any step?)\n\t3.\tAnswer the following:\n\t\u2022\tDo we have enough data to draw conclusions for each creative?\n\t\u2022\tWhich creatives are ready to scale now? Why?\n\t\u2022\tWhich creatives should continue testing?\n\t\u2022\tWhich creatives should be stopped?\n\nOUTPUT FORMAT \u2014 ONLY JSON ARRAY OF CREATIVES:\n\nDo not write any explanation, markdown, or formatting outside of the array. Just return a single JSON array like this:\nYou must include ALL creatives in a SINGLE JSON array \u2014 not split across multiple responses. \nRespond in ONE single message. Do NOT return one object per message.\n\n**Each object must follow this structure**:\n{\n  \"ad_id\": \"string (ad_id from ANALYSIS_DATA dataset)\",\n  \"evaluation\": \"high | medium | low\",\n  \"significance\": \"yes | no\",\n  \"summary\": \"2\u20133 sentence explanation of why this creative got this score\",\n  \"recommendation\": \"scale | optimize | stop\"\n}\n\n*Example*:\n[\n  {\n    \"ad_id\": \"1202153606616005\",\n    \"evaluation\": \"high\",\n    \"significance\": \"yes\",\n    \"summary\": \"CTR and CPC are significantly better than benchmarks, with a strong funnel down to Checkouts Initiated.\",\n    \"recommendation\": \"scale\"\n  },\n  {\n    \"ad_id\": \"92021533361600510\",\n    \"evaluation\": \"low\",\n    \"significance\": \"yes\",\n    \"summary\": \"Low CTR and high CPC. Almost no meaningful downstream activity.\",\n    \"recommendation\": \"stop\"\n  }\n]\n\nIf there isn\u2019t enough data, set \"significance\": \"no\" and clearly explain the reason in summary. Still provide the other fields.\n\n**Important**:\n\t\u2022\tNo markdown\n\t\u2022\tNo extra text\n\t\u2022\tOutput = only one clean JSON array"
            },
            {
              "role": "assistant",
              "content": "=Do not return each creative in a separate message. You must return a SINGLE JSON array that includes ALL creatives from the dataset."
            }
          ]
        },
        "jsonOutput": true
      },
      "credentials": {
        "openAiApi": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 1.8
    },
    {
      "id": "acbba7e0-6a6f-4138-981e-7bc7b7d6e82c",
      "name": "Send data to Gemini",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "position": [
        2032,
        -160
      ],
      "parameters": {
        "text": "=You are the lead performance marketer at Digital Agency, a Meta Ads specialist.\nYour core strength is deep, objective analysis of creatives using funnel metrics (Impressions \u2192 Clicks \u2192 Installs \u2192 Registrations \u2192 Add to Cart \u2192 Checkouts Initiated). You compare test creatives with internal benchmarks and give clear recommendations on whether to scale, keep testing, or stop a creative.\nYour goal is to help make decisions, not just repeat the data.\n\nINPUT DATA\n**1. BENCHMARKS_DATA**:\n*This is a CSV string with data from your top-performing creatives. All key metrics are pre-calculated here.*\n{{ $('Set parameters').item.json.benchmarks_data }}\n\n**2. ANALYSIS_DATA (raw test data without calculated metrics)**:\n{{ $json.creative_csv_data }}\n\nContext:\n\t\u2022\tEasyBusy is a business aggregator.\n\t\u2022\tDue to a long sales cycle (~30 days) and high average order value, there are no Purchases in the data.\n\t\u2022\tWe use Checkouts Initiated as a proxy conversion metric and also track the full funnel.\n\n**Your task:**\n1. Calculate metrics for each creative in ANALYSIS_DATA. Use the following formulas:\n- CTR (link click-through rate) = Link clicks / Impressions\n- CPC (cost per link click) = Amount spent (USD) / Link clicks\n- IPM (Installs per 1000 impressions) = App Installs / (Impressions / 1000)\n- Cost per App Install = Amount spent (USD) / App Installs\n- CR install to reg = Registrations completed / App Installs\n- Cost per registration completed = Amount spent (USD) / Registrations completed\n- Cost per add to cart = Amount spent (USD) / Adds to cart\n- Cost per checkout initiated = Amount spent (USD) / Checkouts initiated\n- If a denominator is zero, the resulting metric should be 0 or null.\n2. Analyze each creative from ANALYSIS_DATA according to the following rules:\n- Rule for determining statistical significance (significance):\n--Consider the data sufficient (\"significance\": \"yes\") if BOTH of the following conditions are met:\n--- Amount spent (USD) > 49\n--- Impressions > 10,000\nOtherwise, set \"significance\": \"no\".\n-Rule for evaluation (evaluation):\n-- Compare the key metrics of the test creative (CTR, CPC, Cost per App Install, Cost per checkout initiated) against the average values of the same metrics from the BENCHMARKS_DATA file.\n-- \"high\": The creative significantly outperforms the benchmark averages on key funnel metrics (e.g., higher CTR, and lower CPC and Cost per checkout initiated).\n-- \"medium\": The creative shows mixed results or performs on par with the benchmarks. For example, a good CTR but an expensive Cost per checkout initiated.\n-- \"low\": The creative significantly underperforms the benchmarks on most key metrics.\n3. Based on your analysis, provide a final JSON object containing the ad_id from the input data, and your calculated values for evaluation, significance, summary, and recommendation. For the summary, provide a 2-3 sentence explanation. If there is not enough data, set \"significance\" to \"no\" and explain why in the summary.",
        "options": {},
        "promptType": "define",
        "hasOutputParser": true
      },
      "typeVersion": 2.1,
      "alwaysOutputData": true
    },
    {
      "id": "c763d9da-66e1-41a6-881f-6f3f210395aa",
      "name": "Ad metrics",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        2112,
        -672
      ],
      "parameters": {
        "columns": {
          "value": {
            "AdID": "={{ $json.ad_id }}",
            "Type": "={{ $('Merge').item.json.creative.object_type }}",
            "Image": "==IMAGE(\"{{ $json.video_image_url ?? $json.image_url }}\",1)",
            "spend": "={{ $json.spend }}",
            "value": "={{ $json.value }}",
            "AdsetID": "={{ $json.adset_id }}",
            "FileName": "={{ $json.ad_name }}",
            "purchase": "={{ $json.purchase }}",
            "CreativeID": "={{ $('Merge').item.json.creative.id }}",
            "link_click": "={{ $('Insights Split Out').item.json.clicks }}",
            "Impressions": "={{ $json.impressions }}",
            "add_to_cart": "={{ $json.add_to_cart }}",
            "app_install": "={{ $json.app_installs }}",
            "campaign_id": "={{ $json.campaign_id }}",
            "initiate_checkout": "={{ $json.initiate_checkout }}",
            "complete_registration": "={{ $json.complete_registration }}"
          },
          "schema": [
            {
              "id": "FileName",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "FileName",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "CreativeID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "CreativeID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Type",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "Type",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Timestamp",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "Timestamp",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "campaign_id",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "campaign_id",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdsetID",
              "type": "string",
              "display": true,
              "required": false,
              "displayName": "AdsetID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "AdID",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "AdID",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Image",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Image",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "Impressions",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "Impressions",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "spend",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "spend",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "link_click",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "link_click",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "app_install",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "app_install",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "complete_registration",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "complete_registration",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "add_to_cart",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "add_to_cart",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "initiate_checkout",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "initiate_checkout",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "purchase",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "purchase",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "value",
              "type": "string",
              "display": true,
              "removed": false,
              "required": false,
              "displayName": "value",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "evaluation",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "evaluation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "significance",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "significance",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "summary",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "summary",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            },
            {
              "id": "recommendation",
              "type": "string",
              "display": true,
              "removed": true,
              "required": false,
              "displayName": "recommendation",
              "defaultMatch": false,
              "canBeUsedToMatch": true
            }
          ],
          "mappingMode": "defineBelow",
          "matchingColumns": [
            "AdID"
          ],
          "attemptToConvertTypes": false,
          "convertFieldsToString": false
        },
        "options": {},
        "operation": "appendOrUpdate",
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": "gid=0",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw/edit#gid=0",
          "cachedResultName": "Creatives"
        },
        "documentId": {
          "__rl": true,
          "mode": "id",
          "value": "=1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "1b303d83-c74f-44a9-89e3-3963d707048f",
      "name": "Get Ads from Sheet",
      "type": "n8n-nodes-base.googleSheets",
      "position": [
        672,
        -288
      ],
      "parameters": {
        "options": {},
        "sheetName": {
          "__rl": true,
          "mode": "list",
          "value": 1754847770,
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw/edit#gid=1754847770",
          "cachedResultName": "Test Ads Analysis"
        },
        "documentId": {
          "__rl": true,
          "mode": "list",
          "value": "1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw",
          "cachedResultUrl": "https://docs.google.com/spreadsheets/d/1gwBOLHpez5fFX9C2m6PoZcsw5LLcjjbR7448jn6cimw/edit?usp=drivesdk",
          "cachedResultName": "AutoTest_of_Creatives_v2"
        }
      },
      "credentials": {
        "googleSheetsOAuth2Api": {
          "name": "<your credential>"
        }
      },
      "typeVersion": 4.6
    },
    {
      "id": "5ab1c7cc-3016-4125-ad8a-20f07fb66731",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        -64,
        -1200
      ],
      "parameters": {
        "color": 5,
        "width": 672,
        "height": 640,
        "content": "### Ads Performance Analysis with AI\n\nThis workflow automates the in-depth analysis of Meta Ads creatives by leveraging the analytical power of AI models (OpenAI and Google Gemini). It fetches performance data, compares it against historical benchmarks, and provides actionable recommendations (\"scale\", \"optimize\", \"stop\") for each creative.\n\nThe system is designed for high flexibility and can be used in two primary ways:\n1.  **As a standalone tool:** By setting the `source` to \"Meta\" and providing a `campaign_id` in the configuration node, it will automatically analyze all active ads in a campaign.\n2.  **As a continuation of the \"Creative Testing Automation\" workflow:** By setting the `source` to \"Sheets\", it can read a list of newly created `AdID`s from a Google Sheet and analyze them.\n\nThe core of this workflow is its AI-driven analysis. It feeds raw performance metrics and pre-defined benchmarks (stored in the configuration node) to AI models, which then act as expert performance marketers to evaluate each creative's potential.\n\n**Key Features:**\n- **Dual AI Analysis:** Runs parallel analyses using both OpenAI and Google Gemini for comparative insights.\n- **Dynamic Benchmarking:** Easily update performance benchmarks in a central configuration node to keep the AI's analysis relevant.\n- **Resilient & Fault-Tolerant:** The workflow is architected to be robust. It first logs raw metrics to a Google Sheet and then updates the same row with AI analysis. If an AI model fails, the core data is still saved.\n- **Flexible Data Sourcing:** Pulls data directly from Meta Ads or from a preparatory Google Sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "0bb38ad0-19df-45c0-a6c1-6f3389989661",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        64,
        -288
      ],
      "parameters": {
        "color": 6,
        "width": 544,
        "height": 352,
        "content": "**\u2699\ufe0f 1. Main Configuration**\n\nThis is the control center for the entire workflow.\n\n**1. Choose a Source (source):**\n- **`Meta`** - to analyze an entire ad campaign (you'll need to set the `campaign_id` below).\n- **`sheets`** - to analyze creatives from a Google Sheet (you'll need to configure the \"Get Ads from Sheet\" node).\n\n**2. Add Your Benchmarks (benchmarks_data):**\n- Paste your top-performing creative data here in CSV format(a standard export from Ads Manager is perfect for this). The AI will use this for comparison and analysis.\n- **The higher the quality of your benchmarks, the more accurate the results.**"
      },
      "typeVersion": 1
    },
    {
      "id": "521dc7b9-0c91-4ad6-9deb-782144bf3b72",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1536,
        -912
      ],
      "parameters": {
        "color": 7,
        "width": 528,
        "height": 256,
        "content": "**\ud83d\udcc8 2. Metrics Preparation**\n\nThis node \"unpacks\" the data from the Meta API response, preparing it for the Google Sheet and for the AI.\n\n- The main metrics (spend, impressions, clicks, actions) are already set up.\n- You can add extraction for **custom conversions** or any other fields you need from the Facebook response here.\n\nAll fields added here will be written to the Google Sheet."
      },
      "typeVersion": 1
    },
    {
      "id": "9ce178d1-f191-4ece-8c12-146256cec783",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1952,
        -352
      ],
      "parameters": {
        "color": 4,
        "width": 624,
        "height": 256,
        "content": "**\ud83e\udd16 3. AI Scoring **\n\nDon't be afraid to **experiment with the prompts!**\n\n- The template includes a quality base prompt, but it can and should be adapted to your specific tasks, KPIs, and business context.\n- Try different phrasing to find the most effective combination for your goals. **The quality of the analysis directly depends on the quality of the prompt!**"
      },
      "typeVersion": 1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8b469281-9218-42b9-95b6-5de9b7e853a8",
  "connections": {
    "If": {
      "main": [
        [
          {
            "node": "Get Ads",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Get Ads from Sheet",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Merge": {
      "main": [
        [
          {
            "node": "Prepare CSV for OpenAI",
            "type": "main",
            "index": 0
          },
          {
            "node": "Set Metrics",
            "type": "main",
            "index": 0
          },
          {
            "node": "Prepare CSV for Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Ads": {
      "main": [
        [
          {
            "node": "Ads Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Split Out": {
      "main": [
        [
          {
            "node": "Ad data from OpenAI",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set Metrics": {
      "main": [
        [
          {
            "node": "Ad metrics",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Insights": {
      "main": [
        [
          {
            "node": "Insights Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Ads Split Out": {
      "main": [
        [
          {
            "node": "Get Insights",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Ad Details": {
      "main": [
        [
          {
            "node": "Get Insights",
            "type": "main",
            "index": 0
          },
          {
            "node": "Merge",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Set parameters": {
      "main": [
        [
          {
            "node": "If",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Schedule Trigger": {
      "main": [
        [
          {
            "node": "Set parameters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Get Ads from Sheet": {
      "main": [
        [
          {
            "node": "Get Ad Details",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Insights Split Out": {
      "main": [
        [
          {
            "node": "Merge",
            "type": "main",
            "index": 1
          }
        ]
      ]
    },
    "Send data to Gemini": {
      "main": [
        [
          {
            "node": "Ad data from Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Send data to 4.1-NANO": {
      "main": [
        [
          {
            "node": "Split Out",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare CSV for Gemini": {
      "main": [
        [
          {
            "node": "Send data to Gemini",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Prepare CSV for OpenAI": {
      "main": [
        [
          {
            "node": "Send data to 4.1-NANO",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Google Gemini Chat Model": {
      "ai_languageModel": [
        [
          {
            "node": "Send data to Gemini",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    },
    "Structured Output Parser": {
      "ai_outputParser": [
        [
          {
            "node": "Send data to Gemini",
            "type": "ai_outputParser",
            "index": 0
          }
        ]
      ]
    }
  }
}