The Facebook Ad Thief Clone Competitor Ads with AI n8n Nano Banana

How to build an AI automation that's able to analyze the best performing live ads that your competitors are running on Facebook and Instagram.

I built an AI agent that finds a competitor's best performing Facebook and Instagram ads, downloads their creatives, and rebuilds those ads with your product and branding. In this guide I will walk you through the full system, explain why each component exists, and give practical tips so you can clone and test competitor creatives at scale.

Join our free AI Automation Community to download the full n8n workflow JSON and get the template I used in this build. The community contains tutorials, templates, and peer support to adapt this agent to your brand.

FB ad cloning automation

Overview

This automation solves a simple business problem. You want to learn which ads in your niche are working and adapt those creatives to promote your product. The agent does three things in sequence

  • Scrapes live ads for a competitor from the Facebook ad library
  • Analyzes each ad and creates a tailored image prompt for editing
  • Generates a final creative with your product using Google Nano Banana and saves it to Google Drive

The core idea is to combine a lightweight scraper with a multi-step AI image editing pipeline that uses a meta-prompt approach to improve output quality.

AG1 source ads

Why this approach works

Trying to write a single catchall prompt for every ad leads to inconsistent results. Ads differ in layout, lighting, text overlays, and the number of product instances on screen. Instead I use a two-step AI flow:

  • Step 1: Ask a text model to analyze the input images and write a customized image editing prompt
  • Step 2: Pass that tailored prompt plus both images to an image editor model to produce the final creative

This metaprompting method lets the text model create context specific instructions for the image editor. The results are cleaner swaps, fewer branding artifacts, and better handling of complex cases like multiple packaging elements.

Tools and components

  • n8n as the automation runner and orchestration layer
  • Apify for scraping the Facebook ad library
  • Google Gemini 2.5 Pro for image analysis and prompt generation
  • Google Nano Banana for image editing and final creative generation
  • Google Drive to store source ads and final cloned creatives
n8n automation overview

Step by step workflow

1. Inputs and trigger

The workflow starts with a form trigger in n8n. You provide two inputs

  • The Facebook ad library URL for a competitor
  • An upload of your product image that will replace the competitor product

These two inputs set up the rest of the pipeline and are stored as fields on the initial node. Make sure the product image shows the packaging and any important angles you want retained in the edit.

n8n Apify scrape url

2. Scrape competitor ads with Appify

Use an Apify actor that targets the Facebook ad library page supplied. In the Apify console use the manual input mode to craft the JSON payload, then paste that into the Apify node inside n8n. Key settings to review

  • Select the Facebook ad library scraper actor
  • Set batching to avoid large single requests
  • Choose the original image URL field where available to get the highest resolution creative

The node returns a list of ad objects including image URLs, text, and metadata. From this payload you extract the image URL that will be downloaded in the next step.

3. Loop over each ad and download the image

Use a loop or batch node to process each ad item one at a time. For each iteration

  • Make an HTTP GET request to download the ad image
  • Upload the raw competitor ad image to a Google Drive source folder for archival
  • Convert the downloaded image and your product image into base64 strings
n8n automation download image

Keeping a repository of original ad assets is important. It lets you inspect edge cases and re-run edits if a generated output needs manual tweaks.

4. Call Gemini to generate a tailored prompt

Send a POST request to Google Gemini 2.5 Pro with three content parts

  1. The text asking Gemini to analyze both images and output a step by step image editing prompt
  2. The base64 inline data of your product image
  3. The base64 inline data of the competitor ad image
n8n automation generate image with nano banana

Gemini returns a refined prompt that understands where to place your product, what lighting adjustments to make, and how to remove or replace the competitor branding. Save that text and pass it to the next node.

5. Generate the edited image with Nano Banana

Make a second POST request to the Google Images endpoint that invokes the Nano Banana editor model. Provide

  • The generated prompt from Gemini
  • Your product image base64 as inline data
  • The competitor ad image base64 as inline data

The API returns one or more candidate content parts. Filter for the part that contains inline base64 image data. If the response includes text parts, ignore those. This filter prevents accidental selection of non-image content.

Nano Banana generate image http body

6. Handle prohibited content and skip logic

Occasionally the image editor returns a prohibited content error. This happens without predictable patterns. To keep the loop running you should

  • Check the API response for a prohibited status
  • If prohibited skip the current item and continue to the next iteration
  • Log or store metadata about skipped items for later review

This approach keeps the batch job resilient and prevents a single failure from stopping the entire job.

7. Convert base64 back to file and save to Google Drive

Once you extract the final base64 inline data from Nano Banana, convert it into a file node in n8n using the base64 to file operation. Then upload the file to a designated Google Drive folder. Name assets using a pattern like Cloned Ad #1 with a running index to avoid collisions.

n8n nano banana ad image result

Conclusion

This Facebook Ad Thief workflow gives you a fast path from competitor ad discovery to brand-ready creatives. The meta-prompt approach reduces artifacts and improves swap quality when compared with single prompt methods. Use the repository of source and cloned images for rapid creative iteration and A/B testing.

Join AI Automation Mastery to download the n8n template and get support from other builders that run these workflows in production.

More AI Tutorials

I Built a Gmail AI Agent for 24/7 Customer Support n8n Template
I Built a Gmail AI Agent for 24/7 Customer Support n8n Template How to build an AI Gmail chatbot agent for local businesses using n8n that is able to respond to customer questions and inquiries around the clock, 24/7
YouTube
How I Generate Unlimited Ad Creative with Nano Banana and n8n Using Gemini 2.5 Flash Image
How I Generate Unlimited Ad Creative with Nano Banana and n8n Using Gemini 2.5 Flash Image How to use Google's Nano Banana to generate infinite ad creatives that feature your product in the hands of influencers.
YouTube
How to Connect WhatsApp to n8n (AI Workflow Tutorial)
How to Connect WhatsApp to n8n (AI Workflow Tutorial) How to connect WhatsApp to n8n so you can power AI agents and automations that send and receive messages.
YouTube
Put Real Products and People into AI Video Ads (Veo 3 Full Tutorial)
Put Real Products and People into AI Video Ads (Veo 3 Full Tutorial) Learn how to use canvas prompting to bring real people and real products into AI generated videos.
YouTube
I Built a Fully-Automated Podcast (with AI + n8n + ElevenLabs)
I Built a Fully-Automated Podcast (with AI + n8n + ElevenLabs) How to build a podcast fully researched, written, and narrated by AI.
YouTube
I Built a WhatsApp Chatbot + AI Agent in n8n for Small Businesses (free template)
I Built a WhatsApp Chatbot + AI Agent in n8n for Small Businesses (free template) How to build a WhatsApp chatbot and AI agent that can handle customer questions about hours, pricing, menus, locations, and appointments in real time.
YouTube