Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Scegli la tua piattaforma:
Measurement Protocol di Google Analytics non restituisce
codici di errore HTTP, anche se un evento è formattato in modo errato o mancano i parametri
obbligatori. Per garantire la validità degli eventi, dovresti testarli in relazione al server di convalida di Measurement Protocol prima di eseguirne il deployment in produzione.
Dopo aver verificato che gli eventi siano strutturati correttamente, devi
verificare l'implementazione per assicurarti di utilizzare le chiavi corrette.
Puoi chiamare direttamente il server di convalida o utilizzare lo strumento di creazione eventi
di Google Analytics. Lo strumento di creazione di eventi di Google Analytics ti consente di creare eventi in modo interattivo e utilizza il server di convalida di Measurement Protocol per convalidarli.
Questa guida descrive come inviare eventi al server di convalida di Measurement Protocol per Google
Analytics 4 e interpretare la risposta.
Inviare eventi per la convalida
L'unica differenza nella richiesta di eventi inviati a Measurement Protocol
e al server di convalida di Measurement Protocol è l'URL.
Server
URL
Measurement Protocol
/mp/collect
Server di convalida di Measurement Protocol
/debug/mp/collect
Tutti gli altri campi della richiesta rimangono invariati. Consulta il riferimento al protocollo per tutti i dettagli sulla creazione di una richiesta valida.
Il seguente codice mostra un evento non valido inviato al server di convalida di Measurement Protocol:
Risposta di convalida
Ecco la risposta del server di convalida all'evento precedente:
{"validationMessages":[{"fieldPath":"events","description":"Event at index: [0] has invalid name [_badEventName]. Names must start with an alphabetic character.","validationCode":"NAME_INVALID"}]}
Ecco la risposta del server di convalida a una richiesta senza problemi di convalida:
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Mancano le informazioni di cui ho bisogno","missingTheInformationINeed","thumb-down"],["Troppo complicato/troppi passaggi","tooComplicatedTooManySteps","thumb-down"],["Obsoleti","outOfDate","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Problema relativo a esempi/codice","samplesCodeIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 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. |"]]