Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add or update global properties #13

Merged
merged 2 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion TinyInsights.Web/Services/InsightsService.Analytics.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public Task<List<CountPerKey>> GetUserPerCountry(GlobalFilter filter)
public Task<List<CountPerKey>> 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);
}
Expand Down
2 changes: 0 additions & 2 deletions TinyInsights.Web/TinyInsights.Web.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>


</PropertyGroup>

<ItemGroup>
Expand Down
5 changes: 5 additions & 0 deletions TinyInsights/ApplicationInsightsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
public bool IsTrackDependencyEnabled { get; set; } = true;

#if IOS || MACCATALYST || ANDROID
public ApplicationInsightsProvider(string connectionString)

Check warning on line 28 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'client' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 28 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'client' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.

Check warning on line 28 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable field 'client' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the field as nullable.
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
TaskScheduler.UnobservedTaskException += TaskScheduler_UnobservedTaskException;

Check warning on line 31 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void ApplicationInsightsProvider.TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)' doesn't match the target delegate 'EventHandler<UnobservedTaskExceptionEventArgs>' (possibly because of nullability attributes).

Check warning on line 31 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void ApplicationInsightsProvider.TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)' doesn't match the target delegate 'EventHandler<UnobservedTaskExceptionEventArgs>' (possibly because of nullability attributes).

Check warning on line 31 in TinyInsights/ApplicationInsightsProvider.cs

View workflow job for this annotation

GitHub Actions / build

Nullability of reference types in type of parameter 'sender' of 'void ApplicationInsightsProvider.TaskScheduler_UnobservedTaskException(object sender, UnobservedTaskExceptionEventArgs e)' doesn't match the target delegate 'EventHandler<UnobservedTaskExceptionEventArgs>' (possibly because of nullability attributes).

var configuration = new TelemetryConfiguration()
{
Expand Down Expand Up @@ -98,6 +98,11 @@
}
#endif

public void UpsertGlobalProperty(string key, string value)
{
client.Context.GlobalProperties[key] = value;
}

public void OverrideAnonymousUserId(string userId)
{
SetUserId(userId);
Expand Down
2 changes: 2 additions & 0 deletions TinyInsights/IInsights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public interface IInsights
{
void AddProvider(IInsightsProvider provider);

void UpsertGlobalProperty(string key, string value);

Task TrackErrorAsync(Exception ex, Dictionary<string, string>? properties = null);

Task TrackPageViewAsync(string viewName, Dictionary<string, string>? properties = null);
Expand Down
2 changes: 2 additions & 0 deletions TinyInsights/IInsightsProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>? properties = null);

Task TrackPageViewAsync(string viewName, Dictionary<string, string>? properties = null);
Expand Down
8 changes: 8 additions & 0 deletions TinyInsights/Insights.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ public class Insights : IInsights
{
private readonly List<IInsightsProvider> 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);
Expand Down
Loading