Skip to content

Commit e0b4676

Browse files
authored
Issue #31 : Fixed order of arguments to TrackEvent method (#32)
Co-authored-by: Richard Greaves <richard.greaves@enera.com>
1 parent 61f4e21 commit e0b4676

6 files changed

Lines changed: 17 additions & 11 deletions

File tree

demo/DemoApp/DemoApp.Client/Pages/Counter.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
private void IncrementCount()
1616
{
1717
currentCount++;
18-
Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage");
18+
Analytics.TrackEvent("Increment", currentCount, "CountPage");
1919
}
2020
}

demo/DemoApp/DemoApp.Server/Pages/Counter.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,6 @@
1515
private void IncrementCount()
1616
{
1717
currentCount++;
18-
Analytics.TrackEvent("Increment", currentCount.ToString(), "CountPage");
18+
Analytics.TrackEvent("Increment", currentCount, "CountPage");
1919
}
2020
}

src/Blazor.Analytics/Abstractions/IAnalytics.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IAnalytics
88

99
Task TrackNavigation(string uri);
1010

11-
Task TrackEvent(string eventName, string eventValue, string eventCategory = null);
11+
Task TrackEvent(string eventName, string eventCategory = null, string eventLabel = null, int? eventValue = null);
12+
Task TrackEvent(string eventName, int eventValue, string eventCategory = null, string eventLabel = null);
1213
}
1314
}

src/Blazor.Analytics/Components/NavigationTracker.razor

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
@using System
2-
@using System.Threading.Tasks
1+
@using System.Threading.Tasks
32
@using Microsoft.AspNetCore.Components
43
@using Microsoft.AspNetCore.Components.Routing
54

src/Blazor.Analytics/GoogleAnalytics/GoogleAnalyticsStrategy.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ await _jsRuntime.InvokeAsync<string>(
5252

5353
public async Task TrackEvent(
5454
string eventName,
55-
string eventValue,
56-
string eventCategory = null)
55+
string eventCategory = null,
56+
string eventLabel = null,
57+
int? eventValue = null)
5758
{
5859
if (!_isInitialized)
5960
{
@@ -62,7 +63,12 @@ public async Task TrackEvent(
6263

6364
await _jsRuntime.InvokeAsync<string>(
6465
GoogleAnalyticsInterop.TrackEvent,
65-
_trackingId, eventName, eventValue, eventCategory);
66+
eventName, eventCategory, eventLabel, eventValue);
67+
}
68+
69+
public Task TrackEvent(string eventName, int eventValue, string eventCategory = null, string eventLabel = null)
70+
{
71+
return TrackEvent (eventName, eventCategory, eventLabel, eventValue);
6672
}
6773
}
6874
}

src/Blazor.Analytics/GoogleAnalytics/Resources/GoogleAnalyticsInterop.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ namespace GoogleAnalyticsInterop
4343
}
4444
}
4545

46-
export function trackEvent(event: string, eventCategory: string, eventLabel: string, eventValue: string)
46+
export function trackEvent(eventName: string, eventCategory: string, eventLabel: string, eventValue: string)
4747
{
48-
gtag("event", event, { event_category: eventCategory, event_label: eventLabel, value: eventValue });
48+
gtag("event", eventName, { event_category: eventCategory, event_label: eventLabel, value: eventValue });
4949
if(this.debug){
50-
console.log(`[GTAG][Event trigered]: ${event}`);
50+
console.log(`[GTAG][Event triggered]: ${eventName}`);
5151
}
5252
}
5353
}

0 commit comments

Comments
 (0)