Competitive Ads Extractor
- Role
- Sole developer
- Client
- marketing work where competitor ad research was being done by hand, one ad at a time
- Year
- 2026
Stack
Each choice with the reason for it.
Node.js
runtimeThe tool has to install and run anywhere, on a machine that has not been prepared for it. Three dependencies on a runtime that is already present is the whole distribution story.
Meta Ad Library API
infrastructureIt is the only sanctioned route to live ad creative, and it is quirky — pagination, EU DSA caveats, page-ID resolution. Building against it properly was most of the engineering.
PDFKit
toolingThe output has to be something a client can open, not a JSON file. A PDF per run, generated with no headless browser and no service, keeps that promise cheaply.
01 · Context
Knowing what competitors are running on Facebook and Instagram means manually trawling the Meta Ad Library, ad by ad — a job that is tedious at ten ads and impossible at three hundred.
02 · Problem
One command in: a competitor list. One report out: every live ad, clustered into hooks, offers, and the angles nobody in the market has claimed.
03 · Constraints
What was fixed before the work started, and what each constraint ruled out.
- Meta’s Ad Library API is quirky: pagination, EU DSA caveats, page-ID resolution
- Zero budget — no LLM spend on analysis
- Output must be client-presentable — a dashboard and a PDF, not JSON dumps
04 · Approach
Deliberately dependency-light: three packages, no framework, no database, and a rule-based analysis pipeline that is deterministic, free and auditable. The hard engineering went somewhere less glamorous — three-tier competitor resolution that accepts a page URL, a brand name, or a bare domain, because that is the input a real user actually has. That describes the command-line tool, and it is still what the tool is. The hosted console that now wraps it is a second artefact with a different constraint: once other people could run analyses, it needed accounts, admin approval and a database to hold them. The no-database decision was right for a tool with one user and stopped being right the moment there were several — which is the trigger the decision itself predicted, arriving for a reason it did not.
05 · Architecture
Each component, why it beat the alternative, and where it gives way first.
01Resolver
12 regex patterns, 3 user-agent identities- Purpose
- Turns a page URL, a brand name or a bare domain into a Facebook page ID.
- Why this, not the obvious alternative
- Pattern redundancy plus a link-preview user agent finds a page ID even behind Facebook’s login wall, which a single well-behaved request cannot.
What breaks firstThis is the fragile end of the tool, deliberately. Twelve patterns exist because any one of them can stop matching when Facebook changes its markup — resolution is what breaks first, and it breaks loudly rather than returning a wrong page.
Connects to- Fetcher · Page ID
02Fetcher
Ad Library API v21- Purpose
- Pages through every live ad for a resolved page.
- Why this, not the obvious alternative
- Pagination with backoff, and EU data caveats flagged rather than treated as failures — a partial result with a caveat is more useful than an error.
Connects to- Analyser · Ad creative
03Analyser
Rule-based clustering- Purpose
- Folds near-duplicates, then classifies hooks, offers and unclaimed angles.
- Why this, not the obvious alternative
- Jaccard folding at 0.9 similarity, 11 hook types, a 9-offer matrix and a 10-angle gap map. At a few hundred ads this is set theory, not a machine learning problem.
Connects to- Reports · Clusters + gaps
04Reports
Single-file dashboard + PDFKit- Purpose
- Emits Markdown, CSV, JSON and PDF per run into a timestamped folder.
- Why this, not the obvious alternative
- Timestamped folders are the datastore. Each run is a self-contained deliverable a client can be handed without exporting anything.
06 · Implementation
Resolution runs twelve patterns across three user-agent identities, because Facebook shows a link-preview crawler things it will not show a browser without a session — that is the difference between the tool working on a bare domain and asking the user to go and find a page ID. The fetcher pages through Ad Library API v21 with backoff, and treats EU DSA data caveats as annotations on the result rather than errors. Analysis is entirely rule-based: near-duplicates are folded at 0.9 Jaccard similarity before anything is counted, then creative is classified into 11 hook types and a 9-offer matrix, and the interesting output falls out of the negative space — a 10-angle gap map naming the emotional angles nobody in a market has claimed. Every run writes a timestamped folder containing a single-file dashboard, Markdown, CSV, JSON and a PDF, so in the command-line tool there is no database and no export step. Token redaction is applied on every error path, because the fastest way to leak an API token is a stack trace nobody expected to see.
07 · Challenges
What resisted, with the specific symptoms.
- Challenge 01Facebook page-ID resolution behind login walls, where a plain request returns nothing useful
- Challenge 02Near-duplicate ads polluting the clusters, making a single creative look like a campaign trend
- Challenge 03Keeping the API token out of every error path, including the ones that only fire when something else has already gone wrong
08 · Solution
Resolution was solved with a user-agent strategy and pattern redundancy rather than a headless browser — twelve patterns and three identities, so no single markup change takes the tool down. Duplicate pollution was solved by folding at 0.9 Jaccard similarity before classification, so clusters count distinct creative rather than repeats. Token leakage was solved by treating redaction as a discipline applied at the logging boundary, not a filter added to individual handlers.
09 · Results
The outcome in the client’s terms, then any measurement, with its source and date.
Twenty-three real analysis runs across six verticals, 361 ads analysed, and gap maps that name the emotional angles nobody in a market has claimed — produced at zero analysis cost by a tool that installs with three dependencies — and a hosted console on top of it for the people who are not going to install anything.
- Real analysis runs
23 across 6 verticals
- Source
- Self-measured
- Captured
Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.
- Ads analysed
361
- Source
- Self-measured
- Captured
Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.
- Runtime dependencies
3
- Source
- Self-measured
- Captured
The command-line tool: no framework, no database. The hosted console adds both an auth layer and a database.
Self-measured: my own measurement under my own conditions, not independently verified. Treat it as an indication, not evidence.
10 · Reflection
What I would do differently now, and why.
Choosing not to use an LLM was the engineering decision here. At this scale deterministic rules beat a model on cost, speed and auditability, and being able to explain why an ad landed in a cluster is worth more to the person reading the report than a better-sounding summary. An optional LLM layer on top of the clusters is the obvious v2 — on top, not instead of.