GA4 Measurement Protocol: server-side event sending explained

Key Takeaway

Measurement Protocol lets you send events to GA4 from servers, IoT devices, or offline systems. But it bypasses consent mode, does not create sessions, and requires manual validation since there is no browser to inspect.
Intermediate

The GA4 Measurement Protocol (MP) is the mechanism for sending events to Google Analytics from your server rather than from a user's browser. While the majority of GA4 implementations use the JavaScript tag or GTM to collect data client-side, the Measurement Protocol opens up use cases that client-side tracking cannot address: offline conversions, subscription renewals, in-store purchases, events from IoT devices, and post-checkout server confirmations that need to fire regardless of what happens in the user's browser.

What the measurement protocol can do

TheGA4 Measurement Protocolallows you to send events to a GA4 property via a standard HTTP POST request. It is closely related to, but distinct from, a fullGA4 server-side taggingsetup. The primary use cases where MP adds genuine value that client-side tracking cannot provide:

  • Server-side purchase confirmation: fire a purchase event from your server after the payment processor confirms the transaction, ensuring the event fires even when the user closes the browser before the thank-you page loads
  • Subscription renewals: monthly or annual renewals processed automatically have no browser session; MP allows these to be sent to GA4 as purchase events tied to the original user
  • Offline conversions: a customer who calls your team and converts can have a conversion event sent to GA4 by your CRM after the call is logged
  • IoT and kiosk devices: GA4 events from devices that cannot run a JavaScript browser
  • Data enrichment: augmenting client-side events with server-side data like margin, profit, or CRM segment

What the measurement protocol cannot do

The GA4 Measurement Protocol is a supplement to client-side tracking, not a replacement. Google's documentation makes this explicit.

Measurement Protocol works best when it augments existing tagged interactions. If you send an MP request without a usable identifier and session context, reporting can become partial: attribution may be weak, source and medium may appear as(not set), and some joined data may be missing.

Additionally, geographic and device information cannot be derived from MP requests unless you pass them explicitly. The client-side tag derives location from the user's IP and device info from the browser user agent. MP requests arrive from your server's IP and carry no browser-level signals by default.

Building a valid measurement protocol request

Every MP request requires four components. The steps below show how they fit together into a complete, valid payload. Before sending live traffic, use the Measurement Protocol debug endpoint athttps://www.google-analytics.com/debug/mp/collectto validate the structure of your payload — it returns validation messages without recording the event in your property.

1

API secret and measurement ID

Generate an API secret in GA4 Admin > Data Streams > Measurement Protocol API secrets. Pass your Measurement ID (G-XXXXXXXXXX) and the api_secret as query parameters in the POST URL: https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXX&api_secret=YOUR_SECRET. The secret authenticates the request — keep it server-side only.

2

client_id, the user identifier

Read the client_id from the user's _ga cookie. This is the field that ties your MP event to the correct user's existing data. The _ga cookie value is in the format GA1.2.XXXXXXXXXX.XXXXXXXXXX, the client_id is the last two dot-separated segments: XXXXXXXXXX.XXXXXXXXXX.

3

Events array, the event payload

Build a JSON payload with the client_id at the top level and an events array. Each event needs a name and a params object. For purchase events, include currency, value, transaction_id, and an items array. Example: { "client_id": "555.8888888", "events": [{ "name": "purchase", "params": { "currency": "GBP", "value": 49.99, "transaction_id": "ORD-9876" } }] }

4

session_id, for correct attribution

Include the session_id from the _ga_MEASUREMENTID cookie to attach the event to an existing session. Without it, the MP event will appear in GA4 with (not set) for source and medium. The session_id is the Unix timestamp of when the session started. Read it from the browser before the session ends and store it alongside the order.

Session attribution: the most common failure mode

The most frequent problem with MP implementations is events arriving with (not set) for session source and medium. This happens because GA4 cannot associate an MP event with a session unless thesession_idparameter is included. The practical workflow: when the user reaches your checkout page, your client-side code reads both the client_id from the_ga cookieand the session_id from the_ga_MEASUREMENTID cookie, passes these values to your server, which stores them against the order. When the payment processor confirms, your server sends the MP purchase event using both the stored client_id and session_id. The same context object should also carry the standardGA4 purchase event parameters— currency, value, transaction_id, and the items array — so the server hit is structurally identical to a healthy client-side hit.

Are your Measurement Protocol events creating orphaned sessions with no attribution?

Deduplication with transaction ids

When you combine client-side purchase tracking with server-side MP purchase confirmation, both events may arrive in GA4 with the sametransaction_id. GA4 can use transaction_id to help deduplicate purchase events in web reporting, but this depends on correct implementation and should be validated in your own property. Do not assume deduplication is a perfect safeguard — review our breakdown ofduplicate transactions in GA4for the patterns that most often defeat it.

API secret security

The Measurement Protocol API secret should never be exposed in client-side code, including GTM containers. If a user finds your API secret, they can send arbitrary events to your GA4 property with any parameters, including fake purchase events with inflated revenue. The secret must only exist on your server, transmitted exclusively in server-to-server requests.

Measurement protocol: validate, fix, and monitor

Validate

  • Query BigQuery for events where the collected_traffic_source or event parameters indicate server-sent hits, look for measurement_protocol=true or missing geo/device fields that server requests leave blank
  • Compare MP event counts in BigQuery to your expected server-side event volume from your order management system or CRM, large discrepancies indicate dropped or duplicate MP requests

Fix

  • Ensure client_id is read from the _ga cookie and stored against the transaction before the session ends. MP requests sent after the cookie expires will create orphaned events
  • Ensure event_timestamp (in microseconds) is set correctly when sending historical or delayed events, incorrect timestamps cause events to appear in the wrong date partition in BigQuery

Watch for

  • MP hits creating orphaned sessions with no attribution, visible in GA4 as (not set) source/medium on purchase events, or in BigQuery as events with missing session_traffic_source_last_click data

Measurement protocol checklist

  • API secret is stored server-side only, never in client-side code or GTM
  • client_id is read from the _ga cookie and passed with every MP request
  • session_id is read from the _ga_MEASUREMENTID cookie and included for session attribution
  • transaction_id on MP purchase events matches the client-side purchase event for deduplication
  • MP is used as a supplement to client-side tracking, not as a standalone replacement
  • MP events are validated using the debug endpoint before deploying to production

Validate your measurement protocol implementation

GA4 Audits helps review orphaned MP sessions, attribution gaps, and purchase deduplication risks in your GA4 property and BigQuery export.

Audit findings should be reviewed by a qualified analyst before they are used for major reporting, media, or implementation decisions. Review your findings

GA4 Audits Team

GA4 Audits Team

Analytics Engineering

Specialising in GA4 architecture, consent mode implementation, and multi-layer audit frameworks.

Share