Lorixen.
EN

GA4 Measurement Protocol: sending server-side events

Short answer: GA4's Measurement Protocol lets your server send events straight to Google Analytics, for things that happen away from the browser: a subscription renewal, a refund processed in your back office, an order confirmed by phone, a lead marked as won in your CRM. You POST JSON to Google's collection endpoint with your measurement ID, a private API secret and the visitor's client_id, so the event joins the right user's journey. Google is clear that it adds to normal tagging rather than replacing it, so keep your site tag in place.

When server-side events are useful

GA4 normally learns about activity through the tag on your website or the SDK in your app. That misses anything that happens later or elsewhere:

  • A trial converts to a paid plan days after the visit.
  • A customer's monthly renewal is charged by your billing system.
  • A refund is issued by staff.
  • An enquiry form becomes a booked job after a phone call.
  • An offline payment is confirmed by your accounting system.

If those events never reach GA4, your reports show the visit and the form but not the outcome. The Measurement Protocol closes that gap.

What Google says it's for

Google's overview puts it plainly: the intent of the Measurement Protocol is to augment automatic collection through gtag, Tag Manager and Google Analytics for Firebase, not to replace it, and you must use tagging to use the protocol. Think of it as a way to add server-known events to journeys the tag already started.

The pieces you need

1. A measurement ID. For a web data stream, this is the ID in your GA4 data stream settings, usually starting with "G-".

2. An API secret. In GA4, go to Admin, then Data streams, choose the stream and open "Measurement Protocol API secrets", then create one. Google warns that the API secret is private: don't put it in your website's client-side code or your app. Keep it on your server with your other secrets.

3. The visitor's client ID. For web streams, Google says the client_id in your request should match the ID generated by the Google Analytics tag on your website. That's how GA4 knows the server event belongs to the same person who visited. Capture it when the visitor converts, for example by reading it with the tag and sending it with your form or checkout, and store it with the lead or order.

For app streams the equivalents are a Firebase app ID and the app_instance_id.

Sending an event

Google's guide shows the request format for web streams:

POST https://www.google-analytics.com/mp/collect?measurement_id=G-XXXX&api_secret=SECRET
Content-Type: application/json

{
  "client_id": "123.456",
  "events": [{
    "name": "subscription_renewed",
    "params": { "value": 29.00, "currency": "USD", "session_id": "1730000000" }
  }]
}

The values above are placeholders, not real figures. A few rules from Google's documentation:

  • Only HTTP POST requests are supported.
  • A request can contain up to 25 events, and an event up to 25 parameters.
  • Include parameters like session_id and engagement_time_msec if you want events tied to sessions, as Google's examples do.
  • Events can be backdated up to 72 hours using timestamp_micros. Google explains the order it uses to pick a timestamp: the event's own, then the request's, then the time the request arrives.

Test before going live

Google provides a validation server. Send the same request to /debug/mp/collect instead of /mp/collect. It doesn't record anything in your reports and returns a list called validationMessages describing problems, such as an invalid name or a missing required value. An empty list means the payload is well formed.

Validation checks the format, not your logic. After going live, check GA4's real-time or DebugView reports with a test user to confirm events appear against the right session.

Designing your events

Use consistent names. Lowercase with underscores, matching anything your site already sends. Don't create refund on the server if the site sends order_refund.

Decide which server events matter. Start with the outcomes you report on: paid conversion, renewal, refund, qualified lead, job won.

Avoid double counting. If the browser already sends purchase, don't send it again from the server for the same order. Use the server for events the browser can't see.

Send money values with currency. If you want revenue in reports, include value and currency.

Mark key events. If a server event represents a business outcome, mark it as a key event in GA4 so it appears in the right reports.

Privacy and policies

Google states that Measurement Protocol events joined to online interactions through client_id or app_instance_id adopt the user's privacy settings, such as non-personalised ads. Don't send names, email addresses or other personal details in event parameters, and follow Google's Measurement Protocol policy, which applies to every application using it. Check your own privacy notice covers server-side measurement.

Reliability

  • Send from a background job, not inside the customer's request, so a slow response from Google doesn't slow your checkout.
  • Log what you send, so you can investigate gaps.
  • Don't expect error messages from the live endpoint. Use the validation server during development and watch your reports afterwards.

A worked example

A hypothetical Seattle software company sells a monthly plan with a 14-day trial. GA4 shows sign-ups but never the trial converting, because billing happens on the server. The developer stores the visitor's client_id with each new account. When the billing system charges a first payment, a background job sends a trial_converted event with value and currency. Monthly renewals send subscription_renewed, and refunds issued by support send refund. After testing payloads on the validation server and confirming events in DebugView, the team marks trial_converted as a key event.

FAQ

Can I use the Measurement Protocol without the GA4 tag on my site?

Google says it's meant to augment tagging, and you must use tagging to use it. Keep the tag.

What if I didn't save the client ID?

The event can't be tied to the original visit. Start capturing it at sign-up or checkout from now on.

Can I send events older than three days?

Google documents backdating up to 72 hours. Older events need another approach, such as a data import.

Is this the same as server-side tagging?

No. Server-side tagging routes your site's tag traffic through your own server. The Measurement Protocol sends events your server creates itself.

If you'd like GA4 to show what happens after the form or checkout, tell us where those outcomes are recorded.

Sources

WhatsAppBook a call