BlazorAnalytics 1.0.2
dotnet add package BlazorAnalytics --version 1.0.2
NuGet\Install-Package BlazorAnalytics -Version 1.0.2
<PackageReference Include="BlazorAnalytics" Version="1.0.2" />
paket add BlazorAnalytics --version 1.0.2
#r "nuget: BlazorAnalytics, 1.0.2"
// 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
Product | Versions 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. |
-
net8.0
- Microsoft.AspNetCore.Components.Web (>= 8.0.2)
- Microsoft.AspNetCore.Components.WebAssembly (>= 8.0.2)
- Microsoft.AspNetCore.WebUtilities (>= 8.0.2)
- Microsoft.Extensions.Http (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.