amplitude / analytics-go

Go Amplitude Analytics SDK
MIT License
12 stars 7 forks source link

Missing required field: events #35

Open moubry opened 2 years ago

moubry commented 2 years ago

I'm trying to implement a simple Hello World and am getting an error saying I'm missing the events field.

Code:

ampConfig := amplitude.NewConfig(os.Getenv("AMPLITUDE_API_KEY"))
ampConfig.FlushInterval = 1 * time.Second
amp := amplitude.NewClient(ampConfig)
amp.Track(amplitude.Event{
    EventType:    "Button Clicked 2",
    EventOptions: amplitude.EventOptions{UserID: "test_user"},
})
amp.Flush()

Logs (with some custom logging):

[00] amplitude-analytics2022/09/08 09:55:25 Debug: Message received from messageChannel: %!(EXTRA amplitude.message={0x1400001c240 <nil>}, *amplitude.Event=&{Button Clicked 2 {test_user  1662648925051 2f60c081-e49b-4601-b91a-a9578dbc1faa amplitude-go/0.0.2 0 0                    0 0 0   0 0  {}} map[] map[] map[] map[]})
[00] amplitude-analytics2022/09/08 09:55:25 Debug: Message received from messageChannel: %!(EXTRA amplitude.message={<nil> 0x140001ceea0}, *amplitude.Event=<nil>)
[00] amplitude-analytics2022/09/08 09:55:25 Debug: Sending event(s) to Amplitude: %!(EXTRA string={"api_key":"19c9...","Events":[{"event_type":"Button Clicked 2","user_id":"test_user","time":1662648925051,"insert_id":"2f60c081-e49b-4601-b91a-a9578dbc1faa","library":"amplitude-go/0.0.2","plan":{}}]})
[00] amplitude-analytics2022/09/08 09:55:25 Error: HTTP request failed with 400 status%!(EXTRA string={"missing_field":"events","code":400,"error":"Request missing required field"}

The request clearly has an Events field. I’m not sure what I’m doing wrong here.

falconandy commented 2 years ago

Hi @moubry Could you please try version v0.0.3? The code snippet works for me.