0

Installation

Install dependencies & start the server

cd ad-tracker-web
npm install
node server.js

Then open http://localhost:3000 and click Settings to enter your credentials.

1

Meta (Facebook) Ads API

App ID App Secret Long-lived Access Token Ad Account ID

Step 1 — Create a Meta App

  1. Go to developers.facebook.com/apps
  2. Click Create App → choose OtherBusiness
  3. Give it any name (e.g. "Ad Tracker")
  4. From the app dashboard, click Add Product → add Marketing API
  5. Your App ID and App Secret are in Settings → Basic

Step 2 — Generate a Long-lived Access Token

  1. Go to Graph API Explorer
  2. Select your app from the dropdown
  3. Click Generate Access Token — grant ads_read and read_insights
  4. Exchange the short-lived token for a long-lived one (valid ~60 days):
curl "https://graph.facebook.com/oauth/access_token\
?grant_type=fb_exchange_token\
&client_id=YOUR_APP_ID\
&client_secret=YOUR_APP_SECRET\
&fb_exchange_token=SHORT_LIVED_TOKEN"

The access_token in the response is your long-lived token. Paste it into Settings.

Token expiry: Long-lived tokens last ~60 days. You'll need to regenerate one when it expires. You can automate this with a system user token — see Meta docs for details.

Step 3 — Find your Ad Account ID

  1. Go to business.facebook.com
  2. Navigate to Business Settings → Accounts → Ad Accounts
  3. Your Ad Account ID looks like act_1234567890 — enter only the numbers (no act_)

Settings fieldWhere to find it
App IDApp dashboard → Settings → Basic
App SecretApp dashboard → Settings → Basic (click Show)
Access TokenGenerated in Step 2 above
Ad Account IDBusiness Manager → numbers only, no "act_"
2

Google Ads API

Developer Token Client ID Client Secret Refresh Token Customer ID

Step 1 — Apply for a Developer Token

  1. Sign in at ads.google.com
  2. Go to Tools & Settings → API Center
  3. Fill out the form and submit — a Basic Access (test) token is sufficient to get started
  4. The token appears in the API Center once approved
Test vs Standard access: Basic Access works fine for reading your own account data. Standard Access is only needed if you're building a product for other advertisers.

Step 2 — Create OAuth 2.0 Credentials

  1. Go to console.cloud.google.com
  2. Create a new project (or select an existing one)
  3. Navigate to APIs & Services → Library → enable Google Ads API
  4. Go to APIs & Services → Credentials → Create Credentials → OAuth Client ID
  5. Choose Desktop App and give it a name
  6. Download the JSON file — it contains your Client ID and Client Secret

Step 3 — Generate a Refresh Token

Run this one-time script to get a refresh token via the OAuth flow:

npm install -g google-auth-library
node -e "
const { OAuth2Client } = require('google-auth-library');
const http = require('http');
const url = require('url');
const open = require('open');

const CLIENT_ID = 'YOUR_CLIENT_ID';
const CLIENT_SECRET = 'YOUR_CLIENT_SECRET';

const client = new OAuth2Client(CLIENT_ID, CLIENT_SECRET, 'http://localhost:4000');
const authUrl = client.generateAuthUrl({
  access_type: 'offline',
  scope: ['https://www.googleapis.com/auth/adwords'],
});

console.log('Opening browser...');
const server = http.createServer(async (req, res) => {
  const code = new url.URL(req.url, 'http://localhost:4000').searchParams.get('code');
  if (code) {
    const { tokens } = await client.getToken(code);
    console.log('\\nRefresh token:', tokens.refresh_token);
    res.end('Done! Check your terminal.');
    server.close();
  }
});
server.listen(4000, () => require('child_process').exec('open \"' + authUrl + '\"'));
"

Or use the simpler Python approach if you have Python available:

pip3 install google-auth-oauthlib
python3 -c "
from google_auth_oauthlib.flow import InstalledAppFlow
flow = InstalledAppFlow.from_client_secrets_file(
    'client_secrets.json',
    scopes=['https://www.googleapis.com/auth/adwords']
)
creds = flow.run_local_server()
print('Refresh token:', creds.refresh_token)
"

Step 4 — Find your Customer ID

  1. Sign in at ads.google.com
  2. Your Customer ID is the 10-digit number in the top right — e.g. 123-456-7890
  3. Enter it with or without dashes — both work

Settings fieldWhere to find it
Developer TokenGoogle Ads → Tools → API Center
Client IDGoogle Cloud Console → Credentials
Client SecretGoogle Cloud Console → Credentials
Refresh TokenGenerated via OAuth flow in Step 3
Customer IDTop-right of Google Ads UI
3

Troubleshooting

ErrorFix
Invalid OAuth access token (Meta)Your token expired (60-day limit). Regenerate via Graph API Explorer.
Request had invalid authentication credentials (Google)Refresh token was revoked. Re-run the OAuth flow in Step 3.
No data showingYour account may have no activity in the selected date range. Try "Last 30d".
Developer token not approvedBasic Access is enough for your own account. Check Google Ads API Center status.
ROAS shows N/AConversion value tracking needs to be set up in your ad account (e.g. purchase value pixel events).