npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@rawdash/connector-meta-ads

v0.29.2

Published

Rawdash connector for Meta (Facebook + Instagram) Ads — campaigns and daily campaign/adset/ad insights

Readme

@rawdash/connector-meta-ads

npm version license

Sync Meta (Facebook + Instagram) ad campaigns plus daily campaign, adset, and ad-level insights - spend, impressions, clicks, reach, conversions, and conversion value.

Install

npm install @rawdash/connector-meta-ads

Authentication

A long-lived System User access token from Meta Business Manager, scoped with ads_read (and read_insights on newer accounts) for the target ad account.

  1. In Meta Business Manager → Business Settings → Users → System Users, create a System User (or reuse an existing one) and assign it to the ad account with at least the Advertiser role.
  2. Generate a System User access token for the System User; pick ads_read and (where available) read_insights as the scopes. Choose the longest available expiry - System User tokens can be made effectively non-expiring.
  3. Find the ad account ID in Ads Manager → Settings → Account info; it always starts with act_.
  4. Store the token as a secret and reference it from the connector config as accessToken: secret("META_ACCESS_TOKEN") alongside adAccountId: "act_<id>".

Configuration

| Field | Type | Required | Description | | -------------- | ------ | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | adAccountId | string | Yes | Meta Marketing API ad account ID. Find it in Ads Manager → Settings → Account info; it always starts with act_. | | accessToken | secret | Yes | Long-lived System User access token from Meta Business Manager with ads_read (and, for newer accounts, read_insights) scopes on the chosen ad account. | | apiVersion | string | No | Pin a specific Meta Graph API version (e.g. v25.0). Defaults to v25.0. Meta deprecates Marketing API versions on a rolling schedule, so older pins eventually stop working. | | lookbackDays | number | No | How many calendar days of insights to fetch on a full sync. Defaults to 90. | | resources | array | No | Which Meta resources to sync. Omit to sync all. Ad-level insights are the most expensive - leave them out if you only need campaign or adset rollups. |

Resources

  • meta_campaign (entity) - Meta ad campaigns with name, objective, status, and budget. Upserted by id; one row per campaign in the ad account.
    • Endpoint: GET /{ad_account_id}/campaigns
  • meta_campaign_insights (metric) - Daily campaign-level Meta Ads insights - spend (primary value), impressions, clicks, reach, conversions, and conversion value bucketed by campaign.
    • Endpoint: GET /{ad_account_id}/insights?level=campaign&time_increment=1
    • Unit: USD
    • Granularity: day
    • Dimensions: date, campaignId, campaignName
    • Measures: impressions, clicks, reach, conversions, conversion_value
    • Primary value is spend. conversions is the sum of the upstream conversions field (conversion events only, default attribution window); conversion_value is the sum of the upstream conversion_values field.
  • meta_adset_insights (metric) - Daily adset-level Meta Ads insights - same fields as the campaign roll-up, bucketed by adset.
    • Endpoint: GET /{ad_account_id}/insights?level=adset&time_increment=1
    • Unit: USD
    • Granularity: day
    • Dimensions: date, campaignId, campaignName, adsetId, adsetName
    • Measures: impressions, clicks, reach, conversions, conversion_value
    • Primary value is spend. Includes campaign_id/campaign_name so adset rows are easy to roll up to their parent campaign.
  • meta_ad_insights (metric) - Daily ad-level Meta Ads insights - same fields as the adset roll-up, bucketed by ad.
    • Endpoint: GET /{ad_account_id}/insights?level=ad&time_increment=1
    • Unit: USD
    • Granularity: day
    • Dimensions: date, campaignId, campaignName, adsetId, adsetName, adId, adName
    • Measures: impressions, clicks, reach, conversions, conversion_value
    • Primary value is spend. Cardinality is the highest of the three insights resources - opt in via resources: [..., "ad_insights"] only when you need per-ad breakdowns.

Example

import {
  defineConfig,
  defineDashboard,
  defineMetric,
  secret,
} from '@rawdash/core';

const metaAds = {
  name: 'metaAds',
  connectorId: 'meta-ads',
  config: {
    adAccountId: 'act_1234567890',
    accessToken: secret('META_ACCESS_TOKEN'),
    lookbackDays: 90,
  },
};

export default defineConfig({
  connectors: [metaAds],
  dashboards: {
    marketing: defineDashboard({
      widgets: {
        spend_30d: {
          kind: 'stat',
          title: 'Meta Ads spend (30d)',
          window: '30d',
          metric: defineMetric({
            connector: metaAds,
            shape: 'metric',
            name: 'meta_campaign_insights',
            field: 'value',
            fn: 'sum',
          }),
        },
        daily_spend: {
          kind: 'timeseries',
          title: 'Daily Meta Ads spend',
          window: '30d',
          metric: defineMetric({
            connector: metaAds,
            shape: 'metric',
            name: 'meta_campaign_insights',
            field: 'value',
            fn: 'sum',
          }),
        },
      },
    }),
  },
});

Rate limits

Meta enforces per-app and per-ad-account budgets surfaced through the X-Business-Use-Case-Usage header. Sync at most every few hours per ad account; very large accounts may need a daily cadence.

Limitations

  • Insights are always fetched at daily granularity. Sub-daily breakdowns are not supported.
  • Insights for the most recent 30 days are re-fetched on every incremental sync because Meta keeps attributing conversions after the event date.
  • Creative-level breakdowns (publisher_platform, placement, demographics) are intentionally out of scope to keep the metric cardinality bounded.

Links

License

Apache-2.0