Enable Azure Monitor Application Insights Real User Monitoring
We collect page views by default. But if you want to also collect clicks by default, consider adding the Click Analytics Auto-Collection plug-in:
- If you're adding a framework extension, which you can add after you follow the steps to get started below, you can optionally add Click Analytics when you add the framework extension.
- If you're not adding a framework extension, add the Click Analytics plug-in after you follow the steps to get started.
- Azure subscription: Create an Azure subscription for free
- Application Insights resource: Create an Application Insights resource
|Method||When would I use this method?|
|npm package||You want to bring the SDK into your code and enable IntelliSense. This option is only needed for developers who require more custom events and configuration.|
Preferably, you should add it as the first script in your
<head>section so that it can monitor any potential issues with all of your dependencies.
|src||string||Required||The full URL for where to load the SDK from. This value is used for the "src" attribute of a dynamically added <script /> tag. You can use the public CDN location or your own privately hosted one.|
|name||string||Optional||The global name for the initialized SDK. Use this setting if you need to initialize two different SDKs at the same time.
The default value is appInsights, so
Note: If you assign a name value or if a previous instance has been assigned to the global name appInsightsSDK, the SDK initialization code requires it to be in the global namespace as
The default value is 0ms after timeout. If you use a negative value, the script tag is immediately added to the
Reporting first attempts to use fetch() if available and then fallback to XHR. Set this setting to
|crossOrigin||string||Optional||By including this setting, the script tag added to download the SDK includes the crossOrigin attribute with this string value. Use this setting when you need to provide support for CORS. When not defined (the default), no crossOrigin attribute is added. Recommended values are not defined (the default), "", or "anonymous". For all valid values, see the cross origin HTML attribute documentation.|
|cr||boolean||Optional||If the SDK fails to load and the endpoint value defined for
If the SDK successfully loads from a backup CDN endpoint, it loads from the first available one, which is determined when the server performs a successful load check. If the SDK fails to load from any of the backup CDN endpoints, the SDK Failure error message appears.
When not defined, the default value is
If you’re loading the SDK from your own privately hosted CDN endpoint, this configuration option is not applicable.
Paste the connection string in your environment
To paste the connection string in your environment, follow these steps:
Navigate to the Overview pane of your Application Insights resource.
Locate the Connection String.
Select the Copy to clipboard icon to copy the connection string to the clipboard.
Replace the placeholder
connectionStringformat must follow "InstrumentationKey=xxxx;....". If the string provided does not meet this format, the SDK load process fails.
The connection string isn't considered a security token or key. For more information, see Do new Azure regions require the use of connection strings?.
(Optional) Add SDK configuration
To add SDK configuration, add each configuration option directly under
connectionString. For example:
(Optional) Add advanced SDK configuration
If you want to use the extra features provided by plugins for specific frameworks and optionally enable the Click Analytics plug-in, see:
Confirm data is flowing
Go to your Application Insights resource that you've enabled the SDK for.
In the Application Insights resource menu on the left, under Investigate, select the Transaction search pane.
Open the Event types dropdown menu and select Select all to clear the checkboxes in the menu.
From the Event types dropdown menu, select:
- Page View for Azure Monitor Application Insights Real User Monitoring
- Custom Event for the Click Analytics Auto-Collection plug-in.
If you want to query data to confirm data is flowing:
Select Logs in the left pane.
When you select Logs, the Queries dialog opens, which contains sample queries relevant to your data.
Select Run for the sample query you want to run.
If needed, you can update the sample query or write a new query by using Kusto Query Language (KQL).
For essential KQL operators, see Learn common KQL operators.
Frequently asked questions
This section provides answers to common questions.
What are the user and session counts?
- If there's no client-side script, you can set cookies at the server.
- If one real user uses your site in different browsers, or by using in-private/incognito browsing, or different machines, they're counted more than once.
- To identify a signed-in user across machines and browsers, add a call to setAuthenticatedUserContext().
Additionally, while the script is downloading from the CDN, all tracking of your page is queued, so you don't lose any telemetry during the entire life cycle of your page. This setup process provides your page with a seamless analytics system that's invisible to your users.
|Chrome Latest ✔||Firefox Latest ✔||v3.x: IE 9+ & Microsoft Edge ✔
v2.x: IE 8+ Compatible & Microsoft Edge ✔
|Opera Latest ✔||Safari Latest ✔|
See GitHub for full details on Internet Explorer 8 support.
- If you can't run the application or you aren't getting data as expected, see the dedicated troubleshooting article.
- For Azure support issues, open an Azure support ticket.
- Use the Telemetry Viewer extension to list out the individual events in the network payload and monitor the internal calls within Application Insights.