Skip to Content
Docs

Destinations to Google Analytics 4

Send your conversions to Google Analytics 4 as events with a destination.

The type ga4 sends the conversions of your workspace to Google Analytics 4 as events. It uses the Measurement Protocol. You need an API key with the scope destinations:write and a Measurement Protocol API secret of a GA4 data stream. Read the common rules for all types (events, filters, delivery, retries and backfill) in Destinations.

Make the destination

Make an API secret in the data stream of your GA4 property. Then make the destination:

curl -X POST https://api.afffast.com/v1/destinations \
  -H "Authorization: Bearer $AFFFAST_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "type": "ga4",
    "label": "Google Analytics",
    "config": { "measurement_id": "G-XXXXXXXXXX", "event_name": "affiliate_conversion" },
    "credentials": { "api_secret": "..." }
  }'
FieldKindMeaning
measurement_idSettingThe ID of the web data stream, for example G-ABC123DEF4. It is required.
event_nameSettingThe GA4 event name. The default is affiliate_conversion. Use letters, digits and _. 25 characters at most.
client_id_subidSettingThe user sub ID that holds the GA4 client ID (the _ga cookie value of the visitor). Without it, the event uses the click ID as client ID.
regionSettingeu sends the events to the EU endpoint of Google. The default is global.
api_secretCredentialA Measurement Protocol API secret of the data stream. The API never returns it.

The GET /v1/destination_types response is the source of truth. It has the description and the options of each field.

What it sends

  • Each conversion change goes to Google Analytics 4 as one Measurement Protocol event.
  • Your site must put the GA4 client ID in the link as a sub ID. Set client_id_subid to that sub ID.
  • Google Analytics 4 takes only events that are not older than 72 hours. It takes no backfill of old data.

Test the destination

POST /v1/destinations/{id}/test sends one test item. The test uses the debug endpoint of Google, so the answer says if the event is valid. See Test a destination.

Delivery

Google Analytics 4 is an analytics type. The API tries again until the item is 72 hours old. Google drops older events. Then the API skips the item and goes on. When the destination has failed for more than 72 hours, its status is failing and the API writes the event destination.failed once. It keeps trying. The first delivery that works sets the status active again. You do not need to resume it. See Delivery.

On this page