diff --git a/index/server/pkg/server/endpoint.go b/index/server/pkg/server/endpoint.go index 0457e120..b93eb3d0 100644 --- a/index/server/pkg/server/endpoint.go +++ b/index/server/pkg/server/endpoint.go @@ -1,5 +1,5 @@ // -// Copyright 2022 Red Hat, Inc. +// Copyright 2022-2023 Red Hat, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -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..d8e68a7f 100644 --- a/index/server/pkg/server/index.go +++ b/index/server/pkg/server/index.go @@ -1,5 +1,5 @@ // -// Copyright 2022 Red Hat, Inc. +// Copyright 2022-2023 Red Hat, Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -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{