Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add telemetry for the download-starter-project endpoint to registry server #157

Merged
merged 2 commits into from
Jan 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion index/server/pkg/server/endpoint.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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)
michael-valdron marked this conversation as resolved.
Show resolved Hide resolved

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)
}
Expand Down
9 changes: 5 additions & 4 deletions index/server/pkg/server/index.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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{
Expand Down