DEV Community

Cover image for Analyze the Top-Performing TikTok Ads Programmatically (TikTok Ad Library API)
Olamide Olaniyan
Olamide Olaniyan

Posted on

Analyze the Top-Performing TikTok Ads Programmatically (TikTok Ad Library API)

If you run paid social, TikTok's Creative Center is one of the most underrated tools out there. It shows you the actual top-performing ads by region, industry, and time window — ranked by real metrics like CTR, play rate, and conversions.

The catch: it's a manual browsing tool. You can't export, can't monitor over time, can't pipe it into anything. So I wired it up with the SociaVault TikTok Ad Library API and now I can pull and analyze top ads in code.

Here's a quick build.

The client

const API_KEY = process.env.SOCIAVAULT_API_KEY;
const BASE = "https://api.sociavault.com";

async function sv(path, params = {}) {
  const url = new URL(BASE + path);
  Object.entries(params).forEach(([k, v]) => url.searchParams.set(k, v));
  const res = await fetch(url, { headers: { "X-API-Key": API_KEY } });
  if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
  return res.json();
}
Enter fullscreen mode Exit fullscreen mode

Step 1: Pull the top ads in your niche

Search the Creative Center's top ads, filtered and sorted however you like — here, top beauty ads in the US over the last 7 days, sorted by click-through rate:

async function topAds() {
  const { data } = await sv("/v1/scrape/tiktok-ad-library/search", {
    industry: "beauty_personal_care",
    region: "US",
    period: "7",
    order_by: "ctr",
    limit: "50",
  });
  console.log(`Found ${data.total} top ads`);
  return data.ads;
}
Enter fullscreen mode Exit fullscreen mode

Each ad comes back with the creative text, CTR, likes, video download URLs, and industry/objective classification.

Step 2: Find the patterns

A quick keyword frequency pass over the top ads tells you what angles are dominating right now:

function trendingTerms(ads) {
  const counts = {};
  for (const ad of Object.values(ads)) {
    for (const word of (ad.ad_title ?? "").toLowerCase().split(/\W+/)) {
      if (word.length > 4) counts[word] = (counts[word] || 0) + 1;
    }
  }
  return Object.entries(counts).sort((a, b) => b[1] - a[1]).slice(0, 20);
}
Enter fullscreen mode Exit fullscreen mode

If "peptide" or "glass" shows up in 15 of the top 50 beauty ads, that's a product angle worth testing.

Step 3: Reverse-engineer a single winner

This is the part I didn't expect. The ad detail endpoint returns a second-by-second breakdown — retention, clicks, conversions:

async function studyAd(adId) {
  const { data } = await sv("/v1/scrape/tiktok-ad-library/ad", { ad_id: adId });

  const retention = data.interactive_time_analysis?.remain;
  console.log(`Duration: ${retention.duration}s`);
  retention.analysis.forEach(p =>
    console.log(`  sec ${p.second}: ${(p.value * 100).toFixed(1)}% still watching`)
  );

  // Where do viewers actually click?
  console.log("Click hotspots:", data.interactive_time_analysis?.clicks?.highlight);
  return data;
}
Enter fullscreen mode Exit fullscreen mode

The retention curve is gold. If the top ad in your category holds 55%+ at second 3 and the click spike lands at second 16, you know exactly what hook strength and CTA timing to aim for.

Cost

One credit per search (returns up to 50 ads), one credit per ad detail lookup. A full weekly sweep across a few industries is pennies.

Honest take on alternatives

Tools like PiPiADS, Minea, and BigSpy do similar things with a nicer UI, but they charge $100–300/month and most can't show you the retention curves. If you want a polished dashboard and don't code, those are fine. If you want raw, exportable data and the per-second analysis, the API route is cheaper and richer.

Going further

I wrote up the full creative-research workflow here: TikTok Ad Library API: Research Competitor Ads at Scale and a deeper dive on using retention curves to optimize hooks.

Free key gets you 50 credits — enough to sweep your whole industry and study a dozen winners. Curious what angles are dominating your niche right now?

Top comments (0)