BlazorUniversalAnalytics 1.0.4

dotnet add package BlazorUniversalAnalytics --version 1.0.4                
NuGet\Install-Package BlazorUniversalAnalytics -Version 1.0.4                
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="BlazorUniversalAnalytics" Version="1.0.4" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add BlazorUniversalAnalytics --version 1.0.4                
#r "nuget: BlazorUniversalAnalytics, 1.0.4"                
#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 BlazorUniversalAnalytics as a Cake Addin
#addin nuget:?package=BlazorUniversalAnalytics&version=1.0.4

// Install BlazorUniversalAnalytics as a Cake Tool
#tool nuget:?package=BlazorUniversalAnalytics&version=1.0.4                

Blazor extensions for Analytics. Supported platforms: Google Analytics, GTAG, GTM and Facebook Pixel. AspNetCore Version: 5.0

NuGet Package

https://www.nuget.org/packages/BlazorUniversalAnalytics/

GitHub Repository

https://github.com/welisonmenezes/blazor-universal-analytics

Configuration

For Every Tracker

First, import the namespaces in _Imports.razor

@using BlazorUniversalAnalytics
@using BlazorUniversalAnalytics.BUA

Then, add the BUANavigationTracker component below your Router in App.razor.<br/> The tracker listens to every navigation change while it's rendered on a page.

    <Router ... />
+   <BUANavigationTracker />

Setting up Analytics

Inside your main Startup/Program, call AddBUA. This will configure your GTAG_ID automatically.

+   builder.Services.AddBUA("YOUR_GTAG_ID", "YOUR_FBPIXEL_ID", null);

If YOUR_GTM_ID is set, YOUR_GTAG_ID and YOUR_FBPIXEL_ID will be ignored as GTM will manage this for you. Pageview events will be heard if the embed of such scripts exists. Example:

    builder.Services.AddBUA(null, null, "YOUR_GTM_ID");

How to trigger an Analytics Event

See below an example:

@page "/counter"
@using Demo.Shared

<h1>Counter</h1>

<p>Current count: @currentCount</p>

<button class="btn btn-primary" @onclick="IncrementCount">Click me</button>

@code {
    private int currentCount = 0;

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

    private WeatherForecast SampleData = new WeatherForecast
    {
        Date = DateTime.Now,
        TemperatureC = 30,
        Summary = "It's a hot day"
    };

    private void IncrementCount()
    {
        currentCount++;

        // IMPORTANT: The object SampleDate are used below just as an example.
        // You must to check the correct object properties on respective Analytic tool you are using.

        // Google Analytics
        //Analytics.TrackEventGtag("event-name", "event-value", "event-category", "event-label");
        //Analytics.TrackEventGtag("event-name", SampleData);

        // Facebook
        //Analytics.TrackEventFacebookPixel("event-name", SampleData);

        // Google Tag Manager
        //Analytics.TrackEventGTM("event-name", SampleData);
    }
}
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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.4 8,399 11/12/2021
1.0.3 2,183 2/3/2021