How to Spy on Competitor Facebook Ads (Meta Ad Library API)
If you are running Facebook Ads in 2025, you are probably spending hours in the Meta Ad Library.
It's the only source of truth for what your competitors are running. You can see their creatives, their headlines, and how long their ads have been active.
But the Meta Ad Library has a problem: It is a manual research tool.
You have to search for each competitor one by one. You have to scroll endlessly. You can't export the data. You can't get alerts when a competitor launches a new creative.
If you are an agency managing 50 clients, or a SaaS company tracking 20 competitors, manual research is impossible.
In this guide, we'll show you how to automate this process using the SociaVault Facebook Ad Library API. We'll build a script that monitors competitors and alerts you to new winning ads.
Why Not Use the Official Meta API?
Meta does have an Ad Library API. However:
- Access is Restricted: You need to undergo identity verification and often need to be a researcher or political organization.
- Rate Limits: Strict limits on how many queries you can make.
- Complexity: It's designed for transparency reporting, not marketing intelligence.
SociaVault's API is designed for marketers. It scrapes the public Ad Library interface, giving you exactly what you see on the screen, but in structured JSON format.
Evaluating Facebook data providers? See our Facebook API alternatives guide.
What Data Can You Extract?
With SociaVault, you can extract:
- Ad Creatives: Images and video thumbnails.
- Ad Copy: The primary text, headline, and description.
- Start Date: When the ad started running (crucial for finding winners).
- Status: Active or Inactive.
- Platforms: Facebook, Instagram, Audience Network, Messenger.
- CTA Buttons: "Shop Now", "Learn More", etc.
Step 1: Searching for Ads
You can search by keyword (e.g., "marketing software") or by Page ID (specific competitor). Searching by Page ID is more accurate for competitor tracking.
Finding a Page ID
You can find a Facebook Page ID by looking at the page source code, or using a "Find my FB ID" tool. Or, you can search for the advertiser using SociaVault first.
The Code (Node.js)
Let's build a script that fetches the active ads for a specific competitor.
const fs = require('fs');
const API_KEY = 'YOUR_SOCIAVAULT_API_KEY';
const PAGE_ID = '105174648626726'; // Example: Jasper.ai
async function getCompetitorAds(pageId) {
const url = `https://api.sociavault.com/v1/scrape/facebook/ads?pageId=${pageId}&active_status=ACTIVE`;
try {
const response = await fetch(url, {
headers: { 'Authorization': `Bearer ${API_KEY}` }
});
const data = await response.json();
if (!data.success) {
console.error('Error:', data.error);
return;
}
console.log(`Found ${data.data.ads.length} active ads.`);
return data.data.ads;
} catch (err) {
console.error('Request failed:', err);
}
}
// Run it
getCompetitorAds(PAGE_ID).then(ads => {
if (ads) {
// Process the ads...
console.log(ads[0]);
}
});
Step 2: Identifying "Winning" Ads
The holy grail of ad spying is finding winners.
A "winner" is an ad that has been running for a long time. If a competitor has been paying to run an ad for 3 months, it is profitable. Period.
Let's filter our results to find these long-running ads.
function findWinningAds(ads) {
const today = new Date();
const thirtyDaysAgo = new Date(today.setDate(today.getDate() - 30));
const winners = ads.filter(ad => {
const startDate = new Date(ad.startDate);
return startDate < thirtyDaysAgo;
});
console.log(`Found ${winners.length} winning ads (running > 30 days).`);
winners.forEach(ad => {
console.log(`\n--- WINNER ---`);
console.log(`Started: ${ad.startDate}`);
console.log(`Headline: ${ad.headline}`);
console.log(`Copy: ${ad.primaryText.substring(0, 100)}...`);
console.log(`Creative: ${ad.imageUrl}`);
});
}
Step 3: Analyzing Ad Copy Trends
Once you have the data, you can analyze the language your competitors are using.
- Hooks: What is the first sentence of their ad copy?
- Angles: Are they focusing on "saving money" or "saving time"?
- CTAs: Are they using "Sign Up" or "Book Demo"?
You can feed the primaryText of all ads into an LLM (like GPT-4) to generate a summary report:
"Analyze these 50 ad copies from Competitor X. Identify the top 3 pain points they are targeting and the emotional hooks they are using."
Building an Automated Dashboard
You don't want to run a script every day. You want a dashboard.
- Database: Store ads in PostgreSQL or Airtable.
- Cron Job: Run the script daily for your top 10 competitors.
- Deduplication: Check if
ad_idalready exists in your DB. If not, it's a New Ad. Send a Slack alert! - Status Check: If an ad was "Active" yesterday but isn't in today's fetch, mark it as "Stopped".
Slack Alert Example:
🚨 New Ad Alert: Jasper.ai Headline: "Write blogs 10x faster" Creative: [Image Link] Started: Today
Conclusion
The Meta Ad Library is a goldmine, but manual mining is inefficient. By using the SociaVault API, you turn a manual chore into an automated intelligence machine.
You stop guessing what works and start modeling what is already proven to work.
Start spying today: Get your API Key and unlock the Ad Library.
Found this helpful?
Share it with others who might benefit
Ready to Try SociaVault?
Start extracting social media data with our powerful API. No credit card required.