13. 3. 2023

Measurement protocol and sessions in GA4

First-party data activation

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.

Využijte sílu*
marketingových dat k optimálnímu prodeji

Other interesting articles

Server-side GTM for Mobile Apps:

Server-side GTM for Mobile Apps:

Customer Success Manager / Consultant for Digital analytics & advertising

Customer Success Manager / Consultant for Digital analytics & advertising

R&D Lead - Cloud for marketing

R&D Lead - Cloud for marketing

Get in touch

Interested to find out the real potential* of your data?

Drop us your contact details and we will
get back to you shortly.

By sending a message you agree with our Privacy Policy and GDPR.