Go SDK
The Vortex Analytics Go SDK is a lightweight, production-ready library for sending analytics events to the Vortex platform from any Go application.
GitHub: Vortex-Analytics-IO/Go-SDK
Supported features:
- Immediate and batched event tracking
- Automatic retry when the server becomes available
- Persistent device and session identification
- Verbose logging for debugging
- Thread-safe queue management
Installation
Section titled “Installation”go get github.com/vortex-analytics-io/go-sdkInitialization
Section titled “Initialization”package main
import ( "time" analytics "github.com/vortex-analytics-io/go-sdk")
func main() { vortex := analytics.Instance()
// Optional: see network requests in stdout vortex.SetVerbose(true)
vortex.Init( "481b9cfb-4b48-4d99-a310-d383c6cc5d3b", // Tenant ID "https://in.vortexanalytics.io", // Server URL "my_backend_service", // Platform "1.0.0", // App version true, // Auto-batching enabled 2, // Flush every 2 seconds )
// Give the background initialization a moment to complete time.Sleep(1 * time.Second)
// ... your app logic ...
vortex.Shutdown()}Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
tenantId | string | Your project identifier from the Vortex dashboard |
serverUrl | string | Server endpoint, e.g. https://in.vortexanalytics.io |
platform | string | Platform string, e.g. my_backend_service, cli_app |
appVersion | string | Your application version |
autoBatching | bool | Queue events and flush on an interval |
flushIntervalSec | int | Flush interval in seconds |
What happens on initialization
Section titled “What happens on initialization”- Loads or generates a persistent device identifier (stored locally)
- Creates a new session ID
- Starts a background task to validate the tenant and check server health
- Enables or disables analytics based on server availability
If the server is unreachable, events are safely queued until connectivity is restored.
Tracking events
Section titled “Tracking events”Simple event
Section titled “Simple event”vortex.TrackEvent("app_started")Event with string payload
Section titled “Event with string payload”vortex.TrackEvent("user_logged_in", "admin_user")Event with structured data
Section titled “Event with structured data”vortex.TrackEvent("order_completed", map[string]any{ "order_id": 12345, "total_amount": 99.99, "currency": "USD", "items_count": 3,})Batching
Section titled “Batching”Manual batching
Section titled “Manual batching”Use manual batching when you want explicit control over when events are sent (e.g. at the end of a transaction or API request).
// Queue eventsvortex.BatchedTrackEvent("transaction_started", "checkout")vortex.BatchedTrackEvent("payment_processed", map[string]any{ "amount": 49.99, "method": "credit_card", "status": "success",})
// Send all queued events in a single HTTP requestvortex.FlushManualBatch()Automatic batching
Section titled “Automatic batching”Enable autoBatching in Init():
vortex.Init(tenantId, serverUrl, platform, appVersion, true, 10)TrackEventcalls are queued automatically- The queue flushes every
flushIntervalSecseconds - If the server is unreachable, events stay queued until connectivity is restored
Custom data
Section titled “Custom data”Attach persistent metadata to every event the SDK sends — useful for user context, environment details, or any session-level information.
// Set custom data — included in all subsequent eventsvortex.SetCustomData(map[string]any{ "user_id": "user_123", "subscription": "premium", "environment": "production", "region": "us-east-1",})
vortex.TrackEvent("feature_used", "dark_mode_toggle")
// Remove custom datavortex.SetCustomData(nil)- Empty custom data is not included in request payloads
- Only valid JSON data is accepted; invalid data is logged as an error
Lifecycle handling
Section titled “Lifecycle handling”Always call Shutdown() when your application exits to ensure buffered events are flushed.
CLI / console app
Section titled “CLI / console app”package main
import ( "fmt" analytics "github.com/vortex-analytics-io/go-sdk")
func main() { vortex := analytics.Instance() vortex.Init("tenant-id", "https://in.vortexanalytics.io", "cli_app", "1.0.0", true, 5)
vortex.TrackEvent("app_started")
// ... application logic ...
vortex.TrackEvent("app_completed")
fmt.Println("Shutting down...") vortex.Shutdown() fmt.Println("Done!")}Web service — graceful shutdown
Section titled “Web service — graceful shutdown”import ( "context" "net/http" "os/signal" "syscall" analytics "github.com/vortex-analytics-io/go-sdk")
func main() { vortex := analytics.Instance() vortex.Init("tenant-id", "https://in.vortexanalytics.io", "web_service", "1.0.0", true, 5)
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM) defer stop()
server := &http.Server{Addr: ":8080"} go server.ListenAndServe()
<-ctx.Done() server.Shutdown(context.Background()) vortex.Shutdown()}