Best Practices
Follow these guidelines to ensure reliability, performance, and maintainability when using the Conviso Go SDK.
Initialization
Do initialize the client once at the start of your application and pass it to your handlers or services. Don't create a new client for every request.
// Good
var cdpClient *cdp.Client
func main() {
cdpClient = cdp.NewClient(config)
}
// Bad
func handleRequest() {
client := cdp.NewClient(config) // Creates new connection pool every time!
client.Identify(...)
client.Close()
}
Identifier Consistency
Always use consistent user IDs across your stack. If you use a database ID (e.g., 507f1f77bcf86cd799439011), use that same string everywhere.
Context Usage
The SDK methods all accept a context.Context. Always pass a valid context.
- Use
context.Background()for background tasks. - Pass the request context (
r.Context()) in HTTP handlers to propagate cancellations.
func handleUserSignup(w http.ResponseWriter, r *http.Request) {
// ...
// If the user cancels the request, the CDP call will also be cancelled/aborted if possible
client.Identify(r.Context(), userID, traits)
}
Error Handling
By default, FailOnException is false. This means the SDK tries its best but won't return an error for network glitches if it can handle them, or it might just log them.
For critical data paths (like signup), we recommend setting FailOnException: true so you can handle failures explicitly (e.g., retry or show an error to the user).
config := cdp.CDPConfig{
// ...
FailOnException: true,
}
Person Attributes
Use standard naming for common traits. Conviso is optimized for these keys:
firstNamelastNameemailphone
Using these keys ensures that they map correctly to the user's main profile fields in the dashboard.