Skip to content

Measurement Protocol

You can send data from your server/backend directly to Google Analytics servers. Measurement Protocol enables you to send additional data, that can’t be sent on the “traditional” way (client side)

Server side vs client side

You can send data in two ways to Google Analytics. The first and most common version is the client side and the other one is the server side.

Client Side tracking

If you use Google Tag Manager or gtag.js you use the client side tracking. It means, the basic Google Analytics loads at the client’s/visitor’s browser. Of course, the pageview and other hit’s are fired from the browser, too.

Most of the trackings are client side. You just add the tracking code/pixel and the JavaScript code do the rest. OK, you have to add some more code, for proper tracking 🙂

If you have installed some tag management system, such as Google Tag Manager, you can use it to install every pixel without any help of the developers.

You can easily modify the events add new ones and change the necessary parameters, with or without GTM. So it is a flexible and very common tracking method.

But it has downsides. You only have to track events that occurs on the client’s browser. When the user left your site and contacted with you another way, you can’t track (with the classic method).

If the basic (in this example, the Google Analytics) tracking code failed to load, you lost the user generated hit. Let’s say it is a simple pageview, it is not OK, but not a big loss, but if it is a purchase/transaction is a bigger issue.

There are several ways to fail the load of the tracking code from slow internet, browser specific errors to some other very-very specific issue. It happens unfortunately. The client side tracking is not bulletproof, but works.

Server side tracking

If you need more accurate tracking you can go with the server side version of Google Analytics tracking. And of course, if you would like to send off-site events to Google Analytics, you should use it, too 🙂

So, with server side tracking you send data directly to Google Analytics. It’s more precise, because the client side factor is not disturb the data. On the other hand, it is harder to implement. You need the help of the developer team, it is more than just add a basic tracking code and your are good. And you can’t use any tag management system, because these tools are client side, too.

What kind of data I can send

Basically, you can track every kind of data with measurement protocol, but I suggest you to make a mixed tracking. Although, you can send every single hit with Measurement Protocol, it is usually too much effort.

Send just the main points/conversions with server side and also the ones that occurs offsite.

The offsite events are when someone starts the process online and finishes it offline. If you can catch it, you should rewire it back to Google Analytics

The Measurement Protocol setup

As I mentioned earlier, the setup is more complex than the client side tracking. With the following steps and the help of your developer, you can implement it to your ecommerce store.

You can find here official documentation of the measurement protocol.

To send user interaction data to Google Analytics with measurement protocol you have to add 2 key element for tis call.

The first one is the endpoint. You send the HTTP Post request to this endpoint:

POST /collect HTTP/1.1 
Host: www.google-analytics.com 

payload_data

The second part of the HTTP Post request is the payload data. It contains the actual information.

v=1              // Version. 
&tid=UA-XXXXX-Y  // Tracking ID / Property ID. 
&cid=555         // Anonymous Client ID. 
&t=              // Hit Type.

The first part of the call tell the servers where to send the payload information. The second one contains every single detail. The code above is a very simple one. An actual payload has way more data.

A real life measurement protocol call is looks like a url with lots of parameters (it is the payload)

The following paragraphs show the details of the 2 element of the request

The protocol reference

There are some rules you have to follow in order to the successful HTTP Post request. The official documentation is here: https://developers.google.com/analytics/devguides/collection/protocol/v1/reference

The parameter reference

This documentation is essential for a good measurement protocol implementation. You can find every element you can send to Google Analytics here: https://developers.google.com/analytics/devguides/collection/protocol/v1/parameters

Tips for successful Measurement Protocol implementation

There are some tips you should consider. Without it some of your calls fail and never arrive to Google Analytics

User Agent Override

Here it is the link of this parameter. It just override the user agent, which is usually looks like this:

Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14

It is a user’s user agent. But if you send data from server side, you usually send the user agent of the server, not the user’s. It results, that the Google Analytics spam filter blocks it, because it is not a reail user agent.

You just simply save the users’ real user agent and add it the request as an additional parameter.

User IP

The mechanics of the problem is the same as the user agent. If you don’t save and add the users’ real ip address Google Analytics blocks it.

Here you can find the link of the parameter.

Client ID

You can use random Client ID, if you don’t know the user, just would like to send the data to Google Analytics. But if you are able to save the users’ Client ID, you should use it, because if you don’t it masses the Google Analytics reports.

It’s a simple task, just read it from the Google Analytics tracker and save/add it to the post requests.

Chache buster

It a random number, it helps to not chache the request you would like to send. Just add it every call 🙂

Firewall

Check the firewall setup, maybe it blocks some of your calls.

How to test it

The test of the measurement protocol implementation is a bit harder than the test of the client side tracking. The consol of your browser doesn’t tell you anything, because the hit is not populated in you browser.

To test it, you should log every call on your server and compare it with the Google Analytics property you send the data.

Don’t forget, first you just send the data to a test Google Analytics property, not the live one.

Another way to test/debug it is to send every hit to the debug endpoint. Important, if you use it, you have to send the “original” endpoint tha data, too. The debug one is just for debug 🙂

Published inAnalytics

Comments are closed.