dotnet add package Soenneker.Blazor.Google.Analytics
- Register the interop within DI (
Program.cs
)
public static async Task Main(string[] args)
{
...
builder.Services.AddGoogleAnalyticsInterop();
}
- Inject
IClarityInterop
within yourApp.Razor
file
@using Soenneker.Blazor.Google.Analytics.Abstract
@inject IGoogleAnalyticsInterop GoogleAnalyticsInterop
- Initialize the interop in
OnInitializedAsync
withinApp.Razor
using your Google Analytics tag id
protected override async Task OnInitializedAsync()
{
await GoogleAnalyticsInterop.Init("your-key-here");
...
}