diff --git a/webapp/channels/src/actions/telemetry_actions.jsx b/webapp/channels/src/actions/telemetry_actions.jsx index ffe9a1ec65..e710cc26ad 100644 --- a/webapp/channels/src/actions/telemetry_actions.jsx +++ b/webapp/channels/src/actions/telemetry_actions.jsx @@ -21,7 +21,7 @@ export function shouldTrackPerformance(state = store.getState()) { return isDevModeEnabled(state) || isTelemetryEnabled(state); } -export function trackEvent(category, event, props) { +export function trackEvent(category, event, props = {}) { const state = store.getState(); if ( isPerformanceDebuggingEnabled(state) && @@ -38,7 +38,7 @@ export function trackEvent(category, event, props) { } } -export function trackFeatureEvent(featureName, event, props) { +export function trackFeatureEvent(featureName, event, props = {}) { Client4.trackFeatureEvent(featureName, event, props); } diff --git a/webapp/channels/src/components/channel_invite_modal/group_option/group_option.tsx b/webapp/channels/src/components/channel_invite_modal/group_option/group_option.tsx index c0f26be8aa..9e72efa601 100644 --- a/webapp/channels/src/components/channel_invite_modal/group_option/group_option.tsx +++ b/webapp/channels/src/components/channel_invite_modal/group_option/group_option.tsx @@ -58,7 +58,7 @@ const GroupOption = (props: Props) => { for (const profile of profiles) { addUserProfile(profile); } - trackFeatureEvent(TrackGroupsFeature, TrackInviteGroupEvent, {}); + trackFeatureEvent(TrackGroupsFeature, TrackInviteGroupEvent); }, [addUserProfile, profiles]); const onKeyDown = useCallback((e: KeyboardEvent) => { diff --git a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/marketplace_item_app.tsx b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/marketplace_item_app.tsx index 5cd2e29b59..6c93ecf017 100644 --- a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/marketplace_item_app.tsx +++ b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_app/marketplace_item_app.tsx @@ -23,7 +23,7 @@ export type MarketplaceItemAppProps = { installing: boolean; error?: string; - trackEvent: (category: string, event: string, props?: unknown) => void; + trackEvent: (category: string, event: string, props?: Record) => void; actions: { installApp: (id: string) => Promise; diff --git a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/marketplace_item_plugin.tsx b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/marketplace_item_plugin.tsx index eada83926f..20c0d996d3 100644 --- a/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/marketplace_item_plugin.tsx +++ b/webapp/channels/src/components/plugin_marketplace/marketplace_item/marketplace_item_plugin/marketplace_item_plugin.tsx @@ -239,7 +239,7 @@ export type MarketplaceItemPluginProps = { pluginStatus?: PluginStatusRedux; error?: string; isDefaultMarketplace: boolean; - trackEvent: (category: string, event: string, props?: unknown) => void; + trackEvent: (category: string, event: string, props?: Record) => void; actions: { installPlugin: (id: string) => void; diff --git a/webapp/channels/src/components/user_settings/notifications/user_settings_notifications.tsx b/webapp/channels/src/components/user_settings/notifications/user_settings_notifications.tsx index 7d595410dd..95bd378e05 100644 --- a/webapp/channels/src/components/user_settings/notifications/user_settings_notifications.tsx +++ b/webapp/channels/src/components/user_settings/notifications/user_settings_notifications.tsx @@ -14,6 +14,10 @@ import {LightbulbOutlineIcon} from '@mattermost/compass-icons/components'; import type {PreferencesType} from '@mattermost/types/preferences'; import type {UserNotifyProps, UserProfile} from '@mattermost/types/users'; +import {TrackPassiveKeywordsFeature, TrackPassiveKeywordsEvent} from 'mattermost-redux/constants/telemetry'; + +import {trackFeatureEvent} from 'actions/telemetry_actions.jsx'; + import ExternalLink from 'components/external_link'; import SettingItem from 'components/setting_item'; import SettingItemMax from 'components/setting_item_max'; @@ -283,6 +287,9 @@ class NotificationsTab extends React.PureComponent { }); } data.highlight_keys = highlightKeys.join(','); + if (this.props.user.notify_props?.highlight_keys !== data.highlight_keys && data.highlight_keys.length > 0) { + trackFeatureEvent(TrackPassiveKeywordsFeature, TrackPassiveKeywordsEvent); + } this.setState({isSaving: true}); stopTryNotificationRing(); diff --git a/webapp/channels/src/packages/mattermost-redux/src/client/rudder.ts b/webapp/channels/src/packages/mattermost-redux/src/client/rudder.ts index 2517bed3d2..5e38cba9e2 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/client/rudder.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/client/rudder.ts @@ -7,21 +7,13 @@ import * as rudderAnalytics from 'rudder-sdk-js'; import type {TelemetryHandler} from '@mattermost/client'; -import {TrackMiscCategory, TrackActionCategory, TrackEnterpriseSKU, TrackProfessionalSKU, TrackInviteGroupEvent} from 'mattermost-redux/constants/telemetry'; +import {TrackMiscCategory, eventCategory, eventSKUs} from 'mattermost-redux/constants/telemetry'; import {isSystemAdmin} from 'mattermost-redux/utils/user_utils'; export {rudderAnalytics}; -const eventSKUs: {[event: string]: string[]} = { - [TrackInviteGroupEvent]: [TrackProfessionalSKU, TrackEnterpriseSKU], -}; - -const eventCategory: {[event: string]: string} = { - [TrackInviteGroupEvent]: TrackActionCategory, -}; - export class RudderTelemetryHandler implements TelemetryHandler { - trackEvent(userId: string, userRoles: string, category: string, event: string, props?: any) { + trackEvent(userId: string, userRoles: string, category: string, event: string, props: Record = {}) { const properties = Object.assign({ category, type: event, @@ -45,13 +37,14 @@ export class RudderTelemetryHandler implements TelemetryHandler { rudderAnalytics.track('event', properties, options); } - trackFeatureEvent(userId: string, userRoles: string, featureName: string, event: string, props?: any) { + trackFeatureEvent(userId: string, userRoles: string, featureName: string, event: string, props: Record = {}) { const properties = Object.assign({ category: getEventCategory(event), type: event, user_actual_id: userId, user_actual_role: getActualRoles(userRoles), }, props); + const options = { context: { feature: { @@ -93,19 +86,23 @@ function getActualRoles(userRoles: string) { function getSKUs(eventName: string) { const skus: string[] | undefined = eventSKUs[eventName]; + if (skus === undefined) { // Next line is to be aware if you've forgotten to add a SKU, add an empty array for Team edition // eslint-disable-next-line console.warn(`Event ${eventName} has no SKUs attached`); } + return skus ?? []; } function getEventCategory(eventName: string) { const category: string | undefined = eventCategory[eventName]; + if (category === undefined) { // eslint-disable-next-line console.warn(`Event ${eventName} doesn't have a category`); } + return category ?? TrackMiscCategory; } diff --git a/webapp/channels/src/packages/mattermost-redux/src/constants/index.ts b/webapp/channels/src/packages/mattermost-redux/src/constants/index.ts index 7b34210f5c..403abefb11 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/constants/index.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/constants/index.ts @@ -12,9 +12,8 @@ import RequestStatus from './request_status'; import Roles from './roles'; import Stats from './stats'; import Teams from './teams'; -import Telemetry from './telemetry'; import Threads from './threads'; import Users from './users'; import WebsocketEvents from './websocket'; -export {General, Preferences, Posts, Files, RequestStatus, WebsocketEvents, Teams, Stats, Permissions, Emoji, Plugins, Users, Roles, Threads, Telemetry}; +export {General, Preferences, Posts, Files, RequestStatus, WebsocketEvents, Teams, Stats, Permissions, Emoji, Plugins, Users, Roles, Threads}; diff --git a/webapp/channels/src/packages/mattermost-redux/src/constants/telemetry.ts b/webapp/channels/src/packages/mattermost-redux/src/constants/telemetry.ts index 5e6958fa1d..9d30c293e6 100644 --- a/webapp/channels/src/packages/mattermost-redux/src/constants/telemetry.ts +++ b/webapp/channels/src/packages/mattermost-redux/src/constants/telemetry.ts @@ -6,13 +6,23 @@ export const TrackProfessionalSKU = 'professional'; export const TrackEnterpriseSKU = 'enterprise'; // Features -export const TrackGroupsFeature: string = 'custom_groups'; +export const TrackGroupsFeature = 'custom_groups'; +export const TrackPassiveKeywordsFeature = 'passive_keywords'; // Events -export const TrackInviteGroupEvent: string = 'invite_group_to_channel'; +export const TrackInviteGroupEvent = 'invite_group_to_channel'; +export const TrackPassiveKeywordsEvent = 'update_passive_keywords'; // Categories -export const TrackActionCategory: string = 'action'; -export const TrackMiscCategory: string = 'miscellaneous'; +export const TrackActionCategory = 'action'; +export const TrackMiscCategory = 'miscellaneous'; -export default {TrackActionCategory, TrackMiscCategory, TrackInviteGroupEvent, TrackGroupsFeature, TrackEnterpriseSKU, TrackProfessionalSKU}; +export const eventSKUs: {[event: string]: string[]} = { + [TrackInviteGroupEvent]: [TrackProfessionalSKU, TrackEnterpriseSKU], + [TrackPassiveKeywordsEvent]: [TrackProfessionalSKU, TrackEnterpriseSKU], +}; + +export const eventCategory: {[event: string]: string} = { + [TrackInviteGroupEvent]: TrackActionCategory, + [TrackPassiveKeywordsEvent]: TrackActionCategory, +}; diff --git a/webapp/platform/client/src/client4.ts b/webapp/platform/client/src/client4.ts index 6eb8dae22a..b46c5d825f 100644 --- a/webapp/platform/client/src/client4.ts +++ b/webapp/platform/client/src/client4.ts @@ -4327,7 +4327,8 @@ export default class Client4 { this.telemetryHandler.trackEvent(this.userId, this.userRoles, category, event, props); } } - trackFeatureEvent(featureName: string, event: string, props?: any) { + + trackFeatureEvent(featureName: string, event: string, props: Record = {}) { if (this.telemetryHandler) { this.telemetryHandler.trackFeatureEvent(this.userId, this.userRoles, featureName, event, props); } diff --git a/webapp/platform/client/src/telemetry.ts b/webapp/platform/client/src/telemetry.ts index f7fb3e364b..e34de5f4c0 100644 --- a/webapp/platform/client/src/telemetry.ts +++ b/webapp/platform/client/src/telemetry.ts @@ -2,7 +2,7 @@ // See LICENSE.txt for license information. export interface TelemetryHandler { - trackEvent: (userId: string, userRoles: string, category: string, event: string, props?: any) => void; - trackFeatureEvent: (userId: string, userRoles: string, featureName: string, event: string, props?: any) => void; + trackEvent: (userId: string, userRoles: string, category: string, event: string, props?: Record) => void; + trackFeatureEvent: (userId: string, userRoles: string, featureName: string, event: string, props?: Record) => void; pageVisited: (userId: string, userRoles: string, category: string, name: string) => void; }