Adswerve

Google Analytics Measurement Protocol Debugger


February 9, 2015

Measurement Protocol is a low level protocol for Google Universal Analytics that allows developers to track user interactions using HTTP requests. At Analytics Pros, we have demonstrated the possibilities of using it in new environments by tracking the game of bocce ball and implementing Google Analytics into movement sensors to track the activities in our office. One of the keys of making sure that your implementation is correct is confirming that all the hits being sent are syntactically valid. This is now possible with the Measurement Protocol Debugger.

Sending Hits and Using the Debugger

Sending a hit is pretty straight-forward. We need to create an HTTP request to http://www.google-analytics.com/collect and use a set of parameters to shape the interaction. If we want to debug the request all we need to do is set our HTTP requests to https://www.google-analytics.com/debug/collect.

The protocol has 4 required parameters:

  1. v (version)
  2. tid (property id or tracking id)
  3. cid (anonymous client id)
  4. t (hit type)

Let’s cut straight to the chase. We have decided that we want to track the little display that nowadays almost everyone has in their car.  Whenever someone turns that display on we want to track a pageview for the main screen. Our property id is UA-123456-1, client id is a random number (let’s say 43223523) to identify a car, and the current protocol version is 1.

The HTTP Request will look something like this:

https://www.google-analytics.com/collect?v=1&cid=43223523&tid=UA-123456-1&t=pageview

But, just to be sure, we use the debugger to test our request.

https://www.google-analytics.com/debug/collect?v=1&cid=43223523&tid=UA-123456-1&t=pageview

The debugger responds with

{
  "hit_parsing_result": [ {
    "valid": false,
    "parser_message": [ {
      "message_type": "ERROR",
      "description": "A value is required for parameter 'dp'. Please see http://goo.gl/a8d4RP#dp for details.",
      "parameter": "dp"
    } ],
    "hit": "GET /debug/collect?v=1u0026cid=43223523u0026tid=UA-123456-1u0026t=pageview HTTP/1.1"
  } ]
}

The debugger replies with a JSON object showing that our hit is not valid and is missing a dp parameter. From the reference in the response (see the Google developer documentation here: http://goo.gl/a8d4RP#dp) we realize that we’re missing a page path. Since we’re trying to measure a pageview in the main menu, let’s try using “/main-menu” as its value.

This time let’s debug it first:

https://www.google-analytics.com/debug/collect?v=1&cid=43223523&tid=UA-123456-1&t=pageview&dp=/main-menu

Now the results make us happier:

{
  "hit_parsing_result": [ {
    "valid": true,
    "parser_message": [ ],
    "hit": "GET /debug/collect?v=1u0026cid=43223523u0026tid=UA-50342403-1u0026t=pageviewu0026dp=/main-menu HTTP/1.1"
  } ]
}

We have made a valid HTTP Request to the Measurement Protocol.

Now let’s remove the “debug” part and check what happens in our Real Time Google Analytics dashboard.

https://www.google-analytics.com/collect?v=1&cid=43223523&tid=UA-123456-1&t=pageview&dp=/main-menu
We're now successfully tracking views of the /main-menu page.

Google Analytics Real Time screenshot shown above: tracking views on the /main-menu page.

We’re now successfully tracking views on the /main-menu page.

Taking the Implementation a Step Further

Now that you’re able to identify possible irregularities in your HTTP Requests faster, you can focus on the data. Look through the parameters and see how you can implement custom dimensions to track the model of the car together with the pageview. Make sure to debug the interaction before sending it to production. Finding what day of the week Toyota drivers like to look at their car screens most often will now be a breeze.

3 Notes

  1. Hits sent to debugger will not show up in the reports.
  2. The tool is still in Beta so not all cases may be handled correctly yet.
  3. The tool only checks if parameters are parsed correctly, any configurational settings (filters, dimensions, etc.) will not be detected.