AI Competitor Ad Analysis and Copy Generation - n8n Workflow

Use this robust n8n workflow to automate competitive intelligence. Scrape Facebook ads using Apify, analyze video, image, and text content with OpenAI and Gemini, and log insights to Google Sheets.

Workflow Preview

Ready to automate?

Download this n8n workflow template and start using it instantly.

Who is this best for?

Markdown-formatted text:

Marketing Agencies: Looking to scale competitor monitoring and generate data-driven ad copy for clients.
PPC Specialists: Needing an automated way to track high-performing Facebook ad creative and messaging strategies.
AI Automation Builders: Seeking complex n8n templates that integrate external scraping APIs (Apify) with advanced AI models (Gemini, OpenAI).
Data Analysts: Requiring a consistent pipeline to extract, classify, and enrich unstructured ad data.

Overview

Understanding competitor advertising strategy is crucial, yet manually monitoring the Facebook Ad Library is time-consuming. This powerful n8n workflow solves this problem by creating a fully automated AI ad spy tool.

Starting with an n8n trigger, the system leverages Apify to scrape hundreds of active Facebook ads based on predefined keywords. It then filters for high-quality pages (over 1000 likes) before routing the ads into three distinct processing pipelines based on media type: video, image, or text. The video pipeline uses Google Gemini's multimodal capabilities, involving temporary storage in Google Drive, for deep analysis. The image pipeline uses GPT-4 Vision for creative breakdown. The resulting intelligence—a detailed summary and strategically rewritten ad copy—is logged automatically into a Google Sheet, creating a dynamic, searchable competitive intelligence database. This complex n8n template provides immense business value for agencies seeking a scalable, revenue-generating service.

How it Works

This advanced n8n workflow operates in three main stages:

Stage 1: Data Acquisition and Filtering


  1. Trigger Execution: The process begins with a manual n8n trigger (When clicking ‘Execute workflow’).

  2. Scraping: The Run Ad Library Scraper n8n node executes an Apify task via HTTP Request, retrieving a list of active Facebook ads based on a specific search term (e.g., 'AI automation').

  3. Quality Check: The Filter For Likes n8n node filters the results, ensuring only ads from advertisers with more than 1000 page likes proceed, focusing the analysis on established competitors.

  4. Content Routing: The Switch n8n node determines the content type (Video, Image, or Text) based on the presence of specific media URLs in the scraped data, sending items to the appropriate batch processor. Items are separated using three SplitInBatches nodes.

Stage 2: AI Multi-Modal Analysis

Video Analysis: For video ads, the workflow downloads the video, uploads it to Google Drive, and initiates a complex resumable upload process to the Gemini API using multiple HTTP Request nodes. The Analyze Video with Gemini n8n node then provides a detailed description of the video content.
Image Analysis: For image ads, the Analyze Image n8n node utilizes OpenAI's GPT-4o model (vision capability) to analyze the image URL and generate a descriptive image prompt.


  • Text Analysis: For text-only ads, the content moves directly to summarization.

Stage 3: Summarization and Logging


  1. Summary Generation: In all three branches, an OpenAI n8n node (Output Summary nodes) receives the raw ad data and the AI-generated visual description (where applicable). It uses a specialized prompt to generate two critical pieces of output in JSON format: a comprehensive strategic summary of the ad and a rewrittenAdCopy based on competitive insights.

  2. Data Persistence: The final Google Sheets n8n node (Add as Type = Video/Image/Text) appends all relevant data points—page ID, date, analysis summary, rewritten copy, and the raw AI prompt (image/video description)—into a dedicated Google Sheets database. This completes the fully automated competitor analysis n8n workflow.

Installation Guide

Markdown-formatted text:


  1. Import the n8n template: Copy the provided JSON code and import it into your self-hosted or cloud n8n instance using the 'Import Workflow' option.

  2. Apify Setup: Locate the Run Ad Library Scraper n8n node. Replace in the Authorization header parameter with your actual Apify API key. Customize the search URL within the JSON body if needed.

  3. Google Service Credentials: Set up OAuth2 credentials for the Google Drive and Google Sheets n8n nodes. Ensure the accounts have the necessary permissions to read/write files and spreadsheets.

  4. OpenAI Credentials: Configure your OpenAI API Key for the nodes used for summarization and image analysis (Analyze Image, Output Image Summary/Video Summary/Text Summary).

  5. Gemini API Setup: Due to the use of raw HTTP nodes for Gemini, you must manually insert your Gemini API Key () into the query parameters of the following n8n nodes: Begin Gemini Upload Session, Upload Video to Gemini, and Analyze Video with Gemini.

  6. Google Sheets Target: In all three Add as Type = ... Google Sheets n8n nodes, link the correct Google Sheet document ID and sheet name where you wish to store the competitor analysis data.

Node Details

Markdown-formatted text:

When clicking ‘Execute workflow’ (Manual Trigger): The initial n8n trigger that starts the entire data extraction and processing cycle.
Run Ad Library Scraper (HTTP Request): Sends a POST request to the Apify service to initiate and retrieve results from the Facebook Ad Library scraper. Key Configuration: Uses a Bearer Token for authorization and defines search parameters for active ads over the last 7 days.
Filter For Likes (Filter n8n node): Ensures data quality by allowing only items where the advertiser's page likes count is greater than 1000.
Switch (Logic n8n node): A routing node that checks for the existence of videosdurl or originalimageurl to direct the flow into the appropriate AI processing path (Video, Image, or Text).
Download Video (HTTP Request): Downloads the raw video binary data from the Facebook source URL provided by the scraping result.
Analyze Image (OpenAI n8n node): Uses the gpt-4o model for vision analysis. Takes the ad image URL and generates a comprehensive text description of the creative, which is used as an input prompt for summarization.
Analyze Video with Gemini (HTTP Request): Calls the Gemini API to analyze the uploaded video file, providing a detailed textual description of the video content. This is a crucial step in this multi-modal n8n workflow.
Output [Media Type] Summary (OpenAI n8n node): These nodes utilize a highly structured system prompt with GPT-4.1 to perform strategic competitor analysis. They output a JSON object containing the summary of the competitor's strategy and optimized, rewrittenAdCopy for internal use.


  • Add as Type = [Media Type] (Google Sheets n8n node): The final action n8n node in each path. It appends the classified ad data, the AI summary, the rewritten copy, and the raw visual description prompts to the configured Google Sheet.

Related n8n Workflows

Free

Nodes: 10 Nodes
Updated: December 26 2025
View all
Created by

Hi 👋 I'm Nick. I make money with automation & teach others how they can too. If you have any questions about my templates or about my n8n builds, feel free to ask and I'll happily respond in the comments. Thanks for reading!

Featured*