### Install Dependencies Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/CONTRIBUTING.md Install all project dependencies using npm. This command should be run after cloning the repository and before building. ```bash npm install ``` -------------------------------- ### Install Nightly Build Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Use this command to install the latest nightly build of the SDK for pre-production testing. ```bash npm install @microsoft/applicationinsights-react-native@nightly ``` -------------------------------- ### Install Specific Nightly Build Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Install a specific nightly build using its version number. This is useful for testing specific changes or rollbacks. ```bash npm install @microsoft/applicationinsights-react-native@2.7.3-nightly.2112-08 ``` -------------------------------- ### Build Project Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/CONTRIBUTING.md Build all packages in the project. This command should be run after installing dependencies or making changes. ```bash npm run build ``` -------------------------------- ### Set as Specific Pre-release Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Sets the version to a specific pre-release tag. Example: 3.1.2 becomes 3.1.2-nightly. ```bash npm run setVersion -- -pre nightly ``` -------------------------------- ### Install Application Insights React Native SDK Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README-manual.md Install the necessary packages for Application Insights React Native and the web SDK using npm. ```zsh npm install --save @microsoft/applicationinsights-react-native @microsoft/applicationinsights-web ``` -------------------------------- ### Install Application Insights React Native Plugin Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/applicationinsights-react-native/README.md Install the necessary packages for the Application Insights React Native plugin and the device info module. Ensure react-native-device-info is linked. ```zsh npm install --save @microsoft/applicationinsights-react-native @microsoft/applicationinsights-web npm install --save react-native-device-info react-native link react-native-device-info ``` -------------------------------- ### Set Dev Pre-release Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Changes the current version to a 'dev' pre-release build. Example: 3.1.2 becomes 3.1.2-dev. ```bash npm run setVersion ``` ```bash npm run setVersion -- -dev ``` -------------------------------- ### Set Version as Release Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Removes any current pre-release tag from the version. Example: 3.1.2-dev becomes 3.1.2. ```bash npm run setVersion -- -release ``` -------------------------------- ### Dev Pre-release and Next Patch Level Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Combines incrementing to the next patch level with setting a 'dev' pre-release tag. Example: 3.1.2 becomes 3.1.3-dev. ```bash npm run setVersion -- -patch -dev ``` -------------------------------- ### Add Build Number to Release (Implied Pre-release) Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Appends a build number to the version, implying a pre-release. If no pre-release tag is specified, 'dev' is assumed. The build number uses a '.' prefix as per semver. Example: 3.1.2 becomes 3.1.2-dev.20210525.1. ```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 ``` -------------------------------- ### Increase to Next Major Release Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Increments the current version to the next major release. Example: 3.1.2 becomes 4.0.0. ```bash npm run setVersion -- -major ``` -------------------------------- ### setVersion.js Usage Help Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md General help displayed when the passed arguments appear to be incorrect. Lists all available options for version management. ```bash setVersion.js [|-patch|-minor|-major] [-dev|-alpha|-beta|-release] [-bld ######] [-test] -------------------------- - Identifies the version to set for all packages, must start with x.y.z -patch - Increment the current version to the next patch number (x.y.z => x.y.[z+1] -minor - Increment the current version to the next minor number (x.y.z => x.[y+1].0 -major - Increment the current version to the next major number (x.y.z => [x+1].0.0 -dev - Add the 'dev' pre-release to the number (x.y.z => x.y.z-dev) -alpha - Add the 'alpha' pre-release to the number (x.y.z => x.y.z-alpha) -beta - Add the 'beta' pre-release to the number (x.y.z => x.y.z-beta) -release - Remove any existing pre-release tags (x.y.z-prerel => x.y.z) -bld ###### - Append the provided build number to the version (x.y.z => x.y.z-[prerel].######) [prerel] defaults to dev if not defined -pre ###### - Set the pre-release to the provided value (x.y.z => x.y.z-[prerel]) -react - Update only the react packages (Require as the react components need to update after the core because of the different versions of TypeScript being used.) -test - Scan all of the package.json files and log the changes, but DON'T update the files ``` -------------------------------- ### Initialize Plugin with Custom Device Info Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README-manual.md Integrate the plugin by providing a custom module for device information collection, which can return strings or Promises. ```typescript import { Application Insights } from '@microsoft/applicationinsights-web'; // Simple inline constant implementation const myDeviceInfoModule = { getModel: () => "deviceModel", getDeviceType: () => "deviceType", // v5 returns a string while latest returns a promise getUniqueId: () => "deviceId", // This "may" also return a Promise }; var RNMPlugin = new ReactNativeManualDevicePlugin(); RNMPlugin.setDeviceInfoModule(myDeviceInfoModule); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', extensions: [RNMPlugin] } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Initialize Application Insights with React Native Plugin Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Construct the plugin and add it as an extension to your Application Insights instance. Replace 'YOUR_INSTRUMENTATION_KEY_GOES_HERE' with your actual key. ```typescript import { Application Insights } from '@microsoft/applicationinsights-web'; import { ReactNativePlugin } from '@microsoft/applicationinsights-react-native'; var RNPlugin = new ReactNativePlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', extensions: [RNPlugin] } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Run Tests Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/CONTRIBUTING.md Execute all project tests. This command should be run to ensure code changes do not break existing functionality. ```bash npm run test ``` -------------------------------- ### Use Custom Device Info Collection Class Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Set a custom device info module using 'setDeviceInfoModule' to provide your own implementation for collecting device details. ```typescript import { Application Insights } from '@microsoft/applicationinsights-web'; // Simple inline constant implementation const myDeviceInfoModule = { getModel: () => "deviceModel", getDeviceType: () => "deviceType", // v5 returns a string while latest returns a promise getUniqueId: () => "deviceId", // This "may" also return a Promise }; var RNPlugin = new ReactNativePlugin(); RNPlugin.setDeviceInfoModule(myDeviceInfoModule); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', extensions: [RNPlugin] } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Initialize Plugin with Disabled Device Collection Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README-manual.md Construct the plugin and add it as an extension to your Application Insights instance, manually disabling device collection. ```typescript import { Application Insights } from '@microsoft/applicationinsights-web'; import {ReactNativeManualDevicePlugin} from '@microsoft/applicationinsights-react-native/manual'; var RNMPlugin = new ReactNativeManualDevicePlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', disableDeviceCollection: true, extensions: [RNMPlugin] } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Module Loading and Test Execution Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/applicationinsights-react-native/Tests/UnitTests.html Loads necessary modules for testing Application Insights React Native, including QUnit, test framework, shims, utilities, core, and React Native specific components. It then configures and runs the unit tests. ```javascript var modules = new ModuleLoader({ baseUrl: '../', paths: { qunit: "../../common/Tests/External/qunit-2.9.3", "react-native": "./Tests/External/DummyReactNative" } }); // Load qunit here instead of with tests, otherwise will not work modules.add("qunit"); // Load and define the app insights test framework module modules.add("@microsoft/ai-test-framework", "../node_modules/@microsoft/ai-test-framework/dist/ai-test-framework"); // Load and define the app insights Shims module modules.add("@microsoft/applicationinsights-shims", "../node_modules/@microsoft/applicationinsights-shims/browser/applicationinsights-shims"); // Load ts-utils (ts-utils changed from umd to main) modules.add("@nevware21/ts-utils", "../node_modules/@nevware21/ts-utils/dist/es5/main/ts-utils"); // Load DynamicProto modules.add("@microsoft/dynamicproto-js", "../node_modules/@microsoft/dynamicproto-js/dist/es5/umd/dynamicproto-js", true); // Load Core modules.add("@microsoft/applicationinsights-core-js", "../node_modules/@microsoft/applicationinsights-core-js/browser/es5/applicationinsights-core-js"); modules.add("react-native"); // Load React native device info modules.add("react-native-device-info", "../node_modules/react-native-device-info/lib/commonjs/web/index"); var testModule = modules.add("Tests/Unit/src/reactnativeplugin.tests", "./Unit/dist/reactnativeplugin.tests.js") testModule.run = function (tests) { console && console.log("Starting tests"); QUnit.start(); tests.runTests(); }; modules.run(); ``` -------------------------------- ### Set Explicit Version with npm Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Use this command to set an explicit version number for all components. Ensure all components are on the same version before running. ```bash npm run setVersion 3.2.0 ``` -------------------------------- ### Initialize Application Insights with React Native Plugin Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/applicationinsights-react-native/README.md Construct the ReactNativePlugin and add it as an extension to your Application Insights instance. Ensure you are using a compatible version of @microsoft/applicationinsights-web. ```ts import { ApplicationInsights } from '@microsoft/applicationinsights-web'; import { ReactNativePlugin } from '@microsoft/applicationinsights-react-native'; var RNPlugin = new ReactNativePlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', extensions: [RNPlugin] } }); appInsights.loadAppInsights(); ``` -------------------------------- ### Set Version Explicitly Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Sets the package version to a specific build number. The '--' is optional when specifying an explicit version. ```bash npm run setVersion 3.2.0 ``` ```bash npm run setVersion -- 3.2.0 ``` -------------------------------- ### Manually Import Plugin for Expo Users Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README-manual.md If importing ReactNativeManualDevicePlugin directly fails in Expo, use this alternative import path. ```typescript import {ReactNativeManualDevicePlugin} from '@microsoft/applicationinsights-react-native/dist-esm/manualIndex'; ``` -------------------------------- ### IDeviceInfoModule Interface Definition Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Defines the interface for accessing device information, abstracting the 'react-native-device-info' module for testing and custom implementations. ```typescript /** * Interface to abstract how the plugin can access the Device Info, this is a stripped * down version of the "react-native-device-info" interface and is mostly supplied for * testing. */ export interface IDeviceInfoModule { /** * Returns the Device Model */ getModel: () => string; /** * Returns the device type */ getDeviceType: () => string; /** * Returns the unique Id for the device, to support both the current version and previous * versions react-native-device-info, this may return either a `string` or `Promise`, * when a promise is returned the plugin will "wait" for the promise to `resolve` or `reject` * before processing any events. This WILL cause telemetry to be BLOCKED until either of these * states, so when returning a Promise it MUST `resolve` or `reject` it can't just never resolve. * There is a default timeout configured via `uniqueIdPromiseTimeout` to automatically unblock * event processing when this issue occurs. */ getUniqueId: () => Promise | string; } ``` -------------------------------- ### Increment Minor Version with npm Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Use this command to automatically increment the minor version number (x.[y+1].0). The increment is based on each component's current version, not the root package.json. ```bash npm run setVersion -- -minor ``` -------------------------------- ### Increment Patch Version with npm Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/tools/release-tools/README.md Use this command to automatically increment the patch version number (x.y.[z+1]). The increment is based on each component's current version, not the root package.json. ```bash npm run setVersion -- -patch ``` -------------------------------- ### Disable Automatic Device Info Collection Source: https://github.com/microsoft/applicationinsights-react-native/blob/main/README.md Initialize Application Insights with the 'disableDeviceCollection' flag set to true to prevent automatic collection of device information. ```typescript import { Application Insights } from '@microsoft/applicationinsights-web'; var RNPlugin = new ReactNativePlugin(); var appInsights = new ApplicationInsights({ config: { instrumentationKey: 'YOUR_INSTRUMENTATION_KEY_GOES_HERE', disableDeviceCollection: true, extensions: [RNPlugin] } }); appInsights.loadAppInsights(); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.