Skip to content

soenneker/soenneker.blazor.google.analytics

Repository files navigation

Soenneker.Blazor.Google.Analytics

A Blazor interop library for Google Analytics

Installation

dotnet add package Soenneker.Blazor.Google.Analytics

Usage

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