@useairfoil/producer-facebook-ads 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +85 -0
- package/dist/index.d.mts +854 -0
- package/dist/index.mjs +3 -0
- package/dist/main.d.mts +1 -0
- package/dist/main.mjs +504 -0
- package/dist/main.mjs.map +1 -0
- package/dist/manifest.d.mts +41 -0
- package/dist/manifest.mjs +67 -0
- package/dist/manifest.mjs.map +1 -0
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/src-BUMrC8kD.mjs +845 -0
- package/dist/src-BUMrC8kD.mjs.map +1 -0
- package/package.json +45 -7
- package/src/client/client.ts +155 -0
- package/src/connector.ts +69 -0
- package/src/create-table.ts +5 -0
- package/src/demo/index.ts +54 -0
- package/src/demo/insights.ts +217 -0
- package/src/demo/setup.ts +115 -0
- package/src/demo/shared.ts +100 -0
- package/src/index.ts +17 -0
- package/src/main.ts +22 -0
- package/src/manifest.ts +45 -0
- package/src/resources/accounts.ts +73 -0
- package/src/resources/insights/read.ts +56 -0
- package/src/resources/insights/resource.ts +28 -0
- package/src/resources/insights/sources.ts +261 -0
- package/src/resources/insights/spec.ts +18 -0
- package/src/resources/insights/specs.ts +58 -0
- package/src/resources/objects.ts +297 -0
- package/src/sandbox.ts +37 -0
- package/src/schemas/api.ts +30 -0
- package/src/schemas/insights.ts +117 -0
- package/src/schemas/objects.ts +146 -0
- package/src/schemas/shared.ts +42 -0
- package/src/start.ts +49 -0
- package/src/tables.ts +20 -0
package/README.md
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
# Facebook Ads producer
|
|
2
|
+
|
|
3
|
+
Syncs ad accounts, campaigns, ad sets, and ads from one or more Meta ad
|
|
4
|
+
accounts, plus daily performance per ad: totals and breakdowns by age and
|
|
5
|
+
gender, country, and platform. It backfills insights day by day and reads recent
|
|
6
|
+
days again, because Meta keeps updating them.
|
|
7
|
+
|
|
8
|
+
## Config
|
|
9
|
+
|
|
10
|
+
| Variable | Required | Default |
|
|
11
|
+
| ---------------------------- | -------- | ----------- |
|
|
12
|
+
| `FACEBOOK_ADS_ACCESS_TOKEN` | yes | none |
|
|
13
|
+
| `FACEBOOK_ADS_ACCOUNT_IDS` | yes | none |
|
|
14
|
+
| `FACEBOOK_ADS_START_DATE` | no | 2 years ago |
|
|
15
|
+
| `FACEBOOK_ADS_LOOKBACK_DAYS` | no | 28 |
|
|
16
|
+
|
|
17
|
+
`FACEBOOK_ADS_ACCOUNT_IDS` is a comma-separated list, with or without `act_`.
|
|
18
|
+
|
|
19
|
+
## Setup
|
|
20
|
+
|
|
21
|
+
1. Create a Meta app of type Business and add the **Marketing API** product.
|
|
22
|
+
Connect it to the business portfolio that owns the ad accounts.
|
|
23
|
+
2. In Business Settings, go to Users > System users and add a system user.
|
|
24
|
+
3. Assign it the ad accounts with the **View performance** permission, and
|
|
25
|
+
assign it the app.
|
|
26
|
+
4. Generate a token for the app with only `ads_read`, and set expiry to
|
|
27
|
+
**Never**.
|
|
28
|
+
|
|
29
|
+
A new app has Limited access, which Meta rate-limits heavily. It can read your
|
|
30
|
+
own ad accounts. Full access needs App Review, after enough successful calls.
|
|
31
|
+
|
|
32
|
+
## Data
|
|
33
|
+
|
|
34
|
+
- `version` is the time the row was read.
|
|
35
|
+
- Budgets, bids, and account amounts are `long` in the currency's minor unit,
|
|
36
|
+
such as cents. Insights spend is a `double` in the account currency, in
|
|
37
|
+
`account_currency`.
|
|
38
|
+
- Insights have one row per ad, day, and breakdown values. The key is a JSON
|
|
39
|
+
array of the account ID, ad ID, day, and breakdown values.
|
|
40
|
+
- Days are in each ad account's time zone. Today is read too, and grows on each
|
|
41
|
+
run.
|
|
42
|
+
- `actions`, `action_values`, and the other action fields are maps from action
|
|
43
|
+
type to value, such as `actions['purchase']`. The values use the account's
|
|
44
|
+
attribution setting, the same as Ads Manager.
|
|
45
|
+
- `reach` counts people, so it doesn't add up across rows or days. With a
|
|
46
|
+
breakdown, Meta leaves `reach` out for days more than 13 months back.
|
|
47
|
+
- Meta keeps 37 months of insights. An older start date moves up to that.
|
|
48
|
+
- Deleted and archived campaigns, ad sets, and ads stay, with their status.
|
|
49
|
+
Their insights stay too.
|
|
50
|
+
- A change to the account's attribution setting changes past numbers. Backfill
|
|
51
|
+
again to pick it up.
|
|
52
|
+
|
|
53
|
+
## Demo data
|
|
54
|
+
|
|
55
|
+
`pnpm demo --size 128MiB` writes made-up Facebook Ads data without Meta
|
|
56
|
+
credentials. See the Connector Kit README for the flags and the variables it
|
|
57
|
+
needs.
|
|
58
|
+
|
|
59
|
+
Two ad accounts with their campaigns, ad sets, and ads are written once. Each
|
|
60
|
+
group is one day of insights, counting back from today. It stops at Meta's 37
|
|
61
|
+
months, about 225 MiB. Ads only have insights while their campaign runs, and the
|
|
62
|
+
breakdowns add up to the ad's day.
|
|
63
|
+
|
|
64
|
+
## Limits
|
|
65
|
+
|
|
66
|
+
- Meta limits calls per ad account per hour, based on the access tier and the
|
|
67
|
+
number of active ads. A limit error waits and tries again.
|
|
68
|
+
- Insights read the last `FACEBOOK_ADS_LOOKBACK_DAYS` again every 6 hours. Meta
|
|
69
|
+
says insights don't change after 28 days.
|
|
70
|
+
- Campaigns are read in full every 6 hours. Ad sets and ads read only the ones
|
|
71
|
+
updated since the last run.
|
|
72
|
+
|
|
73
|
+
## Local development
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
cd connectors/producer-facebook-ads
|
|
77
|
+
pnpm sandbox
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
`pnpm start` runs the hosted connector. It needs the Wings and PostgreSQL
|
|
81
|
+
variables from the [Connector Kit README](../../packages/connector-kit/README.md).
|
|
82
|
+
|
|
83
|
+
To record the VCR cassette, put a sandbox ad account's ID and token in `.env`,
|
|
84
|
+
delete `test/__cassettes__/api.vcr.test.cassette`, and run `pnpm test:ci`. A
|
|
85
|
+
sandbox never delivers ads, so insights stay empty.
|