diff --git a/demo/DemoApp/DemoApp.Client/Pages/Counter.razor b/demo/DemoApp/DemoApp.Client/Pages/Counter.razor index 9cf89b9..52d5dfd 100644 --- a/demo/DemoApp/DemoApp.Client/Pages/Counter.razor +++ b/demo/DemoApp/DemoApp.Client/Pages/Counter.razor @@ -15,6 +15,6 @@ private void IncrementCount() { currentCount++; - Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage"); + Analytics.TrackEvent("Increment", currentCount, "CountPage"); } } diff --git a/demo/DemoApp/DemoApp.Server/Pages/Counter.razor b/demo/DemoApp/DemoApp.Server/Pages/Counter.razor index 9cf89b9..5e7b311 100644 --- a/demo/DemoApp/DemoApp.Server/Pages/Counter.razor +++ b/demo/DemoApp/DemoApp.Server/Pages/Counter.razor @@ -15,6 +15,6 @@ private void IncrementCount() { currentCount++; - Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage"); + Analytics.TrackEvent("Increment", currentCount, "CountPage"); } } diff --git a/src/Blazor.Analytics/Abstractions/IAnalytics.cs b/src/Blazor.Analytics/Abstractions/IAnalytics.cs index 2a82e20..ca4460a 100644 --- a/src/Blazor.Analytics/Abstractions/IAnalytics.cs +++ b/src/Blazor.Analytics/Abstractions/IAnalytics.cs @@ -8,6 +8,7 @@ public interface IAnalytics Task TrackNavigation(string uri); - Task TrackEvent(string eventName, string eventValue, string eventCategory = null); + Task TrackEvent(string eventName, string eventCategory = null, string eventLabel = null, int? eventValue = null); + Task TrackEvent(string eventName, int eventValue, string eventCategory = null, string eventLabel = null); } } diff --git a/src/Blazor.Analytics/Components/NavigationTracker.razor b/src/Blazor.Analytics/Components/NavigationTracker.razor index c1d0b72..c19d7c3 100644 --- a/src/Blazor.Analytics/Components/NavigationTracker.razor +++ b/src/Blazor.Analytics/Components/NavigationTracker.razor @@ -1,5 +1,4 @@ -@using System -@using System.Threading.Tasks +@using System.Threading.Tasks @using Microsoft.AspNetCore.Components @using Microsoft.AspNetCore.Components.Routing diff --git a/src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs b/src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs index 2e5b9b0..dd5245e 100644 --- a/src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs +++ b/src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs @@ -52,8 +52,9 @@ await _jsRuntime.InvokeAsync( public async Task TrackEvent( string eventName, - string eventValue, - string eventCategory = null) + string eventCategory = null, + string eventLabel = null, + int? eventValue = null) { if (!_isInitialized) { @@ -62,7 +63,12 @@ public async Task TrackEvent( await _jsRuntime.InvokeAsync( GoogleAnalyticsInterop.TrackEvent, - _trackingId, eventName, eventValue, eventCategory); + eventName, eventCategory, eventLabel, eventValue); + } + + public Task TrackEvent(string eventName, int eventValue, string eventCategory = null, string eventLabel = null) + { + return TrackEvent (eventName, eventCategory, eventLabel, eventValue); } } } diff --git a/src/Blazor.Analytics/GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts b/src/Blazor.Analytics/GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts index 4e2896c..8a9e187 100644 --- a/src/Blazor.Analytics/GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts +++ b/src/Blazor.Analytics/GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts @@ -43,11 +43,11 @@ namespace GoogleAnalyticsInterop } } - export function trackEvent(event: string, eventCategory: string, eventLabel: string, eventValue: string) + export function trackEvent(eventName: string, eventCategory: string, eventLabel: string, eventValue: string) { - gtag("event", event, { event_category: eventCategory, event_label: eventLabel, value: eventValue }); + gtag("event", eventName, { event_category: eventCategory, event_label: eventLabel, value: eventValue }); if(this.debug){ - console.log(`[GTAG][Event trigered]: ${event}`); + console.log(`[GTAG][Event triggered]: ${eventName}`); } } }