jkmarathoner
jkmarathoner

Reputation: 89

Sending server-side events to GA4 using API

I've been using Google's documentation to attempt to build/test server-side events for GA4 using Postman. I've found the event to work when using their event builder (I see the event in real-time events), but when I transfer it to Postman, it doesn't work (does not show in real-time events). I keep receiving a 403 Forbidden message. I'm 100% sure I have it set up correctly, but I'm not sure if there's some sort of setting in Google to allow requests from a server instead of a browser (I'm using an out-of-the-box implementation of a GA4 data stream). I've tried sending a User-Agent from my browser in the header and that doesn't seem to make a difference. I'm sending the following:

METHOD:

POST

URL:

www.google-analytics.com/mp/collect?measurement_id=<<MY ID IS HERE>>&api_secret=<<MY API SECRET HERE>>

BODY (RAW TEXT):

{
  "clientId": "783221853.1614059609",
  "events": [{
    "name": "add_to_cart",
    "params": {
            "items": [{
                "item_id": "Robot Toy",
                "item_name": "12345678"
            }]
        }
    }]
}

HEADERS:

Content-Type: Text/Plain
Content-Length: 1
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.192 Safari/537.36

Any ideas on what I might be doing wrong, or if it is an issue with Google and the fact that GA4 is still buggy? Or maybe it thinks I'm a bot and has blocked the traffic?

Upvotes: 4

Views: 5586

Answers (2)

Shoe
Shoe

Reputation: 51

We had the same 403 error and discovered that https:// was missing in front of the URL and the request was denied because of using http only.

Upvotes: 3

Maksim Bogan
Maksim Bogan

Reputation: 11

Body is correct. But if you send json body you should have:

headers = {
          "Content-Type": "application/json"
          }

Upvotes: 0

Related Questions