mm.blog

Guide · AI + paid media

How to connect Meta Ads, Google Ads, GA4 and TikTok Ads to Claude Code or Codex

This is the same setup I run for my clients: your AI agent reads campaigns, spend and conversions straight from the APIs, with no spreadsheet exports and no screenshots. You install Orca, pick an agent (Claude Code or Codex), download my skill, and it walks you through the rest.

connect-ads skillFor Claude Code and Codex. Free, open source, runs on your machine. Leave your email and the download starts right away.

By downloading, you agree to get my emails about AI and paid media. Unsubscribe anytime.

01What you need

  • A computer running macOS, Windows or Linux.
  • An agent subscription: Claude Pro or Max (for Claude Code) or ChatGPT Plus or Pro (for Codex). The free Claude plan doesn't include Claude Code.
  • Admin access to the accounts you'll connect: the Meta business portfolio (Business Manager), the Google Ads account, the GA4 property and the TikTok Ads account.
  • Python 3 and Git. On a Mac, run python3 --version in Terminal: if it offers to install the "command line developer tools", accept, which installs both. On Windows, install Python (tick "Add python.exe to PATH") and Git, and use py wherever this guide says python3.
How long it takesMeta, Google Ads and GA4 take about an hour. TikTok requires a developer app approval that can take a few days, so start it first and connect the others while you wait.

02Install Claude Code or Codex

Pick one (or both: the skill works the same). Open Terminal (PowerShell on Windows) and run:

Claude Code

curl -fsSL https://claude.ai/install.sh | bash
irm https://claude.ai/install.ps1 | iex

Close and reopen the terminal, run claude and sign in with your Claude account when the browser opens. To check the install: claude --version.

Codex

curl -fsSL https://chatgpt.com/codex/install.sh | sh
npm install -g @openai/codex

Run codex and choose Sign in with ChatGPT.

03Install Orca

Orca is a free, open-source app for running AI agents side by side. Each task gets its own isolated copy of the project (a Git worktree) with its own terminal and browser. It uses the subscription you already have, with no extra login, and it's where I keep one agent per client running at the same time.

brew install --cask stablyai/orca/orca

Without Homebrew, or on Windows and Linux, download the installer from onorca.dev/download.

Create the project folder

Orca works with Git repositories. Create a folder for the client (or for yourself) and turn it into a repository with an empty first commit:

mkdir -p ~/clients/my-brand && cd ~/clients/my-brand
git init
git commit --allow-empty -m "start"

Open it in Orca

  1. Click Add Repo in the sidebar and pick the folder you created.
  2. Click the + next to the repository name, name the task (for example connect-ads) and keep the suggested base.
  3. In the terminal that opens, pick the agent in the selector: Claude Code or Codex. It starts inside the task's folder.

04Install the skill

A skill is a bundle of instructions and scripts the agent loads when it needs them. connect-ads is the open version of the process I use: it checks what already exists, guides you through only what's missing, stores the keys in .env and tests every connection.

Download the .zip (just leave your email in the box at the top) and, in the folder where it was saved (usually Downloads), run:

cd ~/Downloads
mkdir -p ~/.claude/skills ~/.agents/skills
unzip -o connect-ads.zip -d ~/.claude/skills
unzip -o connect-ads.zip -d ~/.agents/skills
cd $HOME\Downloads
Expand-Archive connect-ads.zip "$HOME\.claude\skills" -Force
Expand-Archive connect-ads.zip "$HOME\.agents\skills" -Force

The first folder is where Claude Code looks for skills, the second is Codex's. If you only use one, run just its line. If the agent was already open, restart it so it picks up the skill.

05Ask the agent to connect

In Orca's terminal, with the agent open, type:

Use the connect-ads skill to connect my ad accounts.

The agent creates .env, .gitignore and a scripts/ folder, asks which platforms you use and what already exists on each, and takes you one step at a time. You do the clicks in each platform's dashboard and paste back what it asks for.

The sections below follow the same script, so you know ahead of time what you'll do (or can do it on your own).

06Meta Ads

The most stable path is a system user: a "robot" inside your business portfolio, with a token that doesn't expire and access only to what you assign.

  1. Business portfolio: open business.facebook.com/settings. The ID is in the URL, after business_id=.
  2. App: at developers.facebook.com/apps, click Create app, choose the Other use case and the Business type, name it after the project and connect it to your portfolio. In the app dashboard, add the Marketing API product. App ID and secret are under App settings > Basic. Development mode is fine for accounts your own portfolio owns.
  3. System user: in Business settings > Users > System users, click Add, name it and choose the Admin role.
  4. Assign assets: on that user, use Assign assets and give full control of the ad account, the Page, the Pixel (dataset) and the app.
  5. Generate the token: click Generate new token, pick the app, expiration Never and the permissions ads_read, ads_management, business_management, pages_read_engagement and read_insights. The token is shown once: paste it into .env as META_ACCESS_TOKEN.
  6. IDs: the ad account ID goes as act_ + numbers. Page and Pixel IDs are optional.

Test it:

python3 scripts/meta_test.py

If you see the system user's name, the ad account and the last 7 days of spend, you're connected. Error 190 means an invalid token. Error 100 or 200 on an asset almost always means it wasn't assigned to the system user.

07Google Cloud (shared by Google Ads and GA4)

Google Ads and GA4 share one project and one sign-in. You do this once and reuse it for every client.

  1. At console.cloud.google.com, create a project (for example "Ads Operator").
  2. Under APIs & Services > Library, enable the Google Ads API, the Google Analytics Admin API and the Google Analytics Data API.
  3. In Google Auth Platform, set up the consent screen: a neutral name, your email, audience External. Then, under Audience, click Publish app so the status reads In production.
  4. Under Clients, create an OAuth client of type Desktop app. Copy its ID and secret into GOOGLE_CLIENT_ID and GOOGLE_CLIENT_SECRET.
Don't skip publishingWhile the app is in "Testing", Google sign-ins expire after 7 days and integrations stop without warning. When you sign in, Google will show "Google hasn't verified this app": that's expected for a personal app. Click Advanced, then Go to your app.
Changed in September 2026There's no API Center "developer token" anymore. Since Sep 9, 2026, API access comes from the Google Cloud project, in levels (Test, Explorer, Basic, Standard), and you no longer need a manager account (MCC) to apply. Many tutorials still teach the old way.
  1. Open console.cloud.google.com/google/ads-apis/overview in the same project. Enabling the API gives you Test access, which only reaches test accounts. Expand Upgrade access level and click Apply for access to request Explorer. Approval is usually automatic. Explorer allows 2,880 operations a day on real accounts, far more than reporting uses.
  2. Copy the 10-digit ID shown at the top of Google Ads into GOOGLE_ADS_CUSTOMER_ID.
  3. If you reach the account through an MCC (manager account), put the MCC ID in GOOGLE_ADS_LOGIN_CUSTOMER_ID and check on the client account that the link was accepted. If you don't use an MCC, leave it empty.
  4. Sign in to Google for Ads. The browser opens: use the Google user that can access the account (or the MCC).
python3 scripts/google_oauth.py --for ads
python3 scripts/google_ads_test.py

The test lists the last 7 days of campaigns. USER_PERMISSION_DENIED means the Google user can't reach the account, or the MCC link wasn't accepted. CLOUD_PROJECT_NOT_APPROVED_FOR_PRODUCTION means the project is still on Test access (step 1).

09GA4

  1. Make sure your Google user has at least Viewer access to the property (GA4 > Admin > Property access management).
  2. Copy the G-... measurement ID (Admin > Data streams) into GA4_MEASUREMENT_ID.
  3. Run the sign-in, the property lookup and the test:
python3 scripts/google_oauth.py --for ga4
python3 scripts/ga4_find_property.py
python3 scripts/ga4_test.py

The test shows users, sessions and last week's ecommerce events. If purchases exceed checkouts started, checkout tracking is probably broken. That's not a connection error: it's the first thing worth fixing.

10TikTok Ads

TikTok's API requires an approved developer app. Apply early, since review can take a few days.

  1. In TikTok Ads Manager, copy the ad account ID (numbers only) into TIKTOK_ADVERTISER_ID.
  2. At business-api.tiktok.com/portal, register as a developer and create an app under My Apps. Fill in name and description and use your website as the redirect URL: the code only needs to show up in the address bar. Select the ad account, ads (read) and reporting permissions, and submit for review.
  3. Once approved, copy the App ID and Secret into TIKTOK_APP_ID and TIKTOK_APP_SECRET.
  4. Open the Advertiser authorization URL shown on the app page, pick the accounts and confirm. TikTok sends you back to your site with auth_code=... in the address bar.
  5. Run the script below and paste the whole address. The code works once, for about an hour.
python3 scripts/tiktok_oauth.py
python3 scripts/tiktok_test.py

If TikTok returns an expiration date, the script saves it as TIKTOK_TOKEN_EXPIRES_AT. Write it down: when the token expires, automations stop silently.

11Security

  • Keys stay in .env, on your computer. The skill adds .env to .gitignore before writing any key and never shows values in the chat. The scripts only talk to the platforms' own APIs.
  • Never push .env to GitHub, a group chat or another AI.
  • To revoke access: on Meta, delete or revoke the system user's token. On Google, remove the app at myaccount.google.com/permissions. On TikTok, deauthorize the app in Business Center.
  • New worktrees don't carry .env, precisely because it lives outside Git. If you open another Orca task for the same client, copy .env into its folder.

12What to ask next

With the accounts connected, the agent reads data straight from the source. A few requests I use every day:

Compare last week's spend, CPA and ROAS across Meta and Google Ads and tell me where the waste is.
List the campaigns that spent in the last 14 days without a single conversion.
Match GA4 purchases against the conversions Meta and Google report and show me the gap.
Build a daily report of yesterday's results and save it in reports/.

13FAQ

Is this a Meta Ads MCP server?

No. The connect-ads skill uses Python scripts that call the official APIs (Meta Marketing API, Google Ads API, GA4 Data API and TikTok Business API) straight from your computer, with the keys stored in .env. There is no MCP server to install or configure.

Does it work with both Claude Code and Codex?

Yes. It is the same skill for both: Claude Code looks for skills in ~/.claude/skills and Codex in ~/.agents/skills. Unzip it into the folder of the agent you use.

Do I still need a Google Ads API developer token?

No. Since September 9, 2026, Google Ads API access comes from your Google Cloud project, in access levels. The Explorer level is usually approved instantly and allows 2,880 operations a day on real accounts, with no manager account (MCC) required.

How much does it cost to connect Meta Ads and Google Ads to Claude?

The skill and Orca are free and open source, and the platforms don't charge for API access. The only cost is the agent subscription: Claude Pro or Max (Claude Code) or ChatGPT Plus or Pro (Codex).

Can the agent change my campaigns?

The skill's tests only read data: campaigns, spend and conversions. The Meta token in this guide includes the ads_management permission, so the agent can make edits if you ask. For read-only access, generate the token with only ads_read and read_insights.

Are my access keys safe?

They stay in the .env file on your computer. The skill adds .env to .gitignore before saving any key, never shows the values in the chat, and the scripts only talk to the platforms' own APIs.

How long does the setup take?

Meta Ads, Google Ads and GA4 are ready in about an hour. TikTok Ads requires an approved developer app, which can take a few days.

If you get stuck on any step, reach me on Instagram or X. The tools I use are linked at moisesmelo.com.