• Skip to main navigation
  • Skip to main content
  • Jump to the main sidebar

Carlosmdh

  • Migra ahora a Google Analytics 4
  • Blog
  • Snippets
  • Tutorials
  • Q&A GA4
  • About Me
  • Contact Me

How Google Analytics collects and sends data (IV). Measurement Protocol Data Collection

21 febrero, 2021

In previous articles we have seen how websites use JavaScript code and how applications use the SDK to send data to Google Analytics. But what happens if we want to obtain and send data from another device, such as a POS or an electronic kiosk, or a mobile device based on Windows Mobile?

Don't panic, we can also collect and send data to Google Analytics from these devices, as long as they are connected to the Internet.

As we saw in previous articles, both a website and a mobile application can send data automatically to Analytics, well in the case of applications, in packets every so often. But if what we want is to send data from other devices, we will have to do it by hand, using the measurement protocol implemented by Analytics in its Universal version, which defines how to generate these results to be sent later to the Analytics servers.

Create and send hits in Google Analytics

Table of contents

  • Measurement protocol
  • How to implement the Google Analytics measurement protocol

Measurement protocol

Measurement Protocol is nothing more or less than doing the work done by JavaScript or the SDK by hand, well, not by hand but by programming and following the formatting and data sending guidelines dictated by Google. You can get all the information in the following links:

Overview of the Measurement Protocol. A brief introduction to what the Measurement Protocolis,

Adeveloper's guide to the measurement protocol. A description of how to send data to Google Analytics using the Measurement Protocol (which is really how both analytics.js and the SDks send data. 

Parameter reference of the measurement protocol. List of the parameters and values that we can use to build the hit that we will send to Google Analytics.

Measurement protocol policy / SDK / UserID. A very brief document that informs us of the privacy policies that we must comply with when sending data to Google Analytics servers.

Okay, and now you may be wondering, what use can this have in practice and how is it done? Well, uses, unlimited, from measuring the traffic of people through a physical store using WiFi receivers or beacon receivers and thus make us a map of routes, to, for example, to know how many drinks a day are bought in a machine that we have in a train station, and what kind. All this from Analytics.

OK, we can know the latter by looking at the counters of the machine, but what if we want to analyze it together with the sales on the Web or we want to know what the weather was like at each location of each machine to try to establish a relationship between weather vs. sales of a particular product?

How to implement the Google Analytics measurement protocol

And how it would be done, in our hands, well in the hands of a programmer, fall the two steps.

First collect the data we want from the device, identification of the device, location, time of sale, how the payment was made, price of the sale, product sold... whatever we want to measure.

Secondly, and also through programming, generate an http POST or https POST request to the Google Analytics servers to send the data we have collected, which is called a load or a hit. We will do this by building, from scratch, a URL, where each parameter has a key and a value separated by a character "= " and each parameter is delimited with a character "&", with a format similar to the one you see below.

It's the same thing that appeared in the article where we talked about how GA collects and sends the data to the server.

If you still haven't understood it, don't worry, it took me a while to finish polishing some doubts and I had to go to a programmer friend, thanks Jesus for your patience XD.

I'm going to try to explain it with the example that occurred to us when we were leaving the Mexican place where we had lunch so that he could explain it to me.

In the Mexicano there were dishes and drinks, which you could choose to make a menu, there were also people behind the counter who attended to your order, they ordered it to the kitchen, chopped what you were going to eat and drink at a POS, took the ticket and charged you. Let's imagine that we want to measure, with Google Analytics, what elements make up customer orders, who serves them and what we bill.

What would have to be done is to program the POS, so that it captures the data that the "shopkeeper" enters: order, products that compose it, number of people, unit price of each product and total price of the order, for example. Once this data is captured, in the same way that the ticket that is printed for the client is generated, the program would be responsible for building the URL that you want to send to the GA server, which will have a fixed part and a variable part and that could look something like this:

Google Analytics measurement protocol

The variables and data in red are mandatory and tell Analytics the protocol version, the property to send data to, the client id and the type of hit. This last parameter can take the following values: "pageview", "screenview", "event", "transaction", "item", "social", "exception" or "timing". There are more variables, but these are the mandatory ones, you can see all the variables defined by Google at https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters?hl=es.

The variables and data in green are the ones we have defined and created and correspond to the data we want to capture (products, unit prices and total price).

Once Analytics receives this string, it will process it and include the data in the corresponding tables, making it available for analysis.

In short, using the GA measurement protocol, you can obtain data from any device, both present and future, and integrate it into your Google Analytics account for further analysis, regardless of the language or operating system that supports that device.

Universal Analytics

Sidebar

Sidebar-Alt

Blog - Snippets - Tutorials

Privacy Policy - Cookie Policy - Change your Consent


carlosmdh © 2023 · Made with by carlosmdh

We use cookies to give you the best experience on our website.

Puedes aprender más sobre qué cookies utilizamos o desactivarlas en los ajustes.

Carlosmdh
Powered by  GDPR Cookie Compliance
Privacy summary

This website uses cookies so that we can provide you with the best possible user experience. Cookie information is stored in your browser and performs functions such as recognising you when you return to our site or helping our team understand which parts of the site you find most interesting and useful.

Strictly necessary cookies

Strictly necessary cookies must always be enabled so that we can save your cookie settings preferences.

If you disable this cookie we will not be able to save your preferences. This means that each time you visit this website you will have to enable or disable cookies again.

Cookies de terceros

Esta web utiliza Google Analytics para recopilar información anónima tal como el número de visitantes del sitio, o las páginas más populares.

Dejar esta cookie activa nos permite mejorar nuestra web.

¡Por favor, activa primero las cookies estrictamente necesarias para que podamos guardar tus preferencias!

Cookies adicionales

Esta web utiliza las siguientes cookies adicionales:

(Lista aquí las cookies que estás utilizando en la web.)

¡Por favor, activa primero las cookies estrictamente necesarias para que podamos guardar tus preferencias!

  • Español
  • Français