diff --git a/TinyInsights.Web/Services/InsightsService.Analytics.cs b/TinyInsights.Web/Services/InsightsService.Analytics.cs index f4d4236..bf9231b 100644 --- a/TinyInsights.Web/Services/InsightsService.Analytics.cs +++ b/TinyInsights.Web/Services/InsightsService.Analytics.cs @@ -56,7 +56,7 @@ public Task> GetUserPerCountry(GlobalFilter filter) public Task> GetUserPerLanguage(GlobalFilter filter) { var queryFilter = GetFilter(filter); - var query = $"pageViews | extend language = tostring(customDimensions.Language) | where{queryFilter} timestamp > ago({filter.NumberOfDays}d) | summarize PageViewsCount = dcount(user_Id) by language"; + var query = $"pageViews | extend language = tostring(customDimensions.Language) | where{queryFilter} timestamp > ago({filter.NumberOfDays}d) | summarize arg_max(timestamp, *) by user_Id | summarize PageViewsCount = dcount(user_Id) by language"; return GetPerKeyResult(query); } diff --git a/TinyInsights.Web/TinyInsights.Web.csproj b/TinyInsights.Web/TinyInsights.Web.csproj index 3e9b328..e1b5df5 100644 --- a/TinyInsights.Web/TinyInsights.Web.csproj +++ b/TinyInsights.Web/TinyInsights.Web.csproj @@ -4,8 +4,6 @@ net8.0 enable enable - - diff --git a/TinyInsights/ApplicationInsightsProvider.cs b/TinyInsights/ApplicationInsightsProvider.cs index d1f2cf3..97c4205 100644 --- a/TinyInsights/ApplicationInsightsProvider.cs +++ b/TinyInsights/ApplicationInsightsProvider.cs @@ -98,6 +98,11 @@ private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledEx } #endif + public void UpsertGlobalProperty(string key, string value) + { + client.Context.GlobalProperties[key] = value; + } + public void OverrideAnonymousUserId(string userId) { SetUserId(userId); diff --git a/TinyInsights/IInsights.cs b/TinyInsights/IInsights.cs index 504bba4..b61c428 100644 --- a/TinyInsights/IInsights.cs +++ b/TinyInsights/IInsights.cs @@ -4,6 +4,8 @@ public interface IInsights { void AddProvider(IInsightsProvider provider); + void UpsertGlobalProperty(string key, string value); + Task TrackErrorAsync(Exception ex, Dictionary? properties = null); Task TrackPageViewAsync(string viewName, Dictionary? properties = null); diff --git a/TinyInsights/IInsightsProvider.cs b/TinyInsights/IInsightsProvider.cs index a05da1c..817fdd7 100644 --- a/TinyInsights/IInsightsProvider.cs +++ b/TinyInsights/IInsightsProvider.cs @@ -8,6 +8,8 @@ public interface IInsightsProvider bool IsTrackEventsEnabled { get; set; } bool IsTrackDependencyEnabled { get; set; } + void UpsertGlobalProperty(string key, string value); + Task TrackErrorAsync(Exception ex, Dictionary? properties = null); Task TrackPageViewAsync(string viewName, Dictionary? properties = null); diff --git a/TinyInsights/Insights.cs b/TinyInsights/Insights.cs index f831fc8..9199b32 100644 --- a/TinyInsights/Insights.cs +++ b/TinyInsights/Insights.cs @@ -4,6 +4,14 @@ public class Insights : IInsights { private readonly List insightsProviders = new(); + public void UpsertGlobalProperty(string key, string value) + { + foreach(var provider in insightsProviders.Where(x => x.IsTrackErrorsEnabled)) + { + provider.UpsertGlobalProperty(key, value); + } + } + public void AddProvider(IInsightsProvider provider) { insightsProviders.Add(provider);