diff --git a/internal/handlers/telemetry.go b/internal/handlers/telemetry.go index 1e52f586f..78610ce76 100644 --- a/internal/handlers/telemetry.go +++ b/internal/handlers/telemetry.go @@ -20,7 +20,13 @@ func NewTelemetryHandler(service services.SegmentIoService) TelemetryHandler { // SendCountMetric validate and handles the metric request to the metric service. func (handler TelemetryHandler) SendCountMetric(telemetry domain.Telemetry) error { - err := handler.service.EnqueueCountMetric( + // the library handles it, and will call Identify once per command + err := handler.service.EnqueueIdentify(telemetry.Domain) + if err != nil { + return err + } + + err = handler.service.EnqueueCountMetric( telemetry.MetricName, telemetry.Domain, telemetry.CLIVersion, diff --git a/internal/services/segment-io.go b/internal/services/segment-io.go index 27e357803..8079b6860 100644 --- a/internal/services/segment-io.go +++ b/internal/services/segment-io.go @@ -33,3 +33,18 @@ func (service SegmentIoService) EnqueueCountMetric(metricName string, domain str return nil } + +// EnqueueIdentify implements SegmentIO Identify https://segment.com/docs/connections/sources/catalog/libraries/server/go/ +func (service SegmentIoService) EnqueueIdentify(domain string) error { + + // Enqueues a Identify event that will be sent asynchronously. + err := service.SegmentIOClient.Enqueue(analytics.Identify{ + UserId: domain, + Type: "identify", + }) + if err != nil { + return err + } + + return nil +}