# Analytics & insights

Read spend, views and CTR for a TikTok ad with breakdowns, and run live TikTok reports for de-duplicated reach.

import { Tab, Tabs } from 'fumadocs-ui/components/tabs';

Read a TikTok ad's synced metrics with `GET /v1/ads/{adId}/analytics`, or run a live TikTok report with `GET /v1/ads/insights` for what the synced metrics cannot answer.

## Read ad analytics

Call `GET /v1/ads/{adId}/analytics` with the ad's `_id` for spend, impressions, clicks, CTR, CPM and video metrics.

Add `breakdowns` for a split by `gender`, `age`, `country_code`, `platform`, `ac` or `language`.

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: insights } = await zernio.adinsights.getAdAnalytics({
  path: { adId: '66f0a1b2c3d4e5f6a7b8c9d0' },
  query: { fromDate: '2027-01-04', toDate: '2027-01-11', breakdowns: 'age' }
});

console.log(insights.analytics.breakdowns.age);
```
</Tab>
<Tab value="Python">
```python
insights = client.ad_insights.get_ad_analytics(
    ad_id="66f0a1b2c3d4e5f6a7b8c9d0",
    from_date="2027-01-04",
    to_date="2027-01-11",
    breakdowns="age",
)

print(insights["analytics"]["breakdowns"]["age"])
```
</Tab>
<Tab value="curl">
```bash
curl "https://zernio.com/api/v1/ads/66f0a1b2c3d4e5f6a7b8c9d0/analytics?fromDate=2027-01-04&toDate=2027-01-11&breakdowns=age" \
  -H "Authorization: Bearer $ZERNIO_API_KEY"
```
</Tab>
</Tabs>

Response (`200`), trimmed:

```json
{
  "ad": { "id": "66f0a1b2c3d4e5f6a7b8c9d0", "name": "Boost viral video", "platform": "tiktok", "status": "active", "currency": "USD" },
  "analytics": {
    "summary": { "spend": 312.4, "impressions": 128400, "clicks": 2110, "ctr": 1.64, "cpc": 0.15, "cpm": 2.43, "videoPlayActions": 96200, "videoP100WatchedActions": 18400 },
    "daily": [ { "date": "2027-01-04", "spend": 44.1, "impressions": 18200, "clicks": 301 } ],
    "breakdowns": { "age": [ { "value": "AGE_18_24", "spend": 140.2, "impressions": 61000, "clicks": 1080 } ] }
  }
}
```

`GET /v1/ads/tree` rolls the same metrics up per campaign and ad group ([Get campaign tree](/ad-campaigns/get-ad-tree)).

Offline conversions (in-store, CRM, call-center) go to TikTok through `POST /v1/events` ([Send a conversion event](/platforms/tiktok-ads/conversions)).

## Live reports and de-duplicated reach

[`GET /v1/ads/insights`](/ad-insights/query-ad-insights) runs TikTok's synchronous report live, for questions the synced metrics cannot answer.

The most common one is reach across a set. Adding the `reach` of two campaigns counts a person who saw both twice, and the synced numbers only hold per-entity reach.

Send these params:

| Param | Value |
|-------|-------|
| `accountId` | A `tiktok` or `tiktokads` connection |
| `adAccountId` | The advertiser id |
| `dataLevel` | `AUCTION_ADVERTISER`, `AUCTION_CAMPAIGN`, `AUCTION_ADGROUP` or `AUCTION_AD` |
| `dimensions` | 1 to 4 TikTok dimensions, comma-separated |
| `metrics` | TikTok metric names, comma-separated |
| `fromDate`/`toDate` | TikTok caps the span at 365 days |

`reportType` is `BASIC` (the default) or `AUDIENCE`.

`filtering` takes the same JSON array as Meta, `[{"field", "operator", "value"}]`. Use TikTok's field names (`campaign_ids`, `adgroup_ids`, `ad_ids`) and TikTok's filter type as `operator`, for example `IN`.

For de-duplicated reach, filter the set and group by `country_code` instead of the entity id. TikTok then counts each person once across the whole set and date range.

Two campaigns over a month:

<Tabs items={['Node.js', 'Python', 'curl']}>
<Tab value="Node.js">
```typescript
const { data: report } = await zernio.adinsights.queryAdInsights({
  query: {
    accountId: '66b2e19d8c3f5a7e9d0b1c2d',
    adAccountId: '7123456789012345678',
    dataLevel: 'AUCTION_CAMPAIGN',
    dimensions: 'country_code',
    metrics: 'reach,impressions,frequency',
    fromDate: '2027-01-01',
    toDate: '2027-01-31',
    filtering: JSON.stringify([{ field: 'campaign_ids', operator: 'IN', value: ['1876574798182050', '1876575504573650'] }])
  }
});
```
</Tab>
<Tab value="Python">
```python
import json

report = client.ad_insights.query_ad_insights(
    account_id="66b2e19d8c3f5a7e9d0b1c2d",
    ad_account_id="7123456789012345678",
    data_level="AUCTION_CAMPAIGN",
    dimensions="country_code",
    metrics="reach,impressions,frequency",
    from_date="2027-01-01",
    to_date="2027-01-31",
    filtering=json.dumps([{"field": "campaign_ids", "operator": "IN", "value": ["1876574798182050", "1876575504573650"]}]),
)
```
</Tab>
<Tab value="curl">
```bash
curl -G "https://zernio.com/api/v1/ads/insights" \
  -H "Authorization: Bearer $ZERNIO_API_KEY" \
  --data-urlencode "accountId=66b2e19d8c3f5a7e9d0b1c2d" \
  --data-urlencode "adAccountId=7123456789012345678" \
  --data-urlencode "dataLevel=AUCTION_CAMPAIGN" \
  --data-urlencode "dimensions=country_code" \
  --data-urlencode "metrics=reach,impressions,frequency" \
  --data-urlencode "fromDate=2027-01-01" \
  --data-urlencode "toDate=2027-01-31" \
  --data-urlencode 'filtering=[{"field":"campaign_ids","operator":"IN","value":["1876574798182050","1876575504573650"]}]'
```
</Tab>
</Tabs>

Response (`200`), trimmed:

```json
{
  "adAccountId": "7123456789012345678",
  "data": [
    { "dimensions": { "country_code": "US" }, "metrics": { "reach": "17770000", "impressions": "41210000", "frequency": "2.32" } }
  ],
  "paging": { "page": 1, "pageSize": 100, "totalRows": 1, "totalPages": 1 }
}
```

Rows come back verbatim from TikTok, with metric values as strings. Page with `page` and `pageSize` (up to 1,000).

For a set of ads, use `dataLevel=AUCTION_AD` with `ad_ids`. For ad groups, use `AUCTION_ADGROUP` with `adgroup_ids`.

## How it behaves

- When the account connects, Zernio imports its last 90 days of metrics. The `summary` and `daily` of `GET /v1/ads/{adId}/analytics` hold no data for days before that, because only Meta backfills an older range on request. Breakdowns and live reports read TikTok directly over the requested range, so they cover those days.
- Reach is per country. When the set delivers in several countries, summing the rows counts a person reached in two countries twice.
- The filter must match the data level or a coarser one. A finer filter, such as `ad_ids` at `AUCTION_CAMPAIGN`, answers `400`: TikTok would silently widen it to every campaign containing those ads.
- `AUCTION_ADVERTISER` takes no entity filter.
- Asynchronous report runs (`POST /v1/ads/insights/reports`) stay Meta only.

## If it fails

| Error | Cause | Fix |
|---|---|---|
| `400` with TikTok's message | TikTok rejected the report query, such as an unknown metric or a bad dimension combination | Fix the field TikTok's message names. |
| `400` on a filter | The filter is finer than `dataLevel`, such as `ad_ids` at `AUCTION_CAMPAIGN` | Use a matching or coarser `dataLevel`. |
| `403` | The connection cannot read that advertiser | Check `adAccountId`, or reconnect TikTok Ads. |
| `429` | TikTok's rate limit | Back off and retry. |

## Related

- [Get ad analytics](/ad-insights/get-ad-analytics): every query parameter and metric.
- [Query ad insights](/ad-insights/query-ad-insights): the live report endpoint.
- [Get campaign tree](/ad-campaigns/get-ad-tree): metrics rolled up per campaign and ad group.
- [Send a conversion event](/platforms/tiktok-ads/conversions): offline conversions to TikTok.