Skip to content

Guide 95 · Admin · GA4 + Tag Manager

Send a GA4 event with the Measurement Protocol: the API secret, the client ID, and the POST

Checked 11 November 2026 · Verification: figures recomputed in Python 3, shown in the downloadable file · Steps traced to Google help and developer pages, opened 11 November 2026 · 7-minute read

The Measurement Protocol sends events to GA4 from your server with a POST to mp/collect. You need a Measurement ID, an API secret, and the browser client ID so the event joins the right session.

Expected signal

After the trace, the POST body names the event, carries the client ID from the browser, and the same body is ready for the validation server before production.

Download the reference: the measurement protocol send event reference (JSON) (452 bytes, MD5 420a8b19a98afabdbd843da32030f230). It holds the worked example from this guide with every figure recomputed. The file was built for this guide and checked the same day; it was not exported from a live property.

What you need

  • A web data stream with its Measurement ID, starting with G-.
  • A Measurement Protocol API secret from the stream settings.
  • The visitor's client ID, captured in the browser and sent with the form.

The trace

  1. Create the API secret. Open Admin, then Data streams, then the web stream, then Measurement Protocol API secrets, and create one. Keep the secret on the server only, never in front-end code.
  2. Capture the client ID in the browser. Without it, GA4 cannot join the server event to the session that produced it, and the event lands as a new user. Read the Analytics cookie or the value your tag already holds, and send it with the form data.
  3. Build the POST body. The endpoint is https://www.google-analytics.com/mp/collect, with the Measurement ID and API secret in the query string. The body names the client_id and an events array with one event, for example generate_lead with its parameters.
  4. Send the event at the moment the server saves the lead, after spam filtering, not before. An event sent for a submission you later reject still counts.
  5. Check the worked example in the download. A purchase sent from the server carries value 72.05, tax 6.12 and shipping 3.47. The order total is 72.05 + 6.12 + 3.47 = 81.64, while value itself excludes tax and shipping. Send value, tax and shipping as separate parameters, as Google's purchase example does.
  6. Confirm the event in Realtime within minutes, then in DebugView. The production endpoint returns 204 even for a malformed event, so a 204 alone proves nothing. Validation comes first, in the companion guide.

Dead ends

DEAD END — A 204 THAT MEANS NOTHING. The Measurement Protocol does not return HTTP error codes, even for malformed events. A 204 is not proof the event was accepted.

DEAD END — THE WRONG CLIENT ID. A server event with a fresh client ID creates a new user instead of joining the session. The client ID must come from the browser.

DEAD END — SENDING THE EVENT TWICE. If the browser tag also fires generate_lead, most leads will be counted twice. Send from one place only, or deduplicate by transaction ID.

End state

The order total is 81.64 from 72.05 plus 6.12 plus 3.47, with value alone at 72.05. The POST carries the browser client ID, and the 204 response is not treated as proof.

Sources

Checked 11 November 2026. The click paths above are the ones in Google's help and developer pages, opened 11 November 2026. No step in this guide was run inside a live Analytics property or a live Tag Manager container, because both need a Google sign-in and this site does not sign in as anyone. The figures on this page were recomputed in Python 3 and are shown in the downloadable file, which was checked the same day. Google moves menu items without warning; if a path on this page no longer matches, the linked help page is the current map.