•
16 February 2018
Analytics & Optimisation
Customer Centric Strategy
Most of us use the Google Analytics suite on a day-to-day basis, without really thinking about how it all works. We install the GA or GTM code snippet on our websites, make some configurations, change some settings and add some tags, after which we dive straight into the reports. But we rarely think about how all that data is sent to the servers, how it is processed and ultimately shown in the Google Analytics user interface. The following will be an informational post on the first part of that process: how data is sent to the Google Analytics servers.
Google Analytics Measurement Protocol
All GA tracking systems (analytics.js, GTM, App SDKs, etc.) use the same standard set of rules for collecting and sending hits to the server, called the Measurement Protocol. This protocol allows us to send hits from any device that is connected to the internet, so not just websites or mobile applications.
When we use the Analytics JavaScript or mobile SDKs on our websites or mobile apps, they automatically build the hits that send the data to GA. But when we want to send data from other internet connected devices, we will have to build the collection hits ourselves. In essence, a hit is a simple HTTP request that is made to the GA server. How this hit should be formatted and sent to GA is defined by the Measurement Protocol.
Building a Google Analytics Hit
Currently, there are eight different types of hits that can be sent through the Measurement Protocol, the most important being pageviews, events and transactions. Every hit that sends data to Google Analytics should contain two parts: the transport and the payload.
Transport
The transport determines where and how your data is sent. Where your data is sent is determined by the URL endpoint of the HTTP request. For Google Analytics, this endpoint will always be the same:
https://www.google-analytics.com/collect
The type of request determines how your data is sent to Analytics. Generally, you can send data using either POST or GET requests. Google recommends sending hits via POST request, since it allows for a larger payload than GET requests. A POST request combined with the URL endpoint for GA will result in a transport that looks like this:
POST https://www.google-analytics.com/collect
Payload
The second part of the hit, the payload, looks like a URL query string with different parameters that contain the actual data that is being sent. For example, a very simple payload for a pageview hit may look like this:
v=1&t=pageview&tid=UA-12345678-9&cid=12345&dp=%2Fhomepage
Every payload has to abide by certain rules concerning required values, parameters that can or cannot be sent together, parameter length, etc. All values have to be UTF-8 encoded, some parameters can only be sent with certain hit types and some values have a maximum length in bytes. Luckily, Google has built a Hit Builder that checks all these different rules so that we don’t have to remember and check them for every hit we want to create.
Using the Measurement Protocol Hit Builder
The Hit Builder is part of the series of developer demos and tools built by the GA team. It’s very easy to use and allows users to construct hits for every different type, including all the necessary information that should be sent to Google Analytics. The tool consists of two parts: the hit parameter details, that you have to fill in according to the information you want to send, and the hit summary, that checks if your constructed hit does not break any of the rules mentioned before.
Let’s assume that we have an internet connected device with four buttons. The buttons measure customer satisfaction in a store (from very unhappy to very happy) by asking how happy customers were with the service and letting them press the corresponding button. Each button will then send a hit to Google Analytics. Using the Hit Builder, we can select and enter every payload parameter that we might want to send for every event.