5

I tried to send event to Google Analytics 4 using the postman. enter image description here

And GA4 just response 204 No Content and the event is not recorded in the data stream. I checked the measurement_id and api_secret has right value. Is there anything wrong?

Thank you.

CicadaKim
  • 73
  • 1
  • 7

3 Answers3

1

I encountered this issue today.

For me personally, it turns out I was looking for my received data in the wrong place: I was looking in Admin > Data Streams, which incorrectly told me "No data received in past 48 hours."

Where I actually needed to look was in the "Realtime Overview" (Reports > Realtime - see picture): Reports > Realtime in the Google Analytics UI

In there, there was a handy little event counter that showed me my events were, in fact, getting through just fine.

Image of the Google Analytics UI event counter

If you check here and it's still zero, here are some other things to try:

  1. You may need to set the Content-Type header to "application/json".

  2. Validate your events by sending them to the endpoint https://www.google-analytics.com/**debug**/mp/collect rather than https://www.google-analytics.com/**debug**/mp/collect - as long as you get "validationMessages": [] back, you should be good to go.

  3. Make sure the JSON you're sending matches this format

  4. According to the folks over at this similar StackOverflow question, You may need to set the User-Agent header, though I personally did not have to.

Christian May
  • 127
  • 11
0

In my case, I try to use GA4 measurement protocol inside the Google Script. It took me quite a while to figure out.

In fact, the GA4 events are already created, only the users report is always empty. But I have to scroll down to see the events in the real time report.

And the reason the users are not showing, as well as the solution is mentioned in this post: Google Analytics 4 Measurement Protocol shows events but no users

Basically, one needs to put the engagement_time_msec inside the event params, in order for the user to show up in the real time report.

Walty Yeung
  • 3,396
  • 32
  • 33
-1

The object should be payload, not body.

Try to see this video: https://youtu.be/WSxdrG1G_yE

Michele Pisani
  • 13,567
  • 3
  • 25
  • 42
  • Not true, see the example in Google's docs here: https://developers.google.com/analytics/devguides/collection/protocol/ga4/sending-events?client_type=gtag#send_an_event. – Terrabythia Jan 23 '23 at 15:56
  • Yes. When using `fetch` the property `payload` does not exist. It should be `body` which should contain a string (in this case a JSON encoded object). – Terrabythia Jan 24 '23 at 10:34
  • Try to see the video too – Michele Pisani Jan 24 '23 at 11:23
  • Yes, I have. See the video at time 1:19. When using fetch (or postman) the body should be appended using `body`. His example uses the Event Builder in the Google Analytics UI. That implementation could be different from the JavaScript `fetch` method (all though I doubt it), but that isn't the case for JavaScript. – Terrabythia Jan 24 '23 at 14:25