From 368a172b0a31734040729d0f7f58e88bb14c4521 Mon Sep 17 00:00:00 2001 From: Ieuan Walker Date: Wed, 21 Aug 2024 17:20:36 +0100 Subject: [PATCH 1/2] update --- TinyInsights.Web/Services/InsightsService.Analytics.cs | 2 +- TinyInsights.Web/TinyInsights.Web.csproj | 2 -- TinyInsights/ApplicationInsightsProvider.cs | 5 +++++ TinyInsights/IInsights.cs | 2 ++ TinyInsights/IInsightsProvider.cs | 2 ++ TinyInsights/Insights.cs | 8 ++++++++ 6 files changed, 18 insertions(+), 3 deletions(-) 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..7eb2ea5 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 AddGlobalProperty(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..f9d6760 100644 --- a/TinyInsights/IInsights.cs +++ b/TinyInsights/IInsights.cs @@ -4,6 +4,8 @@ public interface IInsights { void AddProvider(IInsightsProvider provider); + void AddGlobalProperty(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..44f78e4 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 AddGlobalProperty(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..7c770f6 100644 --- a/TinyInsights/Insights.cs +++ b/TinyInsights/Insights.cs @@ -4,6 +4,14 @@ public class Insights : IInsights { private readonly List insightsProviders = new(); + public void AddGlobalProperty(string key, string value) + { + foreach(var provider in insightsProviders.Where(x => x.IsTrackErrorsEnabled)) + { + provider.AddGlobalProperty(key, value); + } + } + public void AddProvider(IInsightsProvider provider) { insightsProviders.Add(provider); From 7ba290e5726521548e407e6a3c81320481fcc453 Mon Sep 17 00:00:00 2001 From: Ieuan Walker Date: Wed, 21 Aug 2024 17:34:14 +0100 Subject: [PATCH 2/2] renamed method --- TinyInsights/ApplicationInsightsProvider.cs | 2 +- TinyInsights/IInsights.cs | 2 +- TinyInsights/IInsightsProvider.cs | 2 +- TinyInsights/Insights.cs | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/TinyInsights/ApplicationInsightsProvider.cs b/TinyInsights/ApplicationInsightsProvider.cs index 7eb2ea5..97c4205 100644 --- a/TinyInsights/ApplicationInsightsProvider.cs +++ b/TinyInsights/ApplicationInsightsProvider.cs @@ -98,7 +98,7 @@ private void App_UnhandledException(object sender, Microsoft.UI.Xaml.UnhandledEx } #endif - public void AddGlobalProperty(string key, string value) + public void UpsertGlobalProperty(string key, string value) { client.Context.GlobalProperties[key] = value; } diff --git a/TinyInsights/IInsights.cs b/TinyInsights/IInsights.cs index f9d6760..b61c428 100644 --- a/TinyInsights/IInsights.cs +++ b/TinyInsights/IInsights.cs @@ -4,7 +4,7 @@ public interface IInsights { void AddProvider(IInsightsProvider provider); - void AddGlobalProperty(string key, string value); + void UpsertGlobalProperty(string key, string value); Task TrackErrorAsync(Exception ex, Dictionary? properties = null); diff --git a/TinyInsights/IInsightsProvider.cs b/TinyInsights/IInsightsProvider.cs index 44f78e4..817fdd7 100644 --- a/TinyInsights/IInsightsProvider.cs +++ b/TinyInsights/IInsightsProvider.cs @@ -8,7 +8,7 @@ public interface IInsightsProvider bool IsTrackEventsEnabled { get; set; } bool IsTrackDependencyEnabled { get; set; } - void AddGlobalProperty(string key, string value); + void UpsertGlobalProperty(string key, string value); Task TrackErrorAsync(Exception ex, Dictionary? properties = null); diff --git a/TinyInsights/Insights.cs b/TinyInsights/Insights.cs index 7c770f6..9199b32 100644 --- a/TinyInsights/Insights.cs +++ b/TinyInsights/Insights.cs @@ -4,11 +4,11 @@ public class Insights : IInsights { private readonly List insightsProviders = new(); - public void AddGlobalProperty(string key, string value) + public void UpsertGlobalProperty(string key, string value) { foreach(var provider in insightsProviders.Where(x => x.IsTrackErrorsEnabled)) { - provider.AddGlobalProperty(key, value); + provider.UpsertGlobalProperty(key, value); } }