Validate events

Choose your platform:

The Google Analytics Measurement Protocol does not return HTTP error codes, even if an event is malformed or missing required parameters. To ensure your events are valid, you should test them against the Measurement Protocol Validation Server before deploying them to production. After you have validated that your events are structured properly, you should verify your implementation to make sure you're using the correct keys.

You can either call the Validation Server directly, or use the Google Analytics Event Builder. The Google Analytics Event Builder lets you interactively construct events, and uses the Measurement Protocol Validation Server to validate them.

This guide describes how to send events to the Measurement Protocol for Google Analytics 4 Validation Server and interpret the response.

Sending events for validation

The only difference in the request for events sent to the Measurement Protocol and the Measurement Protocol Validation Server is the URL.

Server URL
Measurement Protocol /mp/collect
Measurement Protocol Validation Server /debug/mp/collect

All other request fields are the same. See the protocol reference for full details on constructing a valid request.

The following code shows an invalid event being sent to the Measurement Protocol Validation Server:

Validation response

Here's the Validation Server's response to the previous event:

{
  "validationMessages": [
    {
      "fieldPath": "events",
      "description": "Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.",
      "validationCode": "NAME_INVALID"
    }
  ]
}

Response

Key Type Description
validationMessages Array<ValidationMessage> An array of validation messages.

ValidationMessage

Key Type Description
fieldPath string The path to the field that was invalid.
description string A description of the error.
validationCode ValidationCode A ValidationCode that corresponds to the error.

ValidationCode

Value Description
VALUE_INVALID The value provided for a fieldPath was invalid. See limitations.
VALUE_REQUIRED A required value for a fieldPath was not provided.
NAME_INVALID The name provided was invalid. See limitations.
NAME_RESERVED The name provided was one of the reserved names. See reserved names.
VALUE_OUT_OF_BOUNDS The value provided was too large. See limitations.
EXCEEDED_MAX_ENTITIES There were too many parameters in the request. See limitations.
NAME_DUPLICATED The same name was provided more than once in the request.