BlazorAnalytics 1.0.2

dotnet add package BlazorAnalytics --version 1.0.2                
NuGet\Install-Package BlazorAnalytics -Version 1.0.2                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="BlazorAnalytics" Version="1.0.2" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorAnalytics --version 1.0.2                
#r "nuget: BlazorAnalytics, 1.0.2"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install BlazorAnalytics as a Cake Addin
#addin nuget:?package=BlazorAnalytics&version=1.0.2

// Install BlazorAnalytics as a Cake Tool
#tool nuget:?package=BlazorAnalytics&version=1.0.2                

Blazor extensions for Analytics. Supported platforms: Google Analytics, Google Tag Manager, and FaceBook Pixel.

What is Blazor Analytics and what can it do for me?

First Credit where Credit is Due

All the hard work was done by welisonmenezes in his blazor-universal-analytics repository. I just built upon his work and adapted it to my Blazor needs.

Configuration

First install the Nuget package

Install-Package BlazorAnalytics

Then import the namespaces in _Imports.razor

@using BlazorAnalytics

Then, add the AnalyticsNavigationTracker component below your Router in App.razor.

The tracker listens to the navigation change and reports the page_view event to your analytics tracker.

    <Router ... />
+   <AnalyticsNavigationTracker />

Setting up Analytics

Inside your main Startup/Program, call AddBlazorAnalytics.

+   builder.Services.AddBlazorAnalytics("GoogleAnalyticsId", "PixelId", "TagManagerId");

If TagManagerId is set, GoogleAnalyticsId and PixelId will be ignored as TagManager will manage this for you.

Page view events will be broadcast to your analytics tracker as long as an Id is provided.

You can use all null values though and still use the LogEvent function.

How to trigger an Analytics Event

There is a full example on the Demo's C;ient Counter page, but all you need to do in your code is request the service via the dependency injection.

[Inject]
protected IBlazorAnalytics Analytics { get; set; }

private void MyFunction()
{
  Analytics.LogEvent("button_clicked", "Some Value");
}

Blazor Analytics

GitHub Issues GitHub Stars

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.0.2 452 2/17/2024
1.0.1 87 2/17/2024
1.0.0 76 2/17/2024