An open API service indexing awesome lists of open source software.

https://github.com/soenneker/soenneker.blazor.google.analytics

A Blazor interop library for Google Analytics
https://github.com/soenneker/soenneker.blazor.google.analytics

analytics blazor csharp dotnet google googleanalyticsinterop interop

Last synced: about 2 months ago
JSON representation

A Blazor interop library for Google Analytics

Awesome Lists containing this project

README

          

[![](https://img.shields.io/nuget/v/soenneker.blazor.google.analytics.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.google.analytics/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.blazor.google.analytics/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.blazor.google.analytics/actions/workflows/publish-package.yml)
[![](https://img.shields.io/nuget/dt/soenneker.blazor.google.analytics.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.blazor.google.analytics/)
[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.blazor.google.analytics/codeql.yml?label=CodeQL&style=for-the-badge)](https://github.com/soenneker/soenneker.blazor.google.analytics/actions/workflows/codeql.yml)

# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) 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`)

```csharp
public static async Task Main(string[] args)
{
...
builder.Services.AddGoogleAnalyticsInteropAsScoped();
}
```

2. Inject `IGoogleAnalyticsInterop` within your `App.Razor` file

```csharp
@using Soenneker.Blazor.Google.Analytics.Abstract
@inject IGoogleAnalyticsInterop GoogleAnalyticsInterop
```

3. Call the interop from `OnAfterRenderAsync` in `App.razor`.

```csharp
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (!firstRender)
return;

await GoogleAnalyticsInterop.Init("your-key-here");
}
```