You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/azure-monitor/app/javascript-sdk.md
+11-1Lines changed: 11 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -21,8 +21,18 @@ ms.reviewer: mmcc
21
21
## Get started
22
22
23
23
The Application Insights JavaScript SDK is implemented with a runtime snippet for out-of-the-box web analytics.
24
+
The JavaScript snippet can be added to your webpages manually or via the automatic snippet injection.
24
25
25
-
### Enable Application Insights SDK for JavaScript
26
+
### Enable Application Insights SDK for JavaScript automatically
27
+
28
+
The automatic Snippet injection feature available in the Application Insights .NET core SDK and the Application Insights Node.js SDK (preview)
29
+
allows you to automatically inject the Application Insights JavaScript SDK into every webpage of your web application.
30
+
For more information, see [Application Insights .NET core SDK Snippet Injection](./asp-net-core.md?tabs=netcorenew%2Cnetcore6#enable-client-side-telemetry-for-web-applications)
31
+
and [Application Insights Node.js SDK Snippet Injection (preview)](./nodejs.md#automatic-web-instrumentationpreview).
32
+
However, if you want more control over which pages to add the Application Insights JavaScript SDK
33
+
or if you're using a programming language other than .NET and Node.js, please follow the manual configuration steps below.
34
+
35
+
### Enable Application Insights SDK for JavaScript manually
26
36
27
37
Only two steps are required to enable the Application Insights SDK for JavaScript.
You can use automatic web snippet injection to enable [Application Insights usage experiences](usage-overview.md) and browser diagnostic experiences with a simple configuration. It's an easier alternative to manually adding the JavaScript snippet or npm package to your JavaScript web code.
179
+
Automatic web Instrumentation can be enabled for node server via configuration
180
180
181
-
For node server with configuration, set `enableAutoWebSnippetInjection` to `true`. Alternatively, set the environment variable as `APPLICATIONINSIGHTS_WEB_SNIPPET_ENABLED = true`. Automatic web snippet injection is available in Application Insights Node.js SDK version 2.3.0 or greater. For more information, see [Application Insights Node.js GitHub Readme](https://github.com/microsoft/ApplicationInsights-node.js#automatic-web-snippet-injectionpreview).
181
+
```javascript
182
+
let appInsights =require("applicationinsights");
183
+
appInsights.setup("<connection_string>")
184
+
.enableWebInstrumentation(true)
185
+
.start();
186
+
```
187
+
188
+
or by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_ENABLED = true`.
189
+
190
+
Web Instrumentation will be enabled on node server responses when all of the following requirements are met:
191
+
192
+
- Response has status code `200`.
193
+
- Response method is `GET`.
194
+
- Sever response has `Content-Type` html.
195
+
- Server response contains both `<head>` and `</head>` Tags.
196
+
- If response is compressed, it must have only one `Content-Encoding` type, and encoding type must be one of `gzip`, `br` or `deflate`.
197
+
- Response does not contain current /backup web Instrumentation CDN endpoints. (current and backup Web Instrumentation CDN endpoints [here](https://github.com/microsoft/ApplicationInsights-JS#active-public-cdn-endpoints))
198
+
199
+
web Instrumentation CDN endpoint can be changed by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_SOURCE = "web Instrumentation CDN endpoints"`.
200
+
web Instrumentation connection string can be changed by setting environment variable `APPLICATIONINSIGHTS_WEB_INSTRUMENTATION_CONNECTION_STRING = "web Instrumentation connection string"`
201
+
202
+
> [!Note]
203
+
> Web Instrumentation may slow down server response time, especially when response size is large or response is compressed. For the case in which some middle layers are applied, it may result in web Instrumentation not working and original response will be returned.
0 commit comments