Hi everyone, We're seeing a `analytics.Track.User...
# support
s
Hi everyone, We're seeing a
analytics.Track.UserId: invalid field value: ""
error from the RudderStack Go SDK v4. The documentation at https://www.rudderstack.com/docs/sources/event-streams/sdks/rudderstack-go-sdk/#track says that for the Track event, userId is required if anonymousId is absent, and vice versa, but it also says that the SDK automatically sets anonymousId "where there is no unique identifier for the user" (I assume this means the userId?). So we don't understand this error message. If userId is
""
, then shouldn't the SDK be setting anonymousId for us?
m
Hey There! 👋 Your message has been received by the RudderStack team. Our standard customer support hours are 9-6 PM EST, but we will forward this request to your Technical Account Manager, and they will get back to you shortly. Please use the thread for any additional comments.
h
@stocky-vr-69425, You should not send the userId in that case.
s
@high-zoo-17436 We don't, it's empty, but we're getting an error saying that it's empty.
h
are you sending anonymousId?
Can you share your implementation for track?
m
Hi Will, so the there are 2 types of SDKs here 1. Client Side SDK (JS, Android, iOS, React Native) 2. Server Side SDK (Java, Python, Ruby, NodeJS, Go etc) For both SDKs either the anonymousId or userId are mandatory. For client-side SDKs the code automatically adds an anonymousId, but for server-side SDKs we do not automatically add an anonymous id (Since the event is being generated from your server, the idea is that the user is known to you). Hence, if you want to send a server-side event and you don't know the userId. you have to add the anonymousId before sending the event.
s
No, we don't send AnonymousId, because we thought the SDK would set it for us if UserId is unset.
Our code:
Copy code
rs := analytics.New(...)
defer func() {
	if err := rs.Close(); err != nil {
		log.Printf("cannot close rudderstack client: %v", err)
	}
}()
var userID string
if user := ...; user != nil {
	userID = strconv.Itoa(user.ID)
}
track := analytics.Track{
	UserId:      userID,
	Event:       "...",
	Properties: analytics.Properties{
		...
	},
}
if err := rs.Enqueue(track); err != nil {
	log.Printf("cannot send rudderstack event %#v: %v", track, err)
}
OK, we will set AnonymousId ourselves. Thanks for the clarification.
Please consider updating the documentation on that page to make that clear.
h
Sure