From cc45af09528427e94aaa0254e1d4ad916169755a Mon Sep 17 00:00:00 2001 From: Alex Pearlstein Date: Sun, 18 Feb 2024 22:38:05 -0500 Subject: [PATCH] Update README.md --- README.md | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 946eed5..db6e0f9 100644 --- a/README.md +++ b/README.md @@ -5,20 +5,25 @@ Supported platforms: Google Analytics, Google Tag Manager, and FaceBook Pixel. # First Credit where Credit is Due All the hard work was done by [welisonmenezes](https://github.com/welisonmenezes) in his [blazor-universal-analytics](https://github.com/welisonmenezes/blazor-universal-analytics) repository. +I just built upon his work and adapted it to my Blazor needs. # Configuration -## For Every Tracker +First install the Nuget package -First, Install Nuget, then import the namespaces in `_Imports.razor` +``` +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 every navigation change while it's rendered on a page. +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. ```diff + @@ -26,20 +31,21 @@ The tracker listens to every navigation change while it's rendered on a page. ## Setting up Analytics -Inside your main `Startup`/`Program`, call `AddBlazorAnalytics`. This will configure your GTAG_ID automatically. +Inside your main `Startup`/`Program`, call `AddBlazorAnalytics`. ```diff -+ builder.Services.AddBlazorAnalytics("YOUR_GTAG_ID", "YOUR_FBPIXEL_ID", null); ++ builder.Services.AddBlazorAnalytics("GoogleAnalyticsId", "PixelId", "TagManagerId"); ``` -If YOUR_GTM_ID is set, YOUR_GTAG_ID and YOUR_FBPIXEL_ID will be ignored as GTM will manage this for you. Page view events will be heard if the embed of such scripts exists. -Example: +If TagManagerId is set, GoogleAnalyticsId and PixelId will be ignored as TagManager will manage this for you. -``` - builder.Services.AddBlazorAnalytics(null, null, null); -``` +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; } @@ -52,4 +58,4 @@ Example: # Blazor Analytics [![GitHub Issues](https://img.shields.io/github/issues/VeXHarbinger/BlazorAnalytics.svg)](https://github.com/VeXHarbinger/BlazorAnalytics/issues) -[![GitHub Stars](https://img.shields.io/github/stars/VeXHarbinger/BlazorAnalytics.svg)](https://github.com/VeXHarbinger/BlazorAnalytics/stargazers) \ No newline at end of file +[![GitHub Stars](https://img.shields.io/github/stars/VeXHarbinger/BlazorAnalytics.svg)](https://github.com/VeXHarbinger/BlazorAnalytics/stargazers)