The issue you’re experiencing seems to be stemming from the fact that you’re using the Measurement Protocol (Universal Analytics) to send hits to a Universal Analytics (UA) account. This is only designed to work with UA.
When you want to send hits to a GA4 (Google Analytics 4) account, a different system called Measurement Protocol (Google Analytics 4) is used, and it also has a different endpoint.
Here’s how you set up an endpoint for a GA4:
`
POST /mp/collect HTTP/1.1
HOST: http://www.google-analytics.com
Content-Type: application/json
`
Another important thing to remember is that GA4 is quite different from UA. When switching to GA5, you’ll have to modify the format of your hits and convert them into events. Here’s an example of how an event payload looks like:
`
{
“client_id”: “x”,
“events”: [
{
“name”: “offline_purchase”,
“params”: {
“engagement_time_msec”: “100”,
“session_id”: “123”
}
}
]
}
`
While transitioning, keep in mind that the measurement protocol for GA4 is somewhat limited. You might not be able to send all the hits you want, as many of them are restricted for use by Google’s internal SDKs. If you want a clear picture of what you can send, take a look at the event-builder on the Google Analytics Developer Tools site.