Martin Ueding
Martin Ueding

Reputation: 8699

Google Analytics 4 Measurement Protocol shows events but no users

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?

Upvotes: 11

Views: 3728

Answers (2)

Mike
Mike

Reputation: 496

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.

Upvotes: 24

Anton Trofymenko
Anton Trofymenko

Reputation: 34

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>

Upvotes: -2

Related Questions