"LinkedIn ad library" gets about 5,400 US searches a month. Most of those people want the same thing: see what a competitor is running on LinkedIn, how big each campaign was, and who it was aimed at. Then they want to check again next week without clicking through dozens of ad cards. LinkedIn's Ad Library is public and needs no login. But it's a browse-only website, and the most useful numbers only show up for some ads.
This post builds liads.mjs, a ~200-line Node.js script with no npm dependencies, that turns the library into data you can work with:
-
pullsaves every ad for one company (filtered by country and date) to a JSONL snapshot -
reportturns snapshots into a competitor summary: formats, impression ranges, where impressions actually landed, which targeting facets were used, and the biggest ads -
diffcompares two snapshots, so a weekly cron job can tell you what's new
Everything below ran on November 30, 2026 (04:00-05:00 UTC) with Node.js 24 on a Linux server. The examples compare HubSpot, Salesforce and Pipedrive in the DACH countries (Germany, Austria, Switzerland), plus Notion in the US and in the EU.
Read this first: LinkedIn's terms prohibit scraping. Section 8.2 of the LinkedIn User Agreement (effective November 3, 2025) says you may not "develop, support or use software, devices, scripts, robots or any other means or processes (such as crawlers, browser plugins and add-ons or any other technology) to scrape or copy the Services".
linkedin.com/robots.txtends withUser-agent: */Disallow: /. The Ad Library is a public transparency tool, but the terms still apply to it. Review them and the legal risk for your use case and country before you run anything here. If you can get it, use the official LinkedIn Ad Library API (api.linkedin.com/rest/adLibrary?q=criteria). It's a separate product you request for an app in the LinkedIn Developer Portal, and LinkedIn reviews each request. Keep volumes small, and stick to company advertisers as this post does. Don't build profiles of the individual people who show up as "posters" on thought-leader ads.
Step 1: What a plain Node.js script gets
Before writing a parser, I checked what LinkedIn returns to an ordinary fetch with a desktop Chrome user agent, and what the official API says without a token:
// probe.mjs - what a plain Node.js script gets from LinkedIn's Ad Library and its official API. const UA = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"; const targets = [ ["robots.txt", "https://www.linkedin.com/robots.txt", {}], ["library search", "https://www.linkedin.com/ad-library/search?accountOwner=HubSpot&countries=DE", {}], ["ad detail page", "https://www.linkedin.com/ad-library/detail/1643987424", {}], ["official API, no token", "https://api.linkedin.com/rest/adLibrary?q=criteria&advertiser=HubSpot&count=25", { "X-Restli-Protocol-Version": "2.0.0", "LinkedIn-Version": "202610" }], ]; for (const [label, url, extra] of targets) { const res = await fetch(url, { headers: { "user-agent": UA, "accept-language": "en-US,en;q=0.9", ...extra } }); const body = await res.text(); const hint = body.match(/<title>([^<]*)<\/title>/)?.[1] ?? body.match(/User-agent: \*\nDisallow: .*/)?.[0].replace("\n", " / ") ?? body.slice(0, 90); console.log(`${label.padEnd(23)} ${res.status} ${String(body.length).padStart(6)} B ${hint.trim()}`); } robots.txt 200 120235 B User-agent: * / Disallow: / library search 403 4557 B Attention Required! | Cloudflare ad detail page 403 4557 B Attention Required! | Cloudflare official API, no token 401 105 B {"status":401,"serviceErrorCode":65604,"code":"EMPTY_ACCESS_TOKEN","message":"Empty oauth2 From my server, both library pages came back as Cloudflare's "Attention Required!" block page (HTTP 403, 4.5 KB), not the ad cards. A home connection may get further. But this is the first wall you'll hit if you run a scraper from a cloud VM or a CI job, and retrying from the same IP doesn't help. The official endpoint exists and answers immediately. It just wants an OAuth token from an app that was approved for the Ad Library API product.
So there are two real options:
- Official API: apply for the Ad Library API product. If you're approved, the response has the targeting facets, impression ranges and per-country splits in structured form. Third-party write-ups say it doesn't include the ad text or image (you get
adUrlback), and that it's throttled per minute. - A data API that reads the public pages for you. That's what the rest of this post uses.
Step 2: What the library actually publishes (and the EU catch)
Every ad card shows the advertiser, the "paid for by" entity, the format and the creative. The interesting fields are impressions, run dates, a per-country split and targeting, and LinkedIn only publishes those for ads targeted at the EU (that's what the EU Digital Services Act requires). A US-only campaign shows you the creative and nothing else.
Here's one HubSpot ad after the script below has normalized it (country list shortened):
{ "id": "1643987424", "url": "https://www.linkedin.com/ad-library/detail/1643987424", "advertiser": "HubSpot", "companyId": "68529", "paidForBy": "HubSpot, Inc.", "adType": "Video Ad", "start": "2026-11-17", "end": "2026-11-30", "days": 14, "impressions": { "label": "50k-100k", "lo": 50000, "hi": 100000 }, "countries": [ { "country": "Germany", "share": 1 }, { "country": "India", "share": 0.005 }, { "country": "United Kingdom", "share": 0.005 }, { "...": "19 more rows" } ], "targeting": { "language": "Targeting includes English", "location": "Targeting includes Germany", "audience": "Exclusion targeting applied", "company": "Exclusion targeting applied" }, "text": "Das Marketing Team hinter Ihrem Marketing Team.", "cta": "Request Demo", "query": { "companyId": "68529", "countries": "DE,AT,CH", "dateOption": "last-30-days" }, "pulledAt": "2026-11-30T04:12:05.597Z" } Three things to note before writing any code:
- Impressions are ranges, not numbers:
"<\u200a1k","1k-5k","500k-1M","> 1M". That\u200ais a hair space, so a check likelabel === "< 1k"(normal space) never matches. Any sum you compute is a range too. - Country shares are rounded and don't add up to 100%. This ad is
"100%"Germany plus eight countries at"< 1%". - Targeting is mostly a yes/no flag. You see the locations and languages. For company, job, audience or interest targeting you only learn that it was used:
"Exclusion targeting applied", never the list.
Step 3: The client and the parsers
I fetch the library through ScrapeAtlas*, which has /v1/linkedin/ads/search (one library page, with each card filled in from its detail page) and /v1/linkedin/ad (one ad by ID). Each successful call costs 1 credit, and failed calls are free. If you get access to the official API, swap sa() for your own client and keep everything below it.
The first part of liads.mjs is the HTTP helper plus the two parsers for those human-formatted strings:
// liads.mjs - LinkedIn Ad Library competitor report in Node.js (no npm dependencies). // Node 21+ (built-in fetch, Map.groupBy). Read LinkedIn's User Agreement first: section 8.2 bans scraping. // // node liads.mjs pull --company-id 68529 --countries DE,AT,CH --date last-30-days --pages 4 // node liads.mjs report data/68529_DE-AT-CH_20261130-0405.jsonl [more.jsonl ...] // node liads.mjs diff data/old.jsonl data/new.jsonl import { mkdirSync, readFileSync, writeFileSync } from "node:fs"; const API = "https://api.scrapeatlas.com/v1/linkedin"; const KEY = process.env.SCRAPEATLAS_API_KEY ?? ""; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); let credits = 0; async function sa(path, params) { const url = `${API}/${path}?${new URLSearchParams(params)}`; for (let attempt = 1; ; attempt++) { const res = await fetch(url, { headers: { "x-api-key": KEY } }); const body = await res.json().catch(() => ({})); if (res.ok && body.success) { credits++; return body; } if (attempt < 3 && (res.status === 429 || res.status >= 500)) { await sleep(3000 * attempt); continue; } const f = body.failure ?? {}; throw new Error(`${path} -> HTTP ${res.status} ${f.code ?? ""} ${f.message ?? ""}`.trim()); } } // ---------- parsing the strings LinkedIn shows to humans ---------- const UNIT = { k: 1e3, M: 1e6, B: 1e9 }; const num = (s) => { const m = s.trim().match(/^([\d.]+)\s*([kMB]?)$/); return m ? +m[1] * (UNIT[m[2]] ?? 1) : NaN; }; // "1k-5k" -> [1000, 5000]; "<\u200a1k" -> [0, 1000]; "> 1M" -> [1000000, null] (open-ended) export function parseRange(label) { if (!label) return null; const s = label.replace(/[\u200a\u2009\u00a0\s]/g, ""); if (s.startsWith("<")) return [0, num(s.slice(1))]; if (s.startsWith(">")) return [num(s.slice(1)), null]; if (s.endsWith("+")) return [num(s.slice(0, -1)), null]; const [lo, hi] = s.split("-").map(num); return Number.isNaN(lo) || Number.isNaN(hi) ? null : [lo, hi]; } // "28%" -> 0.28; "< 1%" -> 0.005 (we only know it is under 1%, so take the middle) export function parseShare(label) { const s = label.replace(/[\u200a\u2009\u00a0\s]/g, ""); if (s.startsWith("<")) return parseFloat(s.slice(1)) / 200; return parseFloat(s) / 100; } const clean = (s) => (s ?? "").replace(/\s+/g, " ").trim(); const day = (iso) => (iso ? iso.slice(0, 10) : null); function normalize(ad, query) { const imp = parseRange(ad.totalImpressions); const days = ad.startDate && ad.endDate ? Math.round((Date.parse(ad.endDate) - Date.parse(ad.startDate)) / 864e5) + 1 : null; return { id: ad.id, url: ad.url, advertiser: ad.advertiser, companyId: ad.advertiserLinkedinPage?.match(/company\/(\d+)/)?.[1] ?? null, paidForBy: ad.paidForBy, adType: ad.adType, start: day(ad.startDate), end: day(ad.endDate), days, impressions: ad.totalImpressions ? { label: clean(ad.totalImpressions), lo: imp?.[0] ?? null, hi: imp?.[1] ?? null } : null, countries: (ad.impressionsByCountry ?? []).map((c) => ({ country: c.country, share: parseShare(c.impressions) })), targeting: Object.fromEntries(Object.entries(ad.targetingDetails ?? {}).map(([k, v]) => [k, clean(v)])), text: clean(ad.headline || ad.description).slice(0, 90), cta: ad.cta, query, pulledAt: new Date().toISOString(), }; } normalize() keeps targetingDetails rather than targeting. The two fields hold the same facets, but in targeting long location lists come back with raw markup whitespace and a collapsed "and\n \n 36 others\n" in the middle. companyId comes from the advertiser's page URL. It matters in Step 4.
A test with labels copied from real responses (node --test):
// node --test (checks the two parsers against labels copied from real responses) import test from "node:test"; import assert from "node:assert/strict"; import { parseRange, parseShare } from "./liads.mjs"; test("impression ranges", () => { assert.deepEqual(parseRange("1k-5k"), [1000, 5000]); assert.deepEqual(parseRange("500k-1M"), [500000, 1000000]); assert.deepEqual(parseRange("<\u200a1k"), [0, 1000]); assert.deepEqual(parseRange("> 1M"), [1000000, null]); assert.equal(parseRange(null), null); }); test("country shares", () => { assert.equal(parseShare("28%"), 0.28); assert.equal(parseShare("100%"), 1); assert.equal(parseShare("<\u200a1%"), 0.005); }); ✔ impression ranges (2.242563ms) ✔ country shares (0.259242ms) ℹ tests 2 ℹ pass 2 ℹ fail 0 Step 4: Pulling every ad for one company
// ---------- pull ---------- function flags(argv) { const out = {}; for (let i = 0; i < argv.length; i++) if (argv[i].startsWith("--")) out[argv[i].slice(2)] = argv[i + 1]?.startsWith("--") || argv[i + 1] === undefined ? true : argv[++i]; return out; } async function pull(argv) { const f = flags(argv); if (!KEY) throw new Error("set SCRAPEATLAS_API_KEY"); const query = {}; if (f["company-id"]) query.companyId = f["company-id"]; if (f.company) query.company = f.company; if (f.keyword) query.keyword = f.keyword; if (f.countries) query.countries = f.countries; query.dateOption = f.date ?? "last-30-days"; const pages = Number(f.pages ?? 1); const rows = new Map(); let token = null, failed = [], total = null, broke = false; for (let page = 1; p...