Skip to content
adscapi
← Platforms
Real Conversions API

GA4 (Google Analytics) setup

Set GA4 (Google Analytics)’s tokens once. Then every ads.conversions.track() call fans the event out to GA4 (Google Analytics) server-side — no per-platform code.

1. Install adscapi

shell
npm install adscapi
# or run without installing:
npx adscapi platforms

2. Get GA4 (Google Analytics)'s tokens

GA4 (Google Analytics) activates once all of these are set. Run npx adscapi platforms to see them, then get each value from GA4 (Google Analytics)’s ads or events dashboard.

GA4_MEASUREMENT_IDGA4_API_SECRET

3. Set them for adscapi

Export the tokens in the environment that runs your server or the adscapi CLI.

shell
export GA4_MEASUREMENT_ID="…"
export GA4_API_SECRET="…"

4. Verify

check confirms the secrets are present; verify calls GA4 (Google Analytics)’s API to confirm they are valid.

shell
npx adscapi check
npx adscapi verify --platform ga4

5. Track a conversion

One call, sent to GA4 (Google Analytics) and every other configured platform. Pass raw email — adscapi hashes per platform. Consent is required.

ts
import { createAdscapi } from 'adscapi';

const ads = createAdscapi();

const results = await ads.conversions.track({
  name: 'purchase',
  value: 49,
  currency: 'USD',
  user: { email: 'buyer@example.com' },
  consent: { adUserData: true, adPersonalization: true },
});

See the exact request on the GA4 (Google Analytics) payload preview.