diff --git a/server/flow.go b/server/flow.go index c0845b9b..060c9909 100644 --- a/server/flow.go +++ b/server/flow.go @@ -9,13 +9,17 @@ import ( "github.com/gorilla/mux" pluginapi "github.com/mattermost/mattermost-plugin-api" "github.com/mattermost/mattermost-plugin-api/experimental/flow" - "github.com/mattermost/mattermost-plugin-api/experimental/telemetry" "github.com/mattermost/mattermost-server/v6/model" "github.com/pkg/errors" "github.com/mattermost/mattermost-plugin-gitlab/server/gitlab" ) +type Tracker interface { + TrackEvent(event string, properties map[string]interface{}) + TrackUserEvent(event, userID string, properties map[string]interface{}) +} + type FlowManager struct { client *pluginapi.Client pluginURL string @@ -25,7 +29,7 @@ type FlowManager struct { getGitlabUserInfoByMattermostID func(userID string) (*gitlab.UserInfo, *APIErrorResponse) getGitlabClient func() gitlab.Gitlab - tracker telemetry.Tracker + tracker Tracker setupFlow *flow.Flow oauthFlow *flow.Flow @@ -43,7 +47,7 @@ func (p *Plugin) NewFlowManager() *FlowManager { getGitlabUserInfoByMattermostID: p.getGitlabUserInfoByMattermostID, getGitlabClient: p.getGitlabClient, - tracker: p.tracker, + tracker: p, } fm.setupFlow = fm.newFlow("setup").WithSteps( @@ -216,14 +220,14 @@ func (fm *FlowManager) StartSetupWizard(userID string, delegatedFrom string) err } func (fm *FlowManager) trackStartSetupWizard(userID string, fromInvite bool) { - _ = fm.tracker.TrackUserEvent("setup_wizard_start", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("setup_wizard_start", userID, map[string]interface{}{ "from_invite": fromInvite, "time": model.GetMillis(), }) } func (fm *FlowManager) trackCompleteSetupWizard(userID string) { - _ = fm.tracker.TrackUserEvent("setup_wizard_complete", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("setup_wizard_complete", userID, map[string]interface{}{ "time": model.GetMillis(), }) } @@ -242,13 +246,13 @@ func (fm *FlowManager) StartOauthWizard(userID string) error { } func (fm *FlowManager) trackStartOauthWizard(userID string) { - _ = fm.tracker.TrackUserEvent("oauth_wizard_start", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("oauth_wizard_start", userID, map[string]interface{}{ "time": model.GetMillis(), }) } func (fm *FlowManager) trackCompleteOauthWizard(userID string) { - _ = fm.tracker.TrackUserEvent("oauth_wizard_complete", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("oauth_wizard_complete", userID, map[string]interface{}{ "time": model.GetMillis(), }) } @@ -564,13 +568,13 @@ func (fm *FlowManager) StartWebhookWizard(userID string) error { } func (fm *FlowManager) trackStartWebhookWizard(userID string) { - _ = fm.tracker.TrackUserEvent("webhook_wizard_start", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("webhook_wizard_start", userID, map[string]interface{}{ "time": model.GetMillis(), }) } func (fm *FlowManager) trackCompleteWebhookWizard(userID string) { - _ = fm.tracker.TrackUserEvent("webhook_wizard_complete", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("webhook_wizard_complete", userID, map[string]interface{}{ "time": model.GetMillis(), }) } @@ -715,13 +719,13 @@ func (fm *FlowManager) StartAnnouncementWizard(userID string) error { } func (fm *FlowManager) trackStartAnnouncementWizard(userID string) { - _ = fm.tracker.TrackUserEvent("announcement_wizard_start", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("announcement_wizard_start", userID, map[string]interface{}{ "time": model.GetMillis(), }) } func (fm *FlowManager) trackCompletAnnouncementWizard(userID string) { - _ = fm.tracker.TrackUserEvent("announcement_wizard_complete", userID, map[string]interface{}{ + fm.tracker.TrackUserEvent("announcement_wizard_complete", userID, map[string]interface{}{ "time": model.GetMillis(), }) } diff --git a/server/telemetry.go b/server/telemetry.go index 8f98b913..fb6f2db0 100644 --- a/server/telemetry.go +++ b/server/telemetry.go @@ -11,6 +11,20 @@ const ( keysPerPage = 1000 ) +func (p *Plugin) TrackEvent(event string, properties map[string]interface{}) { + err := p.tracker.TrackEvent(event, properties) + if err != nil { + p.API.LogDebug("Error sending telemetry event", "event", event, "error", err.Error()) + } +} + +func (p *Plugin) TrackUserEvent(event, userID string, properties map[string]interface{}) { + err := p.tracker.TrackUserEvent(event, userID, properties) + if err != nil { + p.API.LogDebug("Error sending user telemetry event", "event", event, "error", err.Error()) + } +} + func (p *Plugin) SendDailyTelemetry() { config := p.getConfiguration() @@ -19,7 +33,7 @@ func (p *Plugin) SendDailyTelemetry() { p.API.LogWarn("Failed to get the number of connected users for telemetry", "error", err) } - _ = p.tracker.TrackEvent("stats", map[string]interface{}{ + p.TrackEvent("stats", map[string]interface{}{ "connected_user_count": connectedUserCount, "is_oauth_configured": config.IsOAuthConfigured(), "is_sass": config.IsSASS(),