VeXHarbinger / BlazorAnalytics

A simple Blazor control to enable MetaPixel, GA4, and Tag Manager tracking

Home Page:https://falootin.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

About

A simple Blazor control to enable MetaPixel, GA4, and Tag Manager tracking

https://falootin.com/

License:GNU General Public License v3.0


Languages

Language:HTML 34.1%Language:C# 28.4%Language:CSS 25.6%Language:JavaScript 11.9%