Skip to content

Commit

Permalink
Added unique sessions view
Browse files Browse the repository at this point in the history
  • Loading branch information
dhindrik committed Oct 31, 2024
1 parent 67ef61c commit 0b8d621
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 2 deletions.
52 changes: 50 additions & 2 deletions TinyInsights.Web/Pages/UserAnalytics.razor
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,28 @@
}
</RadzenStack>
</RadzenCard>

<RadzenCard>
<RadzenStack>
<h2>Unique user sessions per day</h2>
@if (isLoadingSessionsPerDay)
{
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
}
else
{
<RadzenChart>
<RadzenLegend Visible="false" />
<RadzenLineSeries Data="@sessionsPerDay" CategoryProperty="Date" ValueProperty="Count">
<RadzenMarkers MarkerType="MarkerType.Circle" />
<RadzenSeriesDataLabels />
</RadzenLineSeries>
<RadzenCategoryAxis Visible="false"></RadzenCategoryAxis>
</RadzenChart>
}
</RadzenStack>
</RadzenCard>

<div class="wrapbox">
<div class="wrapitem">
<RadzenCard>
Expand Down Expand Up @@ -80,8 +102,9 @@
[CascadingParameter]
public GlobalFilter GlobalFilter { get; set; }

private bool isLoadingUsersPerDayViews = true, isLoadingCountryList = true, isLoadingUsersPerLanguage;
private bool isLoadingUsersPerDayViews = true, isLoadingCountryList = true, isLoadingUsersPerLanguage, isLoadingSessionsPerDay;
private List<CountPerDay> usersPerDay = new();
private List<CountPerDay> sessionsPerDay = new();
private List<CountPerKey> usersPerCountry = new();
private List<CountPerKey> usersPerLanguage = new();
protected override async Task OnParametersSetAsync()
Expand All @@ -95,7 +118,7 @@
{
try
{
await Task.WhenAll(LoadUsersPerDay(), LoadCountries(), LoadLanguageList());
await Task.WhenAll(LoadUsersPerDay(), LoadCountries(), LoadLanguageList(), LoadSessionsPerDay());
}
catch (Exception ex)
{
Expand Down Expand Up @@ -128,6 +151,31 @@
await InvokeAsync(StateHasChanged);
}

private async Task LoadSessionsPerDay()
{
isLoadingSessionsPerDay = true;

var result = await Service.GetSessionsPerDay(GlobalFilter);

var date = DateOnly.FromDateTime(DateTime.Now).AddDays(-GlobalFilter.NumberOfDays);
var days = new List<CountPerDay>();

for (int i = 0; i <= GlobalFilter.NumberOfDays; i++)
{
var currentDate = date.AddDays(i);
var day = result.SingleOrDefault(x => x.Date == currentDate);

var count = day?.Count ?? 0;

days.Add(new CountPerDay(currentDate, count));
}

sessionsPerDay = days;
isLoadingSessionsPerDay = false;

await InvokeAsync(StateHasChanged);
}

private async Task LoadCountries()
{
isLoadingCountryList = true;
Expand Down
2 changes: 2 additions & 0 deletions TinyInsights.Web/Services/IInsightsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ public interface IInsightsService
Task<List<CountPerKey>> GetUsersPerIdiom(GlobalFilter filter);
Task<List<CountPerKey>> GetUsersPerOperatingSystem(GlobalFilter filter);
Task<List<CountPerKey>> GetUserPerManufacturer(GlobalFilter filter);

Task<List<CountPerDay>> GetSessionsPerDay(GlobalFilter filter);
#endregion

}
8 changes: 8 additions & 0 deletions TinyInsights.Web/Services/InsightsService.Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ public Task<List<CountPerDay>> GetUsersPerDay(GlobalFilter filter)
return GetPerDayResult(query);
}

public Task<List<CountPerDay>> GetSessionsPerDay(GlobalFilter filter)
{
var queryFilter = GetFilter(filter);
var query = $"pageViews | where{queryFilter} isnotnull(session_Id) and timestamp > ago({filter.NumberOfDays}d) | summarize uniqueSessions = dcount(session_Id) by bin(timestamp, 1d)";

return GetPerDayResult(query);
}

public Task<List<CountPerKey>> GetUserPerCountry(GlobalFilter filter)
{
var queryFilter = GetFilter(filter);
Expand Down
4 changes: 4 additions & 0 deletions TinyInsights.sln
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Web", "Web", "{0BF7F7D7-1ECA-4A2E-876C-875A75F94BD7}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -46,7 +48,9 @@ Global
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{A40E4E36-924E-4AC5-A60D-5321D7CEA729} = {0BF7F7D7-1ECA-4A2E-876C-875A75F94BD7}
{606F1693-DAA1-4BEA-BF62-F21F0F509E75} = {C4F61F00-5DBB-4913-93EF-2D11D056B4C3}
{A803C1DB-22A0-4B48-A87E-D9815782547E} = {0BF7F7D7-1ECA-4A2E-876C-875A75F94BD7}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {B22FA052-C4FE-4685-B660-995482C7D251}
Expand Down

0 comments on commit 0b8d621

Please sign in to comment.