### Install Dependencies Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/CONTRIBUTING.md Run this command in the root directory to install all project dependencies. ```bash npm install ``` -------------------------------- ### Install Nightly Build (General) Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/README.md Use this command to install the latest nightly build from the NPM registry. This is suitable for pre-production testing and validation. ```bash npm install @microsoft/applicationinsights-react-js@nightly ``` -------------------------------- ### Basic Application Insights Setup with React Router History Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/README.md Initialize Application Insights with the React Plugin and a browser history object for tracking router changes. Ensure to replace 'YOUR_CONNECTION_STRING_GOES_HERE' with your actual connection string. ```javascript import React from 'react'; import { ApplicationInsights } from '@microsoft/applicationinsights-web'; import { ReactPlugin, withAITracking } from '@microsoft/applicationinsights-react-js'; import { createBrowserHistory } from "history"; const browserHistory = createBrowserHistory({ basename: '' }); var reactPlugin = new ReactPlugin(); var appInsights = new ApplicationInsights({ config: { connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE', extensions: [reactPlugin], extensionConfig: { [reactPlugin.identifier]: { history: browserHistory } } } }); appInsights.loadAppInsights(); // To instrument various React components usage tracking, apply the `withAITracking` higher-order // component function. class MyComponent extends React.Component { ... } export default withAITracking(reactPlugin, MyComponent); ``` -------------------------------- ### Install Application Insights React Plugin Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/applicationinsights-react-js/README.md Install the npm package for the Application Insights React Plugin. ```bash npm install @microsoft/applicationinsights-react-js ``` -------------------------------- ### Install Specific Nightly Build Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/README.md Install a specific nightly build using its version number. This allows for testing particular builds, such as '2.7.3-nightly.2112-08'. ```bash npm install @microsoft/applicationinsights-react-js@2.7.3-nightly.2112-08 ``` -------------------------------- ### Application Insights Setup with Auto Route Tracking Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/README.md Initialize Application Insights with the React Plugin and enable `enableAutoRouteTracking` for automatic tracking of router changes, useful when router history is not directly exposed. Replace 'YOUR_CONNECTION_STRING_GOES_HERE' with your actual connection string. ```javascript var reactPlugin = new ReactPlugin(); var appInsights = new ApplicationInsights({ config: { connectionString: 'YOUR_CONNECTION_STRING_GOES_HERE', enableAutoRouteTracking: true, extensions: [reactPlugin] } } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Build All Packages Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/CONTRIBUTING.md Executes a build process for all packages within the project, respecting their dependencies. ```bash npm run build ``` -------------------------------- ### Run All Tests Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/CONTRIBUTING.md Executes all tests across all packages in the project. ```bash npm run test ``` -------------------------------- ### Set Version as Release Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Removes any existing pre-release tags from the version number, preparing it for a stable release (e.g., 3.1.2-dev to 3.1.2). ```bash npm run setVersion -- -release ``` -------------------------------- ### Set Dev Pre-release Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Applies a 'dev' pre-release tag to the current version (e.g., 3.1.2 to 3.1.2-dev). This can be done with or without the '-dev' flag. ```bash npm run setVersion ``` ```bash npm run setVersion -- -dev ``` -------------------------------- ### Set Specific Pre-release Tag Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Assigns a custom pre-release tag to the version number (e.g., 3.1.2 to 3.1.2-nightly). ```bash npm run setVersion -- -pre nightly ``` -------------------------------- ### Set Explicit Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Use this command to set a specific version number for all components. This is suitable when all components share the same version. ```bash npm run setVersion 3.2.0 ``` ```bash npm run setVersion -- 3.2.0 ``` -------------------------------- ### Set Dev Pre-release and Increment Patch Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Combines incrementing the patch version with adding a 'dev' pre-release tag (e.g., 3.1.2 to 3.1.3-dev). ```bash npm run setVersion -- -patch -dev ``` -------------------------------- ### Add Build Number to Release Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Use the `-bld` switch to append a build number to the version. This implies a pre-release version. If no pre-release tag is specified, `dev` will be assumed. ```bash npm run setVersion -- -bld 20210525.1 ``` ```bash npm run setVersion -- -bld 20210525.1 -dev ``` ```bash npm run setVersion -- -bld 20210525.1 -pre nightly ``` ```bash npm run setVersion -- -bld 20210525.1 -release ``` -------------------------------- ### Configure Instrumentation Key Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/sample/applicationinsights-react-sample/README.md To enable external telemetry, modify the instrumentationKey value in ApplicationInsightsService.tsx with your actual instrumentation key. ```typescript connectionString: "instrumentationKey=test", ``` -------------------------------- ### Basic Usage with Custom History Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/applicationinsights-react-js/README.md Integrate the Application Insights React Plugin with a custom browser history object. Ensure your instrumentation key is replaced with your actual key. ```javascript import React from 'react'; import { ApplicationInsights } from '@microsoft/applicationinsights-web'; import { ReactPlugin, withAITracking } from '@microsoft/applicationinsights-react-js'; import { createBrowserHistory } from "history"; const browserHistory = createBrowserHistory({ basename: '' }); var reactPlugin = new ReactPlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', extensions: [reactPlugin], extensionConfig: { [reactPlugin.identifier]: { history: browserHistory } } } }); appInsights.loadAppInsights(); // To instrument various React components usage tracking, apply the `withAITracking` higher-order // component function. class MyComponent extends React.Component { ... } export default withAITracking(reactPlugin, MyComponent); ``` -------------------------------- ### Type Error Fixed Guideline Link Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/README.md This link provides guidance for fixing type errors related to ReactPlugin and ITelemetryPlugin. It is relevant when encountering compatibility issues between the extension and the SDK. ```plaintext Type 'ReactPlugin' is not assignable to type 'ITelemetryPlugin'. ``` -------------------------------- ### Update Imports from applicationinsights-common to applicationinsights-core-js Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/RELEASES.md Migrate your import statements from the deprecated `@microsoft/applicationinsights-common` package to `@microsoft/applicationinsights-core-js` to ensure compatibility with newer versions of Application Insights. ```typescript // Before (deprecated) import { IConfig, ContextTagKeys } from "@microsoft/applicationinsights-common"; // After (recommended) import { IConfig, ContextTagKeys } from "@microsoft/applicationinsights-core-js"; ``` -------------------------------- ### Increment to Next Major Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Automatically increments the version to the next major number (e.g., 3.1.2 to 4.0.0). ```bash npm run setVersion -- -major ``` -------------------------------- ### Automatic Route Tracking Configuration Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/applicationinsights-react-js/README.md Configure Application Insights to automatically track route changes when using react-router v6 or similar scenarios where history is not directly exposed. Replace 'YOUR_INSTRUMENTATION_KEY_GOES_HERE' with your actual key. ```javascript var reactPlugin = new ReactPlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', enableAutoRouteTracking: true, extensions: [reactPlugin] } } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Increment to Next Minor Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Automatically increments the version to the next minor number (e.g., 3.1.2 to 3.2.0). ```bash npm run setVersion -- -minor ``` -------------------------------- ### Increment to Next Patch Version Source: https://github.com/microsoft/applicationinsights-react-js/blob/main/tools/release-tools/README.md Automatically increments the version to the next patch number (e.g., 3.1.2 to 3.1.3). This operation is based on the current version of individual components, not the root package.json. ```bash npm run setVersion -- -patch ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.