telemetryClient.ts
TLDR
The telemetryClient.ts
file is a module that provides a TelemetryClient class for tracking events and page visits. It exports the TelemetryClient class as the default export, as well as constants for telemetry categories and actions. It also exports an interface and a TelemetryHandler class.
Classes
TelemetryClient
The TelemetryClient
class is responsible for tracking events and page visits for telemetry purposes. It has the following methods:
-
setTelemetryHandler(telemetryHandler?: TelemetryHandler): void
: Sets the telemetry handler for the client. -
setUser(user: IUser): void
: Sets the user for the client. -
trackEvent(category: string, event: string, props?: IEventProps): void
: Tracks a custom event with the specified category, event name, and optional properties. -
pageVisited(category: string, name: string): void
: Tracks a page visit with the specified category and page name.
Constants
-
TelemetryCategory
: The category name for telemetry. -
TelemetryActions
: An object containing various telemetry action names.
Interfaces
-
IEventProps
: An interface defining optional properties for telemetry events. It includes properties for channel ID, team ID, board, view, view type, card, card template ID, board template ID, and share board enabled flag.
Classes
TelemetryHandler
The TelemetryHandler
class is responsible for handling telemetry events. Its functionality is not defined in the provided file.
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import {IUser} from '../user'
import {TelemetryHandler} from './telemetry'
export const TelemetryCategory = 'boards'
export const TelemetryActions = {
ClickChannelHeader: 'clickChannelHeader',
ClickChannelIntro: 'channelIntro_boardLink',
ViewBoard: 'viewBoard',
CreateBoard: 'createBoard',
DuplicateBoard: 'duplicateBoard',
DeleteBoard: 'deleteBoard',
DeleteBoardTemplate: 'deleteBoardTemplate',
ShareBoard: 'shareBoard',
CreateBoardTemplate: 'createBoardTemplate',
CreateBoardViaTemplate: 'createBoardViaTemplate',
AddTemplateFromBoard: 'AddTemplateFromBoard',
CreateBoardView: 'createBoardView',
DuplicateBoardView: 'duplicagteBoardView',
DeleteBoardView: 'deleteBoardView',
EditCardProperty: 'editCardProperty',
ViewCard: 'viewCard',
CreateCard: 'createCard',
CreateCardTemplate: 'createCardTemplate',
CreateCardViaTemplate: 'createCardViaTemplate',
DuplicateCard: 'duplicateCard',
DeleteCard: 'deleteCard',
AddTemplateFromCard: 'addTemplateFromCard',
ViewSharedBoard: 'viewSharedBoard',
ShareBoardOpenModal: 'shareBoard_openModal',
ShareBoardLogin: 'shareBoard_login',
ShareLinkPublicCopy: 'shareLinkPublic_copy',
ShareLinkInternalCopy: 'shareLinkInternal_copy',
ImportArchive: 'settings_importArchive',
ImportTrello: 'settings_importTrello',
ImportAsana: 'settings_importAsana',
ImportNotion: 'settings_importNotion',
ImportJira: 'settings_importJira',
ImportTodoist: 'settings_importTodoist',
ExportArchive: 'settings_exportArchive',
StartTour: 'welcomeScreen_startTour',
SkipTour: 'welcomeScreen_skipTour',
CloudMoreInfo: 'cloud_more_info',
ViewLimitReached: 'limit_ViewLimitReached',
ViewLimitCTAPerformed: 'limit_ViewLimitLinkOpen',
LimitCardCTAPerformed: 'limit_CardLimitCTAPerformed',
LimitCardLimitReached: 'limit_cardLimitReached',
LimitCardLimitLinkOpen: 'limit_cardLimitLinkOpen',
VersionMoreInfo: 'version_more_info',
ClickChannelsRHSBoard: 'click_board_in_channels_RHS',
}
interface IEventProps {
channelID?: string
teamID?: string
board?: string
view?: string
viewType?: string
card?: string
cardTemplateId?: string
boardTemplateId?: string
shareBoardEnabled?: boolean
}
class TelemetryClient {
public telemetryHandler?: TelemetryHandler
public user?: IUser
setTelemetryHandler(telemetryHandler?: TelemetryHandler): void {
this.telemetryHandler = telemetryHandler
}
setUser(user: IUser): void {
this.user = user
}
trackEvent(category: string, event: string, props?: IEventProps): void {
if (this.telemetryHandler) {
const userId = this.user?.id
this.telemetryHandler.trackEvent(userId || '', '', category, event, props)
}
}
pageVisited(category: string, name: string): void {
if (this.telemetryHandler) {
const userId = this.user?.id
this.telemetryHandler.pageVisited(userId || '', '', category, name)
}
}
}
const telemetryClient = new TelemetryClient()
export {TelemetryClient}
export default telemetryClient