• Stars
    star
    123
  • Rank 288,854 (Top 6 %)
  • Language
    C#
  • License
    MIT License
  • Created over 5 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Blazor extensions for Analytics: Google Analytics, GTAG, ...

Blazor extensions for Analytics: Google Analytics, GTAG, etc...
AspNetCore Version: 3.1.8

NuGet Package

https://nuget.org/packages/Blazor-Analytics

Configuration

For Every Tracker

First, import the namespaces in _Imports.razor

@using Blazor.Analytics
@using Blazor.Analytics.Components

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

    <Router ... />
+   <NavigationTracker />

ServerSide Specific Configuration

Edit _Host.cshtml and apply the following change:

    <script src="_framework/blazor.server.js"></script>
+   <script src="_content/Blazor-Analytics/blazor-analytics.js"></script>

WASM Specific Configuration

Edit index.html and apply the following change:

    <script src="_framework/blazor.webassembly.js"></script>
+   <script src="_content/Blazor-Analytics/blazor-analytics.js"></script>

Setting up GoogleAnalytics

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

+   services.AddGoogleAnalytics("YOUR_GTAG_ID");

How to trigger an Analytics Event

  1. Inject IAnalytics wherever you want to trigger the event.
  2. Call IAnalytics.TrackEvent passing the EventName and EventData (an object containing the event data).
    Or
    Call IAnalytics.TrackEvent passing the EventName, Value and Category (optional).
@inject Blazor.Analytics.IAnalytics Analytics

Analytics.TrackEvent("generate_lead", new {currency = "USD", value = 99.99});

How to disable tracking on any page

1.- Inject ITrackingState on blazor component

@using Blazor.Analytics.Abstractions
@using Blazor.Analytics

@inject ITrackingNavigationState TrackingNavigationState
@inject IAnalytics GlobalTracking

2.- Disable tracking on initialized

2.1 For current page

protected override void OnInitialized()
{
    TrackingNavigationState.DisableTracking();
}

2.2 For whole application

protected override void OnInitialized()
{
    GlobalTracking.Disable();
}

Changelog

v3.8.0

  • Support for globally enable/disable tracking for the whole application

v3.7.0

  • Support for disable tracking on any page

v3.1.0

  • Support for Events

v3.0.0

  • Added support for
    • ServerSide (pre-rendering)
    • ServerSide (runtime)
    • WASM (runtime)

More Repositories

1

linq-collections

Strongly typed Linq and Collections implementation for Javascript and TypeScript (ECMAScript 5)
TypeScript
117
star
2

blazor-lazy-loading

Automatic Lazy Loading support for Blazor (Server and WebAssembly)
C#
91
star
3

xlnt-wasm

WebAssembly bindings for XLNT library
C++
24
star
4

recycle-tray

Adds the recycle bin to the tray
C#
9
star
5

IscEngine

Pure C++ and OpenGL-based 3D Game engine
C++
5
star
6

generic_optional

enables reference types for std::optional
C++
3
star
7

wasm-imasiengine

C++
3
star
8

noneim-framework

High performance, strongly typed, modular and microservice oriented web framework written from scratch. MVC, task scheduler, cache system, reflection, constructor-based dependency injection, custom ORM for MySQL, yielded responses (event-stream), mappings, routing, …
PHP
3
star
9

blazor-canvas

Canvas Components for easy graphic rendering (WASM+ServerSide)
C#
2
star
10

instant-blazor

Instantaneous Blazor Applications
HTML
2
star
11

ignaciusBros

HTML5 game created from scratch in less than 24h for the Euskal Encounter
JavaScript
2
star
12

eMulerr

Radarr/Sonarr integration for eD2k/KAD networks (eMule)
TypeScript
2
star
13

docker-php7

php7 + nginx + traefik support
PHP
2
star
14

SmsBomber

Result of live streaming. Simple SMS bomber based on adds platforms
PHP
1
star
15

buscaplan.com

buscaplan, oh yeah!
HTML
1
star
16

messagebus

A simple MessageBus implementation for .NET Standard 2.0
C#
1
star
17

dotnet-core-async-console

dotnet-core ConsoleApplication with ThreadPools
C#
1
star
18

cpp-starter

Project template for modern CMake, GoogleTest and multiple projects/libraries
CMake
1
star
19

rpi-traefik

traefik proxy + let's encrypt
Shell
1
star
20

blog.codeisc.com

JavaScript
1
star
21

expressive

C#
1
star
22

wasm-pong

WASM (emscripten, C++14) + WebGL2 (3D) + SDL2 (2D)
HTML
1
star
23

eMysqli

Extended Mysqli class that allows calling PROCEDURES, FUNCTIONS and VIEWS
PHP
1
star