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