Search code examples
google-analyticsgoogle-analytics-4measurement-protocol

What should be "session_id" value GA4 via MP


What should be "session_id" value GA4 via MP in event params when I send GA4 event via MP (POST request)?

{
"client_id": "x",
"events": [
  {
    "name": "click_premium",
    "params": {
      "engagement_time_msec": "1",
      "session_id": "???" // what should be here? Random or calculated value ?
    }
  }
]
}

And I can't get it from gtag, because I send GA from chrome extension and can't insert gtag script to document.

I don't get it and documentation doesn't really helps me


Solution

  • You will need to either extract session_id from the GA4 cookie or generate it yourself.

    If you decide to generate it, you can base it on a set of values such as IP address (anonymized by removing last octet!), browser user agent, day, hour, minute (or block of minutes, e.g. 0-29 and 30-59), it really depends on your session definition.