Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/isc30/blazor-analytics
Blazor extensions for Analytics: Google Analytics, GTAG, ...
https://github.com/isc30/blazor-analytics
blazor blazor-extensions google-analytics gtag razor-components
Last synced: 10 days ago
JSON representation
Blazor extensions for Analytics: Google Analytics, GTAG, ...
- Host: GitHub
- URL: https://github.com/isc30/blazor-analytics
- Owner: isc30
- License: mit
- Created: 2019-04-18T19:03:12.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-06-07T14:40:46.000Z (over 1 year ago)
- Last Synced: 2024-08-01T15:05:36.696Z (3 months ago)
- Topics: blazor, blazor-extensions, google-analytics, gtag, razor-components
- Language: C#
- Homepage:
- Size: 271 KB
- Stars: 143
- Watchers: 6
- Forks: 39
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-blazor - Blazor Analytics - Blazor extensions for Analytics. (Libraries & Extensions / Tools & Utilities)
README
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`
```csharp
@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.```csharp diff
+
```### ServerSide Specific Configuration
Edit `_Host.cshtml` and apply the following change:
```html diff
+
```### WASM Specific Configuration
Edit `index.html` and apply the following change:
```html diff
+
```## Setting up GoogleAnalytics
Inside your main `Startup`/`Program`, call `AddGoogleAnalytics`. This will configure your GTAG_ID automatically.
```csharp diff
+ 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).```csharp
@inject Blazor.Analytics.IAnalytics AnalyticsAnalytics.TrackEvent("generate_lead", new {currency = "USD", value = 99.99});
```# How to disable tracking on any page
1.- Inject ITrackingState on blazor component
```csharp
@using Blazor.Analytics.Abstractions
@using Blazor.Analytics@inject ITrackingNavigationState TrackingNavigationState
@inject IAnalytics GlobalTracking
```2.- Disable tracking on initialized
2.1 For current page
```csharp
protected override void OnInitialized()
{
TrackingNavigationState.DisableTracking();
}
```
2.2 For whole application
```csharp
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)