@@ -31,14 +31,13 @@ npm install @microsoft/applicationinsights-react-js @microsoft/applicationinsigh
31
31
Initialize a connection to Application Insights:
32
32
33
33
``` javascript
34
- // AppInsights.js
34
+ import React from ' react ' ;
35
35
import { ApplicationInsights } from ' @microsoft/applicationinsights-web' ;
36
- import { ReactPlugin } from ' @microsoft/applicationinsights-react-js' ;
37
- import { createBrowserHistory } from ' history' ;
38
-
36
+ import { ReactPlugin , withAITracking } from ' @microsoft/applicationinsights-react-js' ;
37
+ import { createBrowserHistory } from " history" ;
39
38
const browserHistory = createBrowserHistory ({ basename: ' ' });
40
- const reactPlugin = new ReactPlugin ();
41
- const appInsights = new ApplicationInsights ({
39
+ var reactPlugin = new ReactPlugin ();
40
+ var appInsights = new ApplicationInsights ({
42
41
config: {
43
42
instrumentationKey: ' YOUR_INSTRUMENTATION_KEY_GOES_HERE' ,
44
43
extensions: [reactPlugin],
@@ -48,7 +47,6 @@ const appInsights = new ApplicationInsights({
48
47
}
49
48
});
50
49
appInsights .loadAppInsights ();
51
- export { reactPlugin , appInsights };
52
50
```
53
51
54
52
Wrap your component with the higher-order component function to enable Application Insights on it:
@@ -71,6 +69,21 @@ class MyComponent extends React.Component {
71
69
export default withAITracking (reactPlugin, MyComponent);
72
70
```
73
71
72
+ For ` react-router v6 ` or other scenarios where router history is not exposed, appInsights config ` enableAutoRouteTracking ` can be used to auto track router changes:
73
+
74
+ ``` javascript
75
+ var reactPlugin = new ReactPlugin ();
76
+ var appInsights = new ApplicationInsights ({
77
+ config: {
78
+ instrumentationKey: ' YOUR_INSTRUMENTATION_KEY_GOES_HERE' ,
79
+ enableAutoRouteTracking: true ,
80
+ extensions: [reactPlugin]
81
+ }
82
+ }
83
+ });
84
+ appInsights .loadAppInsights ();
85
+ ```
86
+
74
87
## Configuration
75
88
76
89
| Name | Default | Description |
0 commit comments