diff --git a/src/index.tsx b/src/index.tsx index 92ca27f..ce2c1da 100644 --- a/src/index.tsx +++ b/src/index.tsx @@ -25,7 +25,7 @@ log.debug("started"); function executeStartupCommands() { log.debug("Executing startup commands", appData.startupCommands); - appData.startupCommands.forEach(cmd.execute.bind(cmd)); + appData.startupCommands.forEach(c => cmd.execute(c, {doNotTrack: true})); } function initializeModules() { diff --git a/src/networking/module.tsx b/src/networking/module.tsx index d0a8df7..783fe21 100644 --- a/src/networking/module.tsx +++ b/src/networking/module.tsx @@ -1,6 +1,6 @@ import React from 'react'; import AppState from '../shell/AppState'; -import { CmdShell, CommandInput } from '../shell/cmd'; +import { CmdShell, CommandInput, CommandOptions } from '../shell/cmd'; import ErrorResultView from '../shell/components/ErrorResultView'; import IpAddressView from './components/IpAddressView'; import ipAddressParser, {ParsingError, ParsedIpObject} from './ip-parser'; @@ -8,6 +8,7 @@ import { IpAddress, IpAddressWithSubnetMask, SubnetCommand } from "./models"; import log from 'loglevel'; import SubnetView from './components/SubnetView'; import { createSubnetMaskIp } from './subnet-utils'; +import {sendAnalyticsEvent} from '../shell/analytics'; const networkingAppModule = { setup: function(appState: AppState, cmd: CmdShell) { @@ -28,6 +29,7 @@ const networkingAppModule = { if(result instanceof SubnetCommand) { appState.addCommandResult(c.input, ); + trackCommand('SubnetCommand', c.options); return; } @@ -43,6 +45,8 @@ const networkingAppModule = { ipAddresses.push(r); } }); + + trackCommand("IpAddressesInput", c.options); appState.addCommandResult(c.input, ); } @@ -52,4 +56,13 @@ const networkingAppModule = { } } +function trackCommand(action: string, ops: CommandOptions) { + if(ops.doNotTrack !== true) { + sendAnalyticsEvent({ + eventCategory: "NetworkingCommand", + eventAction: action + }); + } +} + export default networkingAppModule; \ No newline at end of file diff --git a/src/shell/cmd.ts b/src/shell/cmd.ts index 3f9f73f..0a3cf3d 100644 --- a/src/shell/cmd.ts +++ b/src/shell/cmd.ts @@ -3,11 +3,20 @@ import log from 'loglevel'; export type CommandInput = { input: string; + options: CommandOptions +} + +export type CommandOptions = { + doNotTrack: boolean; } type HandleFunction = (input: CommandInput) => void; type InputErrorHandler = (input:string, error: Error) => void; +const DEFUALT_COMMAND_OPTIONS : CommandOptions = { + doNotTrack: false +}; + export interface ICommandHandler { canHandle (input:string) : boolean; handle: HandleFunction; @@ -23,19 +32,21 @@ export class CmdShell { this.errorHandler = null; }; - execute (rawInput: string) { + execute (rawInput: string, ops?: CommandOptions ) { - log.debug(`Executing command: ${rawInput}`) + log.debug(`Executing command: ${rawInput}`); + + ops = ops || Object.assign({}, DEFUALT_COMMAND_OPTIONS); var input = rawInput.trim().toLowerCase(); var handler = this.findHandler(input); if(handler != null) { if(this.debugMode) { - this.invokeHandler(input, handler); + this.invokeHandler(input, handler, ops); } else { try { - this.invokeHandler(input, handler); + this.invokeHandler(input, handler, ops); } catch (e) { this.handleError(input, e); } @@ -87,9 +98,9 @@ export class CmdShell { return this.handlers.filter(h => h.canHandle(input))[0]; }; - invokeHandler (input : string, handler : ICommandHandler) { + invokeHandler (input : string, handler : ICommandHandler, options: CommandOptions) { - var cmdResult = handler.handle({ input: input}); + var cmdResult = handler.handle({ input: input, options }); if(cmdResult != null) { log.debug(cmdResult); }