Organiza tus páginas con colecciones
Guarda y categoriza el contenido según tus preferencias.
Elige tu plataforma:
El Protocolo de medición de Google Analytics no devuelve códigos de error HTTP, incluso si un evento está mal formado o le faltan parámetros obligatorios. Para asegurarte de que tus eventos sean válidos, debes probarlos en el servidor de validación del Protocolo de Measurement antes de implementarlos en producción.
Después de validar que tus eventos estén estructurados correctamente, debes verificar tu implementación para asegurarte de que estás usando las claves correctas.
Puedes llamar al servidor de validación directamente o usar el Generador de eventos de Google Analytics. El Creador de eventos de Google Analytics te permite crear eventos de forma interactiva y usa el servidor de validación del Protocolo de medición para validarlos.
En esta guía, se describe cómo enviar eventos al servidor de validación del Protocolo de medición para Google Analytics 4 y cómo interpretar la respuesta.
Envía eventos para la validación
La única diferencia en la solicitud de eventos que se envía al servidor de validación del Protocolo de medición y al Protocolo de medición es la URL.
Servidor
URL
Protocolo de medición
/mp/collect
Servidor de validación del Protocolo de medición
/debug/mp/collect
Todos los demás campos de la solicitud son iguales. Consulta la referencia del protocolo para obtener todos los detalles sobre cómo construir una solicitud válida.
En el siguiente código, se muestra un evento no válido que se envía al servidor de validación de Measurement Protocol:
Respuesta de validación
Esta es la respuesta del servidor de validación al evento anterior:
{"validationMessages":[{"fieldPath":"events","description":"Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.","validationCode":"NAME_INVALID"}]}
A continuación, se muestra la respuesta del servidor de validación a una solicitud sin problemas de validación:
[[["Fácil de comprender","easyToUnderstand","thumb-up"],["Resolvió mi problema","solvedMyProblem","thumb-up"],["Otro","otherUp","thumb-up"]],[["Falta la información que necesito","missingTheInformationINeed","thumb-down"],["Muy complicado o demasiados pasos","tooComplicatedTooManySteps","thumb-down"],["Desactualizado","outOfDate","thumb-down"],["Problema de traducción","translationIssue","thumb-down"],["Problema con las muestras o los códigos","samplesCodeIssue","thumb-down"],["Otro","otherDown","thumb-down"]],["Última actualización: 2025-08-26 (UTC)"],[[["\u003cp\u003eThe Measurement Protocol Validation Server helps ensure your Google Analytics 4 events are correctly formatted before deploying to production.\u003c/p\u003e\n"],["\u003cp\u003eThe Validation Server uses a different URL endpoint (\u003ccode\u003e/debug/mp/collect\u003c/code\u003e) than the standard Measurement Protocol (\u003ccode\u003e/mp/collect\u003c/code\u003e).\u003c/p\u003e\n"],["\u003cp\u003eValidation responses provide detailed error messages including the field path, description, and a validation code for easier debugging.\u003c/p\u003e\n"],["\u003cp\u003eEvents sent to the Validation Server are not processed and will not appear in your Google Analytics reports.\u003c/p\u003e\n"],["\u003cp\u003eThe Google Analytics Event Builder offers an interactive way to construct and validate events before sending them to the server.\u003c/p\u003e\n"]]],["To ensure valid events, use the Measurement Protocol Validation Server by sending requests to `/debug/mp/collect` instead of `/mp/collect`. Validate events before deploying them. This server doesn't log events in reports. It returns a response with `validationMessages`, an array detailing any errors like `NAME_INVALID`, `VALUE_REQUIRED`, or `VALUE_OUT_OF_BOUNDS`, specifying the `fieldPath`, `description`, and `validationCode` of the issue. Use the Google Analytics Event Builder for interactive event construction.\n"],null,["Choose your platform: \nFirebase gtag.js\n\nThe Google Analytics Measurement Protocol does not return\n`HTTP` error codes, even if an event is malformed or missing required\nparameters. To ensure your events are valid, you should test them against the\nMeasurement Protocol validation server before deploying them to production.\nAfter you have validated that your events are structured properly, you should\n[verify your implementation](/analytics/devguides/collection/protocol/ga4/verify-implementation) to make sure you're using the correct keys.\n| **Caution:** The validation server does *not* validate the `api_secret` or Carefully review those values to make sure they are correct.\n\nYou can either call the validation server directly, or use the [Google Analytics\nEvent Builder](https://ga-dev-tools.web.app/ga4/event-builder/). The Google Analytics Event Builder lets you interactively\nconstruct events, and uses the Measurement Protocol validation server to\nvalidate them.\n\nThis guide describes how to send events to the Measurement Protocol for Google\nAnalytics 4 validation server and interpret the response.\n| **Important:** Events sent to the validation server don't show up in reports.\n\nSend events for validation\n\nThe only difference in the request for events sent to the Measurement Protocol\nand the Measurement Protocol validation server is the URL.\n\n| Server | URL |\n|----------------------------------------|-------------------------|\n| Measurement Protocol | `/mp/collect` |\n| Measurement Protocol validation server | `/`*debug*`/mp/collect` |\n\nAll other request fields are the same. See the [protocol](/analytics/devguides/collection/protocol/ga4/reference) reference for full\ndetails on constructing a valid request.\n\nThe following code shows an invalid event being sent to the Measurement Protocol\nvalidation server:\n| **Tip:** If you want your data to be collected in the EU, change the URL passed to the `fetch` method to begin with `https://region1.google-analytics.com` instead of `https://www.google-analytics.com`.\n\nValidation response\n\nHere's the validation server's response to the previous event: \n\n {\n \"validationMessages\": [\n {\n \"fieldPath\": \"events\",\n \"description\": \"Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.\",\n \"validationCode\": \"NAME_INVALID\"\n }\n ]\n }\n\nHere's the validation server's response to a request with no validation issues: \n\n {\n \"validationMessages\": []\n }\n\nResponse\n\n| Key | Type | Description |\n|----------------------|---------------------------------------------------|----------------------------------|\n| `validationMessages` | Array\\\u003c[ValidationMessage](#validation_message)\\\u003e | An array of validation messages. |\n\nValidationMessage\n\n| Key | Type | Description |\n|------------------|------------------------------------|--------------------------------------------------|\n| `fieldPath` | string | The path to the field that was invalid. |\n| `description` | string | A description of the error. |\n| `validationCode` | [ValidationCode](#validation_code) | A validation code that corresponds to the error. |\n\nValidationCode\n\n| Value | Description |\n|-------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------|\n| `VALUE_INVALID` | The value provided for a `fieldPath` was invalid. See [limitations](/analytics/devguides/collection/protocol/ga4/sending-events#limitations). |\n| `VALUE_REQUIRED` | A required value for a `fieldPath` was not provided. |\n| `NAME_INVALID` | The name provided was invalid. See [limitations](/analytics/devguides/collection/protocol/ga4/sending-events#limitations). |\n| `NAME_RESERVED` | The name provided was one of the reserved names. See [reserved names](/analytics/devguides/collection/protocol/ga4/reference#reserved_names). |\n| `VALUE_OUT_OF_BOUNDS` | The value provided was too large. See [limitations](/analytics/devguides/collection/protocol/ga4/sending-events#limitations). |\n| `EXCEEDED_MAX_ENTITIES` | There were too many parameters in the request. See [limitations](/analytics/devguides/collection/protocol/ga4/sending-events#limitations). |\n| `NAME_DUPLICATED` | The same name was provided more than once in the request. |"]]