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.
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 --versionin 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 usepywherever this guide sayspython3.
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
- Click Add Repo in the sidebar and pick the folder you created.
- Click the + next to the repository name, name the task (for example
connect-ads) and keep the suggested base. - 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.
- Business portfolio: open business.facebook.com/settings. The ID is in the URL, after
business_id=. - 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.
- System user: in Business settings > Users > System users, click Add, name it and choose the Admin role.
- Assign assets: on that user, use Assign assets and give full control of the ad account, the Page, the Pixel (dataset) and the app.
- Generate the token: click Generate new token, pick the app, expiration Never and the permissions
ads_read,ads_management,business_management,pages_read_engagementandread_insights. The token is shown once: paste it into.envasMETA_ACCESS_TOKEN. - 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.
- At console.cloud.google.com, create a project (for example "Ads Operator").
- Under APIs & Services > Library, enable the Google Ads API, the Google Analytics Admin API and the Google Analytics Data API.
- 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.
- Under Clients, create an OAuth client of type Desktop app. Copy its ID and secret into
GOOGLE_CLIENT_IDandGOOGLE_CLIENT_SECRET.
08Google Ads
- 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.
- Copy the 10-digit ID shown at the top of Google Ads into
GOOGLE_ADS_CUSTOMER_ID. - If you reach the account through an MCC (manager account), put the MCC ID in
GOOGLE_ADS_LOGIN_CUSTOMER_IDand check on the client account that the link was accepted. If you don't use an MCC, leave it empty. - 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
- Make sure your Google user has at least Viewer access to the property (GA4 > Admin > Property access management).
- Copy the
G-...measurement ID (Admin > Data streams) intoGA4_MEASUREMENT_ID. - 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.
- In TikTok Ads Manager, copy the ad account ID (numbers only) into
TIKTOK_ADVERTISER_ID. - 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.
- Once approved, copy the App ID and Secret into
TIKTOK_APP_IDandTIKTOK_APP_SECRET. - 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. - 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.envto.gitignorebefore writing any key and never shows values in the chat. The scripts only talk to the platforms' own APIs. - Never push
.envto 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.envinto 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/.
If you get stuck on any step, reach me on Instagram or X. The tools I use are linked at moisesmelo.com.