Skip to content

Commit

Permalink
Issue #31 : Fixed order of arguments to TrackEvent method (#32)
Browse files Browse the repository at this point in the history
Co-authored-by: Richard Greaves <richard.greaves@enera.com>
  • Loading branch information
Enritski and Enritski committed Feb 26, 2021
1 parent 61f4e21 commit e0b4676
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
2 changes: 1 addition & 1 deletion demo/DemoApp/DemoApp.Client/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
private void IncrementCount()
{
currentCount++;
Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage");
Analytics.TrackEvent("Increment", currentCount, "CountPage");
}
}
2 changes: 1 addition & 1 deletion demo/DemoApp/DemoApp.Server/Pages/Counter.razor
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@
private void IncrementCount()
{
currentCount++;
Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage");
Analytics.TrackEvent("Increment", currentCount, "CountPage");
}
}
3 changes: 2 additions & 1 deletion src/Blazor.Analytics/Abstractions/IAnalytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
3 changes: 1 addition & 2 deletions src/Blazor.Analytics/Components/NavigationTracker.razor
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@using System
@using System.Threading.Tasks
@using System.Threading.Tasks
@using Microsoft.AspNetCore.Components
@using Microsoft.AspNetCore.Components.Routing

Expand Down
12 changes: 9 additions & 3 deletions src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ await _jsRuntime.InvokeAsync<string>(

public async Task TrackEvent(
string eventName,
string eventValue,
string eventCategory = null)
string eventCategory = null,
string eventLabel = null,
int? eventValue = null)
{
if (!_isInitialized)
{
Expand All @@ -62,7 +63,12 @@ public async Task TrackEvent(

await _jsRuntime.InvokeAsync<string>(
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
}
}
}

0 comments on commit e0b4676

Please sign in to comment.