Measurement protocol and sessions in GA4

If you understand the GA4 sessions correctly, you will find that they differ in many ways from Universal Analytics. I recommend reading this article for a better understanding.  

Many companies send some of the events through the Measurement Protocol, for example, after the real profit per purchase has been determined. In Universal Analytics, if the transaction was sent correctly, it was assigned to that user’s session automatically. However, this is not the case in GA4 because sessions are not created during the processing of the data. In this case, it is necessary to enrich the data with a session ID when sending the data through the Measurement Protocol.

If the session_id is not sent correctly at the session reporting level in GA4, the purchases will be marked as „Unassigned.“

If we want to avoid this, we need to send another parameter in the measurement protocol request, which is session_id. Another parameter that we can send is session_number, but this parameter has no real impact on the correct channel assignment.

Unfortunately, at the time of writing, Google’s documentation on the Measurement Protocol does not mention this fact.

How to obtain session id

The question is where to obtain session_id and session_number. There are two possibilities:

The cookie where session_id is stored is named _ga_[streamID].

Session id is the first number after GS1.1. – “1678392614”. Session_number is number “19” in the string.

In gtag, you can then get the values via the get session_id or session_name command.

The second method is a bit more accurate in practice, as some session_id values may appear irrelevant in the cookie when picked up at the wrong time. On the other hand, gtag is an asynchronous process and may not be fast enough when used, for example, in GTM, so it is a good idea to use a combination of methods for verification.

Request to GA4

In the end, the request to Google Analytics might look like this:

Do not forget on timestamp_micros parameter if the event is sent with the delay.

Jsme tu nachystaní

Řekněte si
o kvalitní pomoc

Hledáte cestu?

My ji známe
a doprovodíme vás

Zamrzli jste?

Pojďte to rozhýbat

Dochází vám dech?

Nekdy je třeba
prostě zpomalit...