From 8dbfdf9424904ffea899b5587254157d6d4478a6 Mon Sep 17 00:00:00 2001 From: Michael Valdron Date: Fri, 13 Jan 2023 14:29:28 -0500 Subject: [PATCH] starter project telemetry event tracking source added to registry server. Signed-off-by: Michael Valdron --- index/server/pkg/server/endpoint.go | 20 ++++++++++++++++++++ index/server/pkg/server/index.go | 7 ++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index 0457e120..092c2a81 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -305,6 +305,26 @@ func serveDevfileStarterProjectWithVersion(c *gin.Context) { return } + // Track event for telemetry. Ignore events from the registry-viewer and DevConsole since those are tracked on the client side. Ignore indirect calls from clients. + if enableTelemetry && !util.IsWebClient(c) && !util.IsIndirectCall(c) { + + user := util.GetUser(c) + client := util.GetClient(c) + + err := util.TrackEvent(analytics.Track{ + Event: eventTrackMap["spdownload"], + UserId: user, + Context: util.SetContext(c), + Properties: analytics.NewProperties(). + Set("devfile", devfileName). + Set("starterProject", starterProjectName). + Set("client", client), + }) + if err != nil { + log.Println(err) + } + } + c.Header("Content-Disposition", fmt.Sprintf("attachment; filename=\"%s.zip\"", starterProjectName)) c.Data(http.StatusAccepted, starterProjectMediaType, downloadBytes) } diff --git a/index/server/pkg/server/index.go b/index/server/pkg/server/index.go index 94a98bd0..095a7f13 100644 --- a/index/server/pkg/server/index.go +++ b/index/server/pkg/server/index.go @@ -41,9 +41,10 @@ import ( ) var eventTrackMap = map[string]string{ - "list": "list devfile", - "view": "view devfile", - "download": "download devfile", + "list": "list devfile", + "view": "view devfile", + "download": "download devfile", + "spdownload": "Starter Project Downloaded", } var mediaTypeMapping = map[string]string{