Learn business growth with Google Analytics 4 Forums Google Analytics 4 Effective methods for including session_id when sending events to GA4 through Measurement protocol

  • Effective methods for including session_id when sending events to GA4 through Measurement protocol

    Posted by Avery on 22 August 2022 at 8:26 am

    Hey folks, here’s the scoop: when sending GA4 purchase events from the client server via the measurement protocol, we’re hitting a snag. We’re missing a session_id parameter in the queries and as a result, our source and medium info goes MIA. We tried to throw the session_id parameter into the MP request, but ended up catching zero, zilch, nada.

    Here’s what we’ve been tossing over the net:

    {
     "timestamp_micros": "1664522406546590",
     "non_personalized_ads": false,
     "events": [
      {
       "name": "purchase_balance_top_up",
       "params": {
        "user_id": "11111111",
        "crm_id": "11111111",
        "balance": 990,
        "payment_method": "paymore"
       }
      }
     ],
     "client_id": "1119492379.1652295143",
     "session_id": "1664522264",
     "user_id": "11111111"
    }
    

    Catch a glimpse of the raw data direct from BigQuery about events sent by the MP.
    Peep the BigQuery snapshot

    Seeking some wisdom here, how do we deliver the session_id like a champ? Or how do we ensure our events don’t drop the source param ball?

    Henry replied 12 months ago 3 Members · 2 Replies
  • 2 Replies
  • Skyler

    Member
    12 March 2023 at 9:25 pm

    Hey, no sweat. We’ve got the fix you need. You just need to put the “session_id” inside the “params” array in the event.

    Like in this example. It shows you just how your measurement protocol event data should look:

    {
     "timestamp_micros": "1664522406546590",
     "non_personalized_ads": false,
     "events": [
      {
       "name": "purchase_balance_top_up",
       "params": {
        "user_id": "11111111",
        "crm_id": "11111111",
        "balance": 990,
        "payment_method": "paymore",
        "session_id": "1664522264"
       }
      }
     ],
     "client_id": "1119492379.1652295143",
     "user_id": "11111111"
    }
    

    There you go, problem solved. Keep slinging those APIs!

  • Henry

    Member
    28 June 2023 at 12:11 am

    In simple terms, these individuals are encountering some trouble when trying to send purchase events from their client’s server using a certain protocol. The issue is that a crucial ‘session_id’ parameter is missing, which causes other important information about source and medium to be lost. This has remained a problem even after trying to include the ‘session_id’ parameter in the request. They have shared the specific code they have been using
    to try and resolve this problem. They are seeking advice on how to correctly include the ‘session_id’, or alternatively, how to ensure their events maintain all the necessary information. The solution involves adjusting the way they are sending the purchase event, being careful to include all necessary info and parameters, and doing away with some unnecessary ones.

Log in to reply.