Skip to content

Commit

Permalink
Merge pull request #11 from IvanJosipovic/bugfix
Browse files Browse the repository at this point in the history
Bugfix
  • Loading branch information
IvanJosipovic authored Oct 4, 2020
2 parents 84e7bc7 + 8a79668 commit 8df3a64
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 10 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,32 @@ Blazor Application Insights
}
}
```

# Set User Name
- Edit Authentication.razor
```csharp
@page "/authentication/{action}"

<RemoteAuthenticatorView Action="@Action" OnLogInSucceeded="OnLogInSucceeded" OnLogOutSucceeded="OnLogOutSucceeded" />

@code{
[Parameter] public string Action { get; set; }

[CascadingParameter] public Task<AuthenticationState> AuthenticationState { get; set; }

[Inject] private IApplicationInsights AppInsights { get; set; }

public async Task OnLogInSucceeded()
{
var user = (await AuthenticationState).User;

await AppInsights.SetAuthenticatedUserContext(user.FindFirst("preferred_username")?.Value);
}

public async Task OnLogOutSucceeded()
{
await AppInsights.ClearAuthenticatedUserContext();
}
}

```
20 changes: 10 additions & 10 deletions src/BlazorApplicationInsights/ApplicationInsights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,47 +15,47 @@ public ApplicationInsights(IJSRuntime jsRuntime)

public async Task TrackPageView(string? name = null, string? uri = null, string? refUri = null, string? pageType = null, bool? isLoggedIn = null, Dictionary<string, object>? properties = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackPageView", new { name, uri, refUri, pageType, isLoggedIn, properties });
await JSRuntime.InvokeVoidAsync("appInsights.trackPageView", new object[] { name, uri, refUri, pageType, isLoggedIn, properties });
}

public async Task TrackEvent(string name, Dictionary<string, object>? properties = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackEvent", new { name, properties });
await JSRuntime.InvokeVoidAsync("appInsights.trackEvent", new object[] { name, properties });
}

public async Task TrackTrace(string message, SeverityLevel? severityLevel, Dictionary<string, object>? properties)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackTrace", new { message , severityLevel, properties});
await JSRuntime.InvokeVoidAsync("appInsights.trackTrace", new object[] { message, severityLevel, properties });
}

public async Task TrackException(Error error, SeverityLevel? severityLevel = null, Dictionary<string, object>? properties = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackException", new { error, severityLevel, properties });
await JSRuntime.InvokeVoidAsync("appInsights.trackException", new object[] { error, severityLevel, properties });
}

public async Task StartTrackPage(string? name = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.startTrackPage", new { name });
await JSRuntime.InvokeVoidAsync("appInsights.startTrackPage", new object[] { name });
}

public async Task StopTrackPage(string? name = null, string? url = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.stopTrackPage", new { name, url });
await JSRuntime.InvokeVoidAsync("appInsights.stopTrackPage", new object[] { name, url });
}

public async Task TrackMetric(string name, double average, double? sampleCount = null, double? min = null, double? max = null, Dictionary<string, object>? properties = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackMetric", new { name, average, sampleCount, min, max, properties });
await JSRuntime.InvokeVoidAsync("appInsights.trackMetric", new object[] { name, average, sampleCount, min, max, properties });
}

public async Task TrackDependencyData(string id, double responseCode, string? absoluteUrl = null, bool? success = null, string? commandName = null, double? duration = null, string? method = null, Dictionary<string, object>? properties = null)
{
await JSRuntime.InvokeVoidAsync("appInsights.trackDependencyData", new { id, responseCode, absoluteUrl, success, commandName, duration, method, properties });
await JSRuntime.InvokeVoidAsync("appInsights.trackDependencyData", new object[] { id, responseCode, absoluteUrl, success, commandName, duration, method, properties });
}

public async Task Flush(bool? async = true)
{
await JSRuntime.InvokeVoidAsync("appInsights.flush", new { async });
await JSRuntime.InvokeVoidAsync("appInsights.flush", new object[] { async });
}

public async Task ClearAuthenticatedUserContext()
Expand All @@ -65,7 +65,7 @@ public async Task ClearAuthenticatedUserContext()

public async Task SetAuthenticatedUserContext(string authenticatedUserId, string? accountId = null, bool storeInCookie = false)
{
await JSRuntime.InvokeVoidAsync("appInsights.setAuthenticatedUserContext", new { authenticatedUserId, accountId, storeInCookie });
await JSRuntime.InvokeVoidAsync("appInsights.setAuthenticatedUserContext", new object[] { authenticatedUserId, accountId, storeInCookie });
}
}
}

0 comments on commit 8df3a64

Please sign in to comment.