This document describes how to validate Google Analytics Measurement Protocol hits.
Overview
The Google Analytics Measurement Protocol does not return HTTP error codes, even if a Measurement Protocol hit is malformed or missing required parameters. To ensure that your hits are correctly formatted and contain all required parameters, you can test them against the validation server before deploying them to production.
This guide describes the process for sending hits to the Measurement Protocol Validation Server and explains how to interpret the response.
Sending hits for validation
Hits can be sent to the Measurement Protocol Validation Server via any
method currently supported by the Measurement Protocol. The only
difference is the URL. To send hits to the Measurement Protocol Validation
Server use the endpoint /debug/collect
instead of
/collect
. The follow example shows an invalid hit sent to the
Measurement Protocol Validation Server:
https://www.google-analytics.com/debug/collect?tid=fake&v=1
For more details on how to construct a Measurement Protocol hit, see the protocol reference.
Interpreting the Response
Responses from the Measurement Protocol Validation Server will be in JSON format. The following example shows the response for the hit shown above:
{ "hitParsingResult": [ { "valid": false, "hit": "GET /debug/collect?tid=fake\u0026v=1 HTTP/1.1", "parserMessage": [ { "messageType": "ERROR", "description": "The value provided for parameter 'tid' is invalid. Please see http://goo.gl/a8d4RP#tid for details.", "parameter": "tid" }, { "messageType": "ERROR", "description": "Tracking Id is a required field for this hit. Please see http://goo.gl/a8d4RP#tid for details.", "parameter": "tid" } ] } ] }
The response root, hitParsingResult
, is an array whose
length will correspond to the number of hits sent in the original request.
Each object in the array will contain the keys valid
,
hit
, and parserMessage
. If a hit is invalid,
parserMessage
will contain an array of objects describing the
validation issues. If a hit is valid, parserMessage
will be an
empty array.
The following table describes the properties of each item in the
hitParsingResult
array:
Key | Type | Description |
---|---|---|
valid |
Boolean |
true for valid hits, false for invalid
hits. |
hit |
string |
A string containing the path of the request as well as its method and protocol. |
parserMessage |
Array |
A list of parser messages. If the hit is valid, this array will be empty. |
parserMessage.messageType |
string |
Possible values are "INFO", "WARN", and "ERROR". |
parserMessage.description |
string |
Additional details or steps to fix the validation issue. |
parserMessage.parameter |
string|undefined |
The parameter (if applicable) causing the validation issue. |