Skip to content

Commit

Permalink
Implement segmentio identify (#743)
Browse files Browse the repository at this point in the history
* feat: implement segmentio identify

* docs: update in code documentation for segmentio identify

Signed-off-by: João Vanzuita <joao@kubeshop.io>
  • Loading branch information
João Paulo Vanzuita authored Dec 13, 2022
1 parent a2d1906 commit 16fb64c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion internal/handlers/telemetry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 15 additions & 0 deletions internal/services/segment-io.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 16fb64c

Please sign in to comment.