Sub topic 15
Debugging Measurement Protocol Events
This chapter assumes you understand GA4 events and parameters, can access a GA4 property, and can send HTTP requests from a server or terminal. Measurement Protocol is an HTTP interface for sending events directly to GA4 instead of using a browser or app SDK.
Choose the Correct Endpoint
GA4 provides two related endpoints:
| Endpoint | Purpose | Records events? |
|---|---|---|
| `/debug/mp/collect` | Validates a payload | No |
| `/mp/collect` | Sends an event to GA4 | Yes |
Start with the debug endpoint. It returns validation messages without adding data to the property. After the payload passes validation, send the same payload to the collection endpoint.
The request needs a measurement ID, an API secret, a client or app instance identifier, and at least one event. Keep the API secret on a trusted server. Never place it in browser code or commit it to a repository.
Validate a Payload
This example validates a sign_up event:
curl -X POST "https://www.google-analytics.com/debug/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_API_SECRET" \
-H "Content-Type: application/json" \
-d '{
"client_id": "test.1234567890",
"events": [{
"name": "sign_up",
"params": {
"method": "email",
"debug_mode": 1
}
}]
}'The response contains a validationMessages array. An empty array means that the request passed the checks performed by this endpoint. It does not prove that the event was recorded or that every business rule is correct. For example, validation does not confirm that the event name represents the action you intended.
To send a validated request, change /debug/mp/collect to /mp/collect:
https://www.google-analytics.com/mp/collect?measurement_id=G-XXXXXXXXXX&api_secret=YOUR_API_SECRETThe debug_mode parameter marks the event as debug traffic. This helps DebugView identify the event. The parameter is not a replacement for a developer traffic filter. Configure that filter separately if test events must stay out of standard reports.
Make the Event Appear in DebugView
The normal sequence is:
- Build a payload with a stable test
client_id. - Validate it with
/debug/mp/collect. - Correct every validation error.
- Send it to
/mp/collectwithdebug_modeset to1. - Open Admin > Data display > DebugView.
- Select the device associated with the test client ID.
- Inspect the event and expand its parameters.
The event can appear in DebugView even when it is not yet visible in standard reports. DebugView is intended for near-immediate inspection, while standard reports use processed and aggregated data.
Common Failure Modes
- The validation endpoint succeeds, but DebugView is empty: You validated the event but did not send it to
/mp/collect. - The event is missing from DebugView: The request may lack
debug_mode, use a different client ID, or target the wrong property. - The API returns an error: Check the measurement ID, API secret, JSON syntax, and required identifier.
- The event appears later in reports: Processing delay is normal. Check Realtime and DebugView before concluding that delivery failed.
- Sensitive data appears in parameters: Remove personal data. GA4 event parameters must not contain information that identifies an individual.
Exercise
You receive an empty validationMessages array, but the event does not appear in DebugView. What should you check first?
Show answer
Confirm that you sent a second request to /mp/collect, included debugmode, used the same clientid while viewing DebugView, and targeted the intended GA4 property.