Google Analytics 4 Measurement Protocol shows events but no users
Asked Answered
F

2

11

I would like to use Google Analytics from a script (using explicit HTTP requests) and understand that Google Analytics 4 with the Measurement Protocol would be the way to go. I have created a new Property, added a Web tag and created an API key for the Measurement Protocol there. Then I send this request:

{
    "client_id": "Test-User",
    "user_id": "test_user_id",
    "events": [
        {
            "name": "MyEvent",
            "params": {}
        }
    ]
}

To this URL: https://www.google-analytics.com/mp/collect?measurement_id=G-LQDLGRLGZS&api_secret=JXGZ_CyvTt29ucNi9y0DkA

The measurement gets logged there in a corner of the report:

enter image description here

These events don't show up as users. And in reports I don't quite see how to analyze these events. Is there some way to track user sessions by sending special events?

Fennelly answered 14/1, 2022 at 10:4 Comment(4)
Could you paste the request that you crafted please ?Possible
@lkostka: Sure, I've updated the question.Fennelly
@MartinUeding , did you by any chance managed to fix this? I have the same issue right now and looking for a solution.Gunas
@user7607751: No, unfortunately not. I've then tried to play around with sentry.io, but eventually dropped the idea of telemetry altogether.Fennelly
S
24

I had the same problem and the answer is here GA4 Measurement Protocol returns events not the users Under the events branch of the JSON, when I added "engagement_time_msec" : 1 the users started to be counted.

"events" : [{
  "name" : "SoftMeter_event",
  "params" : {
    "action" : "From UA-xxxxx [muted]",
    "engagement_time_msec" : 1,
    "label" : "SoftMeter-dev/v1.0.2/lib v1.4.4 DEBUG"
  }
}],

The Measurement Protocol V4 is for GA4 properties(which is also the one you are using).

According to the official document: https://support.google.com/analytics/answer/9408920 It says "Google Analytics 4 properties counts users who engaged with your app/site for any non-zero amount of time during the previous 30 minutes".

GA4 uses "engagement_time_msec" parameter to identify user interaction time. This explains why you can see the number of events but not the number of users. If you want users sent from MP to be counted as active user, simply add the "engagement_time_msec" parameter to your event.

Spoor answered 9/4, 2022 at 19:38 Comment(1)
This was my issue as well. Wish there was a good reference for all this stuff.Caber
R
-2

client_id is wrong. This id is set by google, so you should get your real id. You can get it from your cookies for testing. Or, if you use gtag.js you can add this code to your web page.

<script>
    gtag('get', <yourMeasurementID>, 'client_id', (clientID) => {
        // here you can use clientID
    });
</script>
Raynell answered 19/1, 2022 at 18:14 Comment(1)
Which means that I cannot just track within my App, I need to have a web session in order to get a cookie?Fennelly

© 2022 - 2024 — McMap. All rights reserved.