Skip to content

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

Terminal window
go get github.com/vortex-analytics-io/go-sdk

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()
}
ParameterTypeDescription
tenantIdstringYour project identifier from the Vortex dashboard
serverUrlstringServer endpoint, e.g. https://in.vortexanalytics.io
platformstringPlatform string, e.g. my_backend_service, cli_app
appVersionstringYour application version
autoBatchingboolQueue events and flush on an interval
flushIntervalSecintFlush interval in seconds
  1. Loads or generates a persistent device identifier (stored locally)
  2. Creates a new session ID
  3. Starts a background task to validate the tenant and check server health
  4. Enables or disables analytics based on server availability

If the server is unreachable, events are safely queued until connectivity is restored.


vortex.TrackEvent("app_started")
vortex.TrackEvent("user_logged_in", "admin_user")
vortex.TrackEvent("order_completed", map[string]any{
"order_id": 12345,
"total_amount": 99.99,
"currency": "USD",
"items_count": 3,
})

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 events
vortex.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 request
vortex.FlushManualBatch()

Enable autoBatching in Init():

vortex.Init(tenantId, serverUrl, platform, appVersion, true, 10)
  • TrackEvent calls are queued automatically
  • The queue flushes every flushIntervalSec seconds
  • If the server is unreachable, events stay queued until connectivity is restored

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 events
vortex.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 data
vortex.SetCustomData(nil)
  • Empty custom data is not included in request payloads
  • Only valid JSON data is accepted; invalid data is logged as an error

Always call Shutdown() when your application exits to ensure buffered events are flushed.

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!")
}
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()
}