ads-as-code

Configuration

ads.config.ts setup, credentials resolution, and all configuration options.

ads.config.ts

Every project needs an ads.config.ts at the root. Use defineConfig() for type safety:

ads.config.ts
import { defineConfig } from '@upspawn/ads'

export default defineConfig({
  google: {
    customerId: '1112223333',
    managerId: '4445556666',
  },
  meta: {
    accountId: '1234567890',
    pageId: '9876543210',
  },
})

Run ads init to scaffold this file automatically.


Google config

FieldTypeRequiredDescription
customerIdstringYesGoogle Ads customer ID (no dashes)
managerIdstringNoManager (MCC) account ID
developerTokenstringNoOverride developer token (usually from credentials file)

Meta config

FieldTypeRequiredDescription
accountIdstringYesMeta ad account ID
pageIdstringYesFacebook Page ID for creatives

AI config

export default defineConfig({
  google: { customerId: '...' },
  ai: {
    provider: 'openai',     // 'openai' | 'anthropic'
    model: 'gpt-4o',
  },
})
FieldTypeDescription
provider'openai' | 'anthropic'LLM provider for AI generation
modelstringModel ID to use

Credentials

Resolution order

Credentials are resolved in this order (first match wins):

  1. Explicit values in ads.config.ts
  2. ~/.ads/credentials.json
  3. Environment variables

~/.ads/credentials.json

~/.ads/credentials.json
{
  "google_client_id": "123-abc.apps.googleusercontent.com",
  "google_client_secret": "GOCSPX-your-secret",
  "google_refresh_token": "1//your-refresh-token",
  "google_developer_token": "your-developer-token",
  "google_customer_id": "1112223333",
  "google_manager_id": "4445556666"
}

This file lives in your home directory and is shared across all ads-as-code projects on your machine.

Environment variables

Alternative to the credentials file. Useful in CI/CD environments.

Google Ads:

VariableDescription
GOOGLE_ADS_CLIENT_IDOAuth client ID
GOOGLE_ADS_CLIENT_SECRETOAuth client secret
GOOGLE_ADS_REFRESH_TOKENOAuth refresh token
GOOGLE_ADS_DEVELOPER_TOKENGoogle Ads developer token
GOOGLE_ADS_CUSTOMER_IDCustomer account ID
GOOGLE_ADS_MANAGER_IDManager (MCC) account ID

Meta Ads:

VariableDescription
FB_ADS_ACCESS_TOKENLong-lived system user access token

CI/CD setup

In CI, set environment variables as secrets. Example GitHub Actions setup:

.github/workflows/deploy-ads.yml
- name: Apply ad changes
  env:
    GOOGLE_ADS_CLIENT_ID: ${{ secrets.GOOGLE_ADS_CLIENT_ID }}
    GOOGLE_ADS_CLIENT_SECRET: ${{ secrets.GOOGLE_ADS_CLIENT_SECRET }}
    GOOGLE_ADS_REFRESH_TOKEN: ${{ secrets.GOOGLE_ADS_REFRESH_TOKEN }}
    GOOGLE_ADS_DEVELOPER_TOKEN: ${{ secrets.GOOGLE_ADS_DEVELOPER_TOKEN }}
    GOOGLE_ADS_CUSTOMER_ID: ${{ secrets.GOOGLE_ADS_CUSTOMER_ID }}
  run: ads apply

Campaign discovery

The CLI scans campaigns/**/*.ts relative to the config file. All TypeScript files in that directory (recursively) are imported, and any export with provider and kind fields is treated as a campaign.

You can't change the scan directory in config — it's always campaigns/. Use subdirectories to organize.

On this page