To integrate TikTok Ads with V0 by Vercel, create a Next.js API route that calls the TikTok Marketing API using your Access Token and App ID stored as Vercel environment variables. V0 generates the analytics dashboard UI; the API route fetches campaign data, ad group performance, and creative metrics server-side so your credentials stay secure.
Build a TikTok Ads Analytics Dashboard with V0 and the Marketing API
TikTok is now the dominant short-video advertising platform for reaching Gen Z and millennial audiences, with over 1.5 billion monthly active users. For marketing teams and agencies building V0-powered analytics tools, the TikTok Marketing API provides programmatic access to campaign performance data, audience metrics, creative reports, and conversion tracking — everything needed to build a custom ads dashboard or reporting tool.
The TikTok Marketing API uses a token-based authentication system. Developer apps go through an approval process, and then you generate Long-Term Access Tokens (valid for 30 days) or use OAuth for user-specific advertiser account access. For internal dashboards managing your own TikTok Ads account, the simpler approach is using a Long-Term Access Token with your Advertiser ID, all stored as Vercel environment variables. The Next.js API route handles all TikTok API communication server-side.
V0 generates the analytics UI — charts, tables, date range pickers, and metric cards — while the API route provides the data pipeline. This guide covers fetching campaign performance data (impressions, clicks, spend, conversions) and building a functional reporting dashboard that your marketing team can use directly.
Integration method
V0 generates the ad analytics dashboard UI in Next.js. A server-side API route at app/api/tiktok-ads/route.ts authenticates with the TikTok Marketing API using an Access Token stored in Vercel environment variables, fetches campaign and ad performance data, and returns it to the frontend. No TikTok credentials reach the browser.
Prerequisites
- A TikTok For Business account and access to TikTok Ads Manager
- A TikTok Marketing API developer app created at ads.tiktok.com/marketing_api — this requires an application and approval process
- Your TikTok Marketing API Access Token and Advertiser ID
- A V0 account at v0.dev and a Vercel account for deployment
- Basic understanding of REST APIs and Next.js API routes
Step-by-step guide
Set Up a TikTok Marketing API Developer App
Set Up a TikTok Marketing API Developer App
Before writing any code, you need a TikTok Marketing API developer app. Go to ads.tiktok.com and log in with your TikTok For Business account. Navigate to Tools → API and click 'Create App'. If you don't see the API option, you need to apply for developer access first at ads.tiktok.com/marketing_api — this approval process typically takes 1-3 business days. Once you have developer access and create an app, TikTok will assign you an App ID and App Secret. For internal use (managing your own ad account), navigate to the app details and generate a Long-Term Access Token by clicking 'Get Access Token'. This token grants access to your advertiser account data. You also need your Advertiser ID — find this in TikTok Ads Manager by clicking the account name in the top left corner. The Advertiser ID is the numerical ID shown below your account name. Keep these four values ready: App ID, App Secret, Access Token, and Advertiser ID. The Access Token expires after 30 days and must be refreshed — for production, implement the OAuth refresh flow, but for testing and internal tools, manual refresh works fine.
Pro tip: TikTok's developer application process requires a business justification. Be specific about what data you plan to access and your use case — 'internal analytics dashboard' or 'client reporting tool' typically approves faster than vague descriptions.
Expected result: You have a TikTok Marketing API app with an App ID, App Secret, a valid Access Token, and your Advertiser ID ready.
Generate the Analytics Dashboard UI with V0
Generate the Analytics Dashboard UI with V0
Open V0 at v0.dev and describe your TikTok Ads analytics dashboard. V0 can generate sophisticated analytics UIs with metric cards, data tables with sorting, and chart components powered by recharts or Chart.js. Specify the data shape you expect — campaign name, status, spend, impressions, clicks, CTR, and conversion count. V0 will generate a complete Next.js page with placeholder data and the skeleton of an API route. Since TikTok uses dark branding (black and pink/red), you can ask V0 to style the dashboard with a dark theme and TikTok-inspired colors. The generated component should fetch from /api/tiktok-ads/campaigns on mount using useEffect or SWR. Ask V0 to include a date range picker so users can filter performance data by time period — this is essential for any ads analytics tool. V0 will scaffold the API route stub at app/api/tiktok-ads/route.ts which you will fill in the next step.
Create a TikTok Ads performance dashboard with a dark theme. At the top, show four metric cards (Total Spend, Total Impressions, Total Clicks, Average CTR) with trend arrows. Below that, add a date range picker and a campaigns table with columns: Campaign Name, Status (colored badge), Budget, Spend, Impressions, Clicks, CTR, and Conversions. The table should support sorting by clicking column headers. Fetch data from /api/tiktok-ads/campaigns. Add a loading skeleton while data loads.
Paste this in V0 chat
Pro tip: Include specific placeholder data values in your V0 prompt (e.g., 'campaigns with $5,234 spend, 1.2M impressions') so V0 generates realistic-looking sample data that shows the actual proportions you want in the final UI.
Expected result: V0 generates a dark-themed analytics dashboard with metric cards, a date range picker, and a sortable campaigns table. The project deploys to a Vercel preview URL with placeholder data.
Create the TikTok Marketing API Route
Create the TikTok Marketing API Route
Create the Next.js API route that fetches TikTok campaign data. The TikTok Marketing API base URL is https://business-api.tiktok.com/open_api/v1.3/. Every request requires the Access-Token header and the advertiser_id query parameter. The campaigns report endpoint is /report/integrated/get/ which returns both campaign details and metrics in a single call. This endpoint uses a POST request with a JSON body specifying the advertiser ID, report type, dimensions (like campaign_id and campaign_name), metrics (like spend, impressions, clicks, cpc, ctr, conversion), and the date range in YYYYMMDD format. The response wraps data in data.list with pagination metadata. For the initial implementation, fetch up to 1000 records (the maximum page size) to avoid pagination complexity. In production, implement cursor-based pagination using the page and page_size parameters. Parse the TikTok response to extract just the fields your frontend needs, transforming the nested metrics object into a flat campaign summary object. This reduces the payload size and simplifies the frontend data handling.
1import { NextResponse } from 'next/server';23const TIKTOK_API = 'https://business-api.tiktok.com/open_api/v1.3';45export async function GET(request: Request) {6 const { searchParams } = new URL(request.url);7 const startDate = searchParams.get('startDate') ?? '20260301';8 const endDate = searchParams.get('endDate') ?? '20260331';910 try {11 const response = await fetch(`${TIKTOK_API}/report/integrated/get/`, {12 method: 'POST',13 headers: {14 'Access-Token': process.env.TIKTOK_ACCESS_TOKEN!,15 'Content-Type': 'application/json',16 },17 body: JSON.stringify({18 advertiser_id: process.env.TIKTOK_ADVERTISER_ID!,19 report_type: 'BASIC',20 data_level: 'AUCTION_CAMPAIGN',21 dimensions: ['campaign_id', 'stat_time_day'],22 metrics: [23 'campaign_name', 'spend', 'impressions', 'clicks',24 'ctr', 'cpc', 'reach', 'conversion', 'cost_per_conversion'25 ],26 start_date: startDate,27 end_date: endDate,28 page_size: 200,29 page: 1,30 }),31 });3233 const data = await response.json();3435 if (data.code !== 0) {36 return NextResponse.json(37 { error: data.message ?? 'TikTok API error' },38 { status: 400 }39 );40 }4142 const campaigns = (data.data?.list ?? []).map((item: Record<string, unknown>) => {43 const metrics = item.metrics as Record<string, unknown>;44 const dims = item.dimensions as Record<string, unknown>;45 return {46 campaignId: dims?.campaign_id,47 date: dims?.stat_time_day,48 campaignName: metrics?.campaign_name,49 spend: parseFloat((metrics?.spend as string) ?? '0'),50 impressions: parseInt((metrics?.impressions as string) ?? '0', 10),51 clicks: parseInt((metrics?.clicks as string) ?? '0', 10),52 ctr: parseFloat((metrics?.ctr as string) ?? '0'),53 cpc: parseFloat((metrics?.cpc as string) ?? '0'),54 conversions: parseInt((metrics?.conversion as string) ?? '0', 10),55 };56 });5758 return NextResponse.json({ campaigns, total: data.data?.page_info?.total_number ?? 0 });59 } catch (error) {60 console.error('TikTok Ads API error:', error);61 return NextResponse.json({ error: 'Failed to fetch campaign data' }, { status: 500 });62 }63}Pro tip: TikTok Ads API returns metrics as strings (e.g., '1234.56') even for numeric values — always use parseFloat() or parseInt() when processing metric values to avoid NaN in your calculations.
Expected result: The API route returns a JSON array of campaign performance objects when called with startDate and endDate query parameters.
Add Environment Variables in Vercel Dashboard
Add Environment Variables in Vercel Dashboard
Navigate to your Vercel project at vercel.com, select your project, and go to Settings → Environment Variables. Add the following variables for Production and Preview environments. TIKTOK_ACCESS_TOKEN is the Long-Term Access Token you generated from your TikTok Marketing API app — it is a long alphanumeric string starting with the characters your app generated. TIKTOK_ADVERTISER_ID is the numerical Advertiser ID from your TikTok Ads Manager account. Neither variable should have the NEXT_PUBLIC_ prefix since they are server-only. TIKTOK_APP_ID and TIKTOK_APP_SECRET should also be added as environment variables even if not used in the current route, as they will be needed for the OAuth refresh flow when your Access Token expires after 30 days. After adding all variables, go to the Deployments tab and click Redeploy on the latest deployment to apply the new configuration. For Preview deployments, consider using a separate TikTok Ads test account or sandbox environment if available, to avoid mixing test requests with production campaign data.
1# .env.local (local development only — set in Vercel Dashboard for deployments)2TIKTOK_ACCESS_TOKEN=your_tiktok_access_token3TIKTOK_ADVERTISER_ID=12345678901234TIKTOK_APP_ID=your_app_id5TIKTOK_APP_SECRET=your_app_secretPro tip: Set a reminder for 30 days from now to refresh your TikTok Long-Term Access Token before it expires. The TikTok Marketing API returns error code 40001 when the token has expired.
Expected result: All four TikTok environment variables are set in Vercel Dashboard. The deployment is redeployed and the API route can now authenticate with TikTok.
Connect the Dashboard to Real Data and Handle Date Filtering
Connect the Dashboard to Real Data and Handle Date Filtering
With the API route deployed and credentials configured, update your V0-generated dashboard to fetch real TikTok campaign data. The component should convert the date range picker's values to YYYYMMDD format before calling the API route, since TikTok requires this specific date format. When the date range changes, refetch the data. Add aggregation logic to calculate summary metrics from the campaigns array — sum spend, impressions, clicks, and compute overall CTR for the metric cards. For the campaigns table, group data by campaignId if you are fetching daily granularity data, summing up daily values to show campaign-level totals. Test the integration using your real TikTok Ads account data. If you see a 40100 error code, your Access Token is invalid or expired. A 40002 error means the Advertiser ID is incorrect. TikTok returns error codes as numbers in the code field of the response — check the TikTok Marketing API error code documentation for the full list. For agencies building multi-client reporting tools with complex access patterns, RapidDev can help implement the full OAuth 2.0 refresh flow and multi-advertiser account management.
Update the dashboard to convert the date range picker dates to YYYYMMDD format and append them as startDate and endDate query params when fetching /api/tiktok-ads/campaigns. Aggregate the response to show total spend, total impressions, total clicks, and overall CTR in the four metric cards. Display the campaigns in the table grouped by campaignName with summed totals.
Paste this in V0 chat
1// Date format helper for TikTok API2function toTikTokDate(date: Date): string {3 return date.toISOString().slice(0, 10).replace(/-/g, '');4}56// Example usage in fetch call:7const start = toTikTokDate(startDate); // '20260301'8const end = toTikTokDate(endDate); // '20260331'9const res = await fetch(`/api/tiktok-ads/campaigns?startDate=${start}&endDate=${end}`);Pro tip: TikTok Ads data can have a 2-3 hour delay for real-time metrics. Inform users in the dashboard UI that data reflects performance up to 3 hours ago to manage expectations.
Expected result: The dashboard displays real TikTok campaign data with spend, impressions, clicks, and CTR for the selected date range. Changing the date picker refetches and updates the table.
Common use cases
Campaign Performance Dashboard
Build a real-time dashboard showing all active TikTok ad campaigns with key metrics: spend, impressions, clicks, CTR, and conversions for a selected date range. Marketing teams can monitor campaign health without logging into TikTok Ads Manager.
Create a TikTok Ads campaign dashboard with a date range picker at the top and a table of campaigns below. Each row shows: campaign name, status badge (active/paused), budget, spend to date, impressions, clicks, CTR percentage, and conversions. Fetch from /api/tiktok-ads/campaigns. Include summary metric cards above the table showing total spend, total impressions, and average CTR.
Copy this prompt to try it in V0
Creative Performance Tracker
Display performance metrics for individual TikTok video creatives — view-through rates, engagement rates, and conversion performance — to identify which video formats and hooks are driving the best results.
Build an ad creative tracker with a grid of video thumbnail cards. Each card shows the creative name, thumbnail image, play rate, engagement rate, and conversion count. Sort by performance metric using a dropdown. Fetch creative data from /api/tiktok-ads/creatives.
Copy this prompt to try it in V0
Agency Multi-Account Report
For marketing agencies managing multiple clients' TikTok Ads accounts, build a consolidated view that shows cross-account performance and lets users switch between advertiser accounts to drill into specific campaign data.
Design an agency reporting page with an advertiser account selector dropdown at the top. Below it, show a performance summary card and a campaigns table for the selected account. The account selector should call /api/tiktok-ads/advertisers on load, and changing the selection should refetch /api/tiktok-ads/campaigns?advertiserId=XXX.
Copy this prompt to try it in V0
Troubleshooting
TikTok API returns error code 40001: 'Access token is invalid or expired'
Cause: The TIKTOK_ACCESS_TOKEN environment variable contains an expired or invalid token. Long-Term Access Tokens expire after 30 days.
Solution: Log in to your TikTok Marketing API developer portal at ads.tiktok.com, navigate to your app, and generate a new Long-Term Access Token. Update the TIKTOK_ACCESS_TOKEN environment variable in Vercel Dashboard and redeploy. For production, implement the OAuth refresh flow to automate token renewal.
API returns empty campaigns array despite having active campaigns in TikTok Ads Manager
Cause: The date range is incorrect, the data_level parameter does not match your campaign structure, or the Advertiser ID is wrong.
Solution: Verify TIKTOK_ADVERTISER_ID matches the Advertiser ID shown in TikTok Ads Manager (the numerical ID, not the account name). Check that startDate and endDate are in YYYYMMDD format and the range includes dates with active campaigns. Try changing data_level from AUCTION_CAMPAIGN to AUCTION_ADGROUP to see if ad group data returns instead.
Campaign metrics show 0 for conversions despite conversions appearing in Ads Manager
Cause: Conversion tracking requires the TikTok Pixel to be installed and conversion events to be configured. The API only returns conversion data when the pixel is properly set up and has recorded events.
Solution: Verify the TikTok Pixel is installed on your landing pages and conversion events (Purchase, Lead, Complete Registration) are firing correctly in the TikTok Events Manager. Once pixel data is collected, the conversions metric will populate in API responses.
CORS error when the frontend tries to call TikTok API directly
Cause: TikTok's Marketing API does not allow direct browser requests (CORS is blocked). The API must be called from a server-side environment.
Solution: Ensure all TikTok API calls are made inside the Next.js API route handler, never from a client component. The fetch call in your React component should target /api/tiktok-ads/campaigns (your own API route), not the TikTok API directly.
Best practices
- Store TIKTOK_ACCESS_TOKEN as a server-only Vercel environment variable (no NEXT_PUBLIC_ prefix) — exposing it in client-side code would allow anyone to read your TikTok Ads data
- Set a 30-day calendar reminder to refresh your Long-Term Access Token before it expires to prevent dashboard outages
- Cache TikTok API responses for 15-30 minutes using Vercel KV or simple in-memory caching — TikTok data is not real-time and caching reduces API rate limit pressure
- Always pass explicit date ranges to the TikTok report API — avoid open-ended queries that could return excessive data and trigger rate limits
- Handle TikTok's string-formatted numeric metrics explicitly with parseFloat/parseInt to prevent display errors in your dashboard
- Test with small date ranges (3-7 days) during development before expanding to larger historical data pulls
- Monitor TikTok API rate limits (3,000 requests/day for basic apps) and implement queuing if your dashboard is used by many users
Alternatives
Twitter Ads is better for text-based and engagement-focused campaigns targeting tech-savvy audiences, while TikTok Ads excels for visual/video content reaching younger demographics.
Pinterest Ads is better for visual product discovery and shopping campaigns, particularly in home decor, fashion, and food verticals.
Reddit Ads targets specific interest communities with text-native ads, offering deeper niche targeting than TikTok's algorithm-driven broad reach.
Google Ads reaches users with explicit purchase intent through search, while TikTok Ads reaches users in a passive discovery mode through video.
Frequently asked questions
Do I need a TikTok business account to use the Marketing API?
Yes. The TikTok Marketing API requires a TikTok For Business account and an approved developer application. Personal TikTok accounts cannot access the Marketing API. Apply at ads.tiktok.com and then go to Tools → API to create your developer app.
Can I manage (create or edit) campaigns via the TikTok Marketing API, or only read data?
The TikTok Marketing API supports both read and write operations. You can create campaigns, ad groups, and ads; update budgets and statuses; and upload creative assets. The API is full-featured for campaign management. However, write operations require stricter app approval and review by TikTok.
How long does TikTok Marketing API developer access approval take?
Initial developer access approval typically takes 1-3 business days. Apps requesting write permissions (campaign creation and management) go through a more rigorous review that can take 1-2 weeks and may require additional business documentation.
What is the rate limit for the TikTok Marketing API?
TikTok enforces rate limits per app: approximately 3,000 requests per day for basic reporting apps, with higher limits for approved partners. The report/integrated/get endpoint specifically has limits on how many report requests can be made per hour. Implement caching in your API route to stay within limits.
Can I access multiple advertiser accounts from one API app?
Yes. If your TikTok Business account manages multiple advertiser accounts (common for agencies), you can pass different advertiser_id values to the API. Use the GET /advertiser/info/ endpoint to list all advertiser accounts your Access Token has access to, then make separate report calls for each account.
Talk to an Expert
Our team has built 600+ apps. Get personalized help with your project.
Book a free consultation