Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
VeXHarbinger authored Feb 19, 2024
1 parent d17e9d3 commit cc45af0
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,41 +5,47 @@ 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`.<br/>
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
<Router ... />
+ <AnalyticsNavigationTracker />
```

## 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; }
Expand All @@ -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)
[![GitHub Stars](https://img.shields.io/github/stars/VeXHarbinger/BlazorAnalytics.svg)](https://github.com/VeXHarbinger/BlazorAnalytics/stargazers)

0 comments on commit cc45af0

Please sign in to comment.