Skip to content

Commit

Permalink
web/satellite, satellite/analytics: add UI type to analytics properties
Browse files Browse the repository at this point in the history
This change incorporates the UI type (legacy or Vuetify) in the
properties attached to analytics events originating from the satellite
UI.

Resolves #6363

Change-Id: Ie3627bc24e4349407376e28460a5a830d211b47b
  • Loading branch information
jewharton authored and Storj Robot committed Oct 13, 2023
1 parent c9421d1 commit ad13cb2
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 7 deletions.
9 changes: 6 additions & 3 deletions satellite/analytics/service.go
Expand Up @@ -526,7 +526,7 @@ func (service *Service) TrackAccountVerified(userID uuid.UUID, email string) {

// TrackEvent sends an arbitrary event associated with user ID to Segment.
// It is used for tracking occurrences of client-side events.
func (service *Service) TrackEvent(eventName string, userID uuid.UUID, email string, customProps map[string]string) {
func (service *Service) TrackEvent(eventName string, userID uuid.UUID, email, uiType string, customProps map[string]string) {
if !service.config.Enabled {
return
}
Expand All @@ -539,6 +539,7 @@ func (service *Service) TrackEvent(eventName string, userID uuid.UUID, email str

props := segment.NewProperties()
props.Set("email", email)
props.Set("ui_type", uiType)

for key, value := range customProps {
props.Set(key, value)
Expand All @@ -553,14 +554,15 @@ func (service *Service) TrackEvent(eventName string, userID uuid.UUID, email str

// TrackErrorEvent sends an arbitrary error event associated with user ID to Segment.
// It is used for tracking occurrences of client-side errors.
func (service *Service) TrackErrorEvent(userID uuid.UUID, email string, source string) {
func (service *Service) TrackErrorEvent(userID uuid.UUID, email, source, uiType string) {
if !service.config.Enabled {
return
}

props := segment.NewProperties()
props.Set("email", email)
props.Set("source", source)
props.Set("ui_type", uiType)

service.enqueueMessage(segment.Track{
UserId: userID.String(),
Expand All @@ -571,7 +573,7 @@ func (service *Service) TrackErrorEvent(userID uuid.UUID, email string, source s

// TrackLinkEvent sends an arbitrary event and link associated with user ID to Segment.
// It is used for tracking occurrences of client-side events.
func (service *Service) TrackLinkEvent(eventName string, userID uuid.UUID, email, link string) {
func (service *Service) TrackLinkEvent(eventName string, userID uuid.UUID, email, link, uiType string) {
if !service.config.Enabled {
return
}
Expand All @@ -585,6 +587,7 @@ func (service *Service) TrackLinkEvent(eventName string, userID uuid.UUID, email
props := segment.NewProperties()
props.Set("link", link)
props.Set("email", email)
props.Set("ui_type", uiType)

service.enqueueMessage(segment.Track{
UserId: userID.String(),
Expand Down
7 changes: 4 additions & 3 deletions satellite/console/consoleweb/consoleapi/analytics.go
Expand Up @@ -40,6 +40,7 @@ type eventTriggeredBody struct {
EventName string `json:"eventName"`
Link string `json:"link"`
ErrorEventSource string `json:"errorEventSource"`
UIType string `json:"uiType"`
Props map[string]string `json:"props"`
}

Expand Down Expand Up @@ -70,11 +71,11 @@ func (a *Analytics) EventTriggered(w http.ResponseWriter, r *http.Request) {
}

if et.ErrorEventSource != "" {
a.analytics.TrackErrorEvent(user.ID, user.Email, et.ErrorEventSource)
a.analytics.TrackErrorEvent(user.ID, user.Email, et.ErrorEventSource, et.UIType)
} else if et.Link != "" {
a.analytics.TrackLinkEvent(et.EventName, user.ID, user.Email, et.Link)
a.analytics.TrackLinkEvent(et.EventName, user.ID, user.Email, et.Link, et.UIType)
} else {
a.analytics.TrackEvent(et.EventName, user.ID, user.Email, et.Props)
a.analytics.TrackEvent(et.EventName, user.ID, user.Email, et.UIType, et.Props)
}
w.WriteHeader(http.StatusOK)
}
Expand Down
4 changes: 4 additions & 0 deletions web/satellite/src/api/analytics.ts
Expand Up @@ -24,6 +24,7 @@ export class AnalyticsHttpApi {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: eventName,
uiType: __UI_TYPE__,
};
if (props) {
body['props'] = props;
Expand Down Expand Up @@ -51,6 +52,7 @@ export class AnalyticsHttpApi {
const body = {
eventName: eventName,
link: link,
uiType: __UI_TYPE__,
};
const response = await this.http.post(path, JSON.stringify(body));
if (response.ok) {
Expand All @@ -73,6 +75,7 @@ export class AnalyticsHttpApi {
const path = `${this.ROOT_PATH}/page`;
const body = {
pageName: pageName,
uiType: __UI_TYPE__,
};
const response = await this.http.post(path, JSON.stringify(body));
if (response.ok) {
Expand All @@ -95,6 +98,7 @@ export class AnalyticsHttpApi {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: AnalyticsEvent.UI_ERROR,
uiType: __UI_TYPE__,
};

if (source) {
Expand Down
4 changes: 4 additions & 0 deletions web/satellite/src/types/vite-env.d.ts
@@ -0,0 +1,4 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.

declare const __UI_TYPE__: string;
5 changes: 4 additions & 1 deletion web/satellite/vite.config-vuetify.js
Expand Up @@ -22,7 +22,10 @@ export default defineConfig({
},
}),
],
define: { 'process.env': {} },
define: {
'process.env': {},
__UI_TYPE__: JSON.stringify('vuetify'),
},
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url)),
Expand Down
1 change: 1 addition & 0 deletions web/satellite/vite.config.js
Expand Up @@ -66,6 +66,7 @@ export default defineConfig(({ mode }) => {
},
define: {
'process.env': {},
__UI_TYPE__: JSON.stringify('legacy'),
},
test: {
globals: true,
Expand Down

0 comments on commit ad13cb2

Please sign in to comment.