Vibe Google Analytics
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
using Microsoft.JSInterop;
|
||||
|
||||
namespace Shared.Services;
|
||||
|
||||
public class AnalyticsService
|
||||
{
|
||||
private readonly IJSRuntime _jsRuntime;
|
||||
|
||||
public AnalyticsService(IJSRuntime jsRuntime)
|
||||
{
|
||||
_jsRuntime = jsRuntime;
|
||||
}
|
||||
|
||||
public async ValueTask TrackPageView(string path)
|
||||
{
|
||||
await _jsRuntime.InvokeVoidAsync("trackPageView", path);
|
||||
}
|
||||
|
||||
public async ValueTask TrackEvent(string eventName, object? eventData = null)
|
||||
{
|
||||
if (eventData != null)
|
||||
await _jsRuntime.InvokeVoidAsync("gtag", "event", eventName, eventData);
|
||||
else
|
||||
await _jsRuntime.InvokeVoidAsync("gtag", "event", eventName);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user