Skip to content

Commit

Permalink
telemetry/feat: override page view names - now english only (#472)
Browse files Browse the repository at this point in the history
* telemetry/feat: override page view names - now  engllish only

* add all page names
  • Loading branch information
alex-krasn committed Aug 5, 2020
1 parent 76381bc commit 76945df
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/react/components/pages/modelCompose/modelCompose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ export default class ModelComposePage extends React.Component<IModelComposePageP
if (this.props.project) {
this.getModelList();
}
document.title = strings.modelCompose.title + "-" + strings.appName;
document.title = strings.modelCompose.title + " - " + strings.appName;
}

public componentDidUpdate(prevProps, prevState) {
Expand Down
43 changes: 35 additions & 8 deletions src/services/telemetryService.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,33 @@
import {ApplicationInsights} from '@microsoft/applicationinsights-web';
import {ReactPlugin} from '@microsoft/applicationinsights-react-js';
import { constants } from '../common/constants';
import { ApplicationInsights, ITelemetryItem } from "@microsoft/applicationinsights-web";
import { ReactPlugin } from "@microsoft/applicationinsights-react-js";
import { constants } from "../common/constants";

let reactPlugin = null;
let appInsights = null;

const adjustPageViewName = (item) => {
const pathArray: string[] = item.uri.split("/");
const pathName = pathArray.length > 2 ? pathArray[1].slice(0, -1) + "_" + pathArray[3] : pathArray[1];
switch (pathName) {
case "project_edit":
return "Editor";
case "project_train":
return "Train";
case "project_modelcompose":
return "Model_Compose"
case "project_predict":
return "Analyze";
case "project_settings":
return "Project_Setting";
case "connections":
return "Application_Connections";
case "settings":
return "Application_Settings";
default:
return "Home";
}
}

/**
* Create the App Insights Telemetry Service
* @return {{reactPlugin: ReactPlugin, appInsights: Object, initialize: Function}} - Object
Expand All @@ -14,15 +37,15 @@ const createTelemetryService = () => {
/**
* Initialize the Application Insights class
* @param {string} instrumentationKey - Application Insights Instrumentation Key
* @param {Object} browserHistory - client's browser history, supplied by the withRouter HOC
* @param {Object} browserHistory - client"s browser history, supplied by the withRouter HOC
* @return {void}
*/
const initialize = (instrumentationKey: string, browserHistory: any): void => {
if (!browserHistory) {
throw new Error('Could not initialize Telemetry Service');
throw new Error("Could not initialize Telemetry Service");
}
if (!instrumentationKey) {
throw new Error('Telemetry Service Instrumentation key not provided.')
throw new Error("Telemetry Service Instrumentation key not provided.")
}

reactPlugin = new ReactPlugin();
Expand All @@ -41,12 +64,16 @@ const createTelemetryService = () => {
}
}
});

appInsights.loadAppInsights();

appInsights.context.application.ver = constants.apiVersion;
appInsights.addTelemetryInitializer((envelope) => {
const telemetryItem: ITelemetryItem = envelope.baseData;
telemetryItem.name = adjustPageViewName(telemetryItem);
})
};

return {reactPlugin, appInsights, initialize};
return { reactPlugin, appInsights, initialize };
};

export const ai = createTelemetryService();
Expand Down

0 comments on commit 76945df

Please sign in to comment.