@useairfoil/producer-facebook-ads

中文文档
0.0.3发布于 2026/11/03TypeScriptES Module构建来源已验证

Syncs ad accounts, campaigns, ad sets, and ads from one or more Meta ad accounts, plus daily performance per ad: totals and breakdowns by age and gender, country, and platform. It backfills insights day by day and reads recent days again, because Meta kee

原始使用文档
文档目录6 节
  1. Config
  2. Setup
  3. Data
  4. Demo data
  5. Limits
  6. Local development

Facebook Ads producer

Syncs ad accounts, campaigns, ad sets, and ads from one or more Meta ad accounts, plus daily performance per ad: totals and breakdowns by age and gender, country, and platform. It backfills insights day by day and reads recent days again, because Meta keeps updating them.

Config

VariableRequiredDefault
FACEBOOK_ADS_ACCESS_TOKENyesnone
FACEBOOK_ADS_ACCOUNT_IDSyesnone
FACEBOOK_ADS_START_DATEno2 years ago
FACEBOOK_ADS_LOOKBACK_DAYSno28

FACEBOOK_ADS_ACCOUNT_IDS is a comma-separated list, with or without act_.

Setup

  1. Create a Meta app of type Business and add the Marketing API product. Connect it to the business portfolio that owns the ad accounts.
  2. In Business Settings, go to Users > System users and add a system user.
  3. Assign it the ad accounts with the View performance permission, and assign it the app.
  4. Generate a token for the app with only ads_read, and set expiry to Never.

A new app has Limited access, which Meta rate-limits heavily. It can read your own ad accounts. Full access needs App Review, after enough successful calls.

Data

  • version is the time the row was read.
  • Budgets, bids, and account amounts are long in the currency's minor unit, such as cents. Insights spend is a double in the account currency, in account_currency.
  • Insights have one row per ad, day, and breakdown values. The key is a JSON array of the account ID, ad ID, day, and breakdown values.
  • Days are in each ad account's time zone. Today is read too, and grows on each run.
  • actions, action_values, and the other action fields are maps from action type to value, such as actions['purchase']. The values use the account's attribution setting, the same as Ads Manager.
  • reach counts people, so it doesn't add up across rows or days. With a breakdown, Meta leaves reach out for days more than 13 months back.
  • Meta keeps 37 months of insights. An older start date moves up to that.
  • Deleted and archived campaigns, ad sets, and ads stay, with their status. Their insights stay too.
  • A change to the account's attribution setting changes past numbers. Backfill again to pick it up.

Demo data

pnpm demo --size 128MiB writes made-up Facebook Ads data without Meta credentials. See the Connector Kit README for the flags and the variables it needs.

Two ad accounts with their campaigns, ad sets, and ads are written once. Each group is one day of insights, counting back from today. It stops at Meta's 37 months, about 225 MiB. Ads only have insights while their campaign runs, and the breakdowns add up to the ad's day.

Limits

  • Meta limits calls per ad account per hour, based on the access tier and the number of active ads. A limit error waits and tries again.
  • Insights read the last FACEBOOK_ADS_LOOKBACK_DAYS again every 6 hours. Meta says insights don't change after 28 days.
  • Campaigns are read in full every 6 hours. Ad sets and ads read only the ones updated since the last run.

Local development

cd connectors/producer-facebook-ads
pnpm sandbox

pnpm start runs the hosted connector. It needs the Wings and PostgreSQL variables from the Connector Kit README.

To record the VCR cassette, put a sandbox ad account's ID and token in .env, delete test/__cassettes__/api.vcr.test.cassette, and run pnpm test:ci. A sandbox never delivers ads, so insights stay empty.

版本与发布记录

@useairfoil/producer-facebook-ads 共发布 4 个版本,首次发布于 2026/10/29;过去 12 个月发布了 4 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.0.3latest2026/11/03今天
0.0.22026/10/295 天前
0.0.12026/10/295 天前
0.0.0-stage2026/10/295 天前

关于 @useairfoil/producer-facebook-ads 的常见问题

@useairfoil/producer-facebook-ads 是什么?

同步来自一个或多个元广告帐户的广告、活动、广告集和广告,以及每个广告的每日表现:按年龄和性别、国家和平台划分的总数和细分。它会逐日回填见解,并再次读取最近几天的内容,因为Meta会保持

如何安装 @useairfoil/producer-facebook-ads?

在项目目录运行 npm install @useairfoil/producer-facebook-ads,或使用 pnpm add / yarn add / bun add。

@useairfoil/producer-facebook-ads 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@useairfoil/producer-facebook-ads 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@useairfoil/producer-facebook-ads 可以商用吗?

@useairfoil/producer-facebook-ads 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@useairfoil/producer-facebook-ads 还在维护吗?

最新版本 0.0.3 发布于 2026/11/03(今天);至今共发布 4 个版本,其中过去 12 个月发布了 4 个;首次发布于 2026/10/29。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。