A Blazor interop library that sets up client-side Azure Application Insights.
dotnet add package Soenneker.Blazor.ApplicationInsights
- Insert the script in
wwwroot/index.html
at the bottom of your<body>
but before the other scripts
<script src="_content/Soenneker.Blazor.ApplicationInsights/applicationinsights.js"></script>
- Register the interop within DI (
Program.cs
)
public static async Task Main(string[] args)
{
...
builder.Services.AddApplicationInsights();
}
- Inject
IApplicationInsightsInterop
within yourApp.Razor
file
@using Soenneker.Blazor.ApplicationInsights.Abstract
@inject IApplicationInsightsInterop AppInsightsInterop
- Initialize the interop in
OnInitializedAsync
withinApp.Razor
using your Clarity project key
protected override async Task OnInitializedAsync()
{
await AppInsightsInterop.Init("your-connection-string-here");
...
}