web/satellite, satellite/analytics: add UI type to analytics properties

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
This commit is contained in:
Jeremy Wharton 2023-10-13 00:39:30 -05:00 committed by Storj Robot
parent c9421d11e7
commit ad13cb2bf5
6 changed files with 23 additions and 7 deletions

View File

@ -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
}
@ -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)
@ -553,7 +554,7 @@ 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
}
@ -561,6 +562,7 @@ func (service *Service) TrackErrorEvent(userID uuid.UUID, email string, source s
props := segment.NewProperties()
props.Set("email", email)
props.Set("source", source)
props.Set("ui_type", uiType)
service.enqueueMessage(segment.Track{
UserId: userID.String(),
@ -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
}
@ -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(),

View File

@ -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"`
}
@ -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)
}

View File

@ -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;
@ -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) {
@ -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) {
@ -95,6 +98,7 @@ export class AnalyticsHttpApi {
const path = `${this.ROOT_PATH}/event`;
const body = {
eventName: AnalyticsEvent.UI_ERROR,
uiType: __UI_TYPE__,
};
if (source) {

4
web/satellite/src/types/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1,4 @@
// Copyright (C) 2023 Storj Labs, Inc.
// See LICENSE for copying information.
declare const __UI_TYPE__: string;

View File

@ -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)),

View File

@ -66,6 +66,7 @@ export default defineConfig(({ mode }) => {
},
define: {
'process.env': {},
__UI_TYPE__: JSON.stringify('legacy'),
},
test: {
globals: true,