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

Automatic page view tracking #14

Closed
wants to merge 14 commits into from
50 changes: 34 additions & 16 deletions TinyInsights.TestApp/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -1,22 +1,40 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TinyInsights.TestApp.MainPage">
<ContentPage
x:Class="TinyInsights.TestApp.MainPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml">

<ScrollView Padding="20">
<VerticalStackLayout
Spacing="25">
<HorizontalStackLayout Spacing="10">

<Switch IsToggled="{Binding UseILogger, Mode=TwoWay}" />
<Label Text="Use ILogger" />
</HorizontalStackLayout>
<Button x:Name="PageViewButton" Text="Track page view" Clicked="PageViewButton_OnClicked" />

<Button x:Name="EventButton" Text="Track event" Clicked="EventButton_OnClicked" />
<Button x:Name="ExceptionButton" Text="Track exception" Clicked="ExceptionButton_OnClicked" />
<Button x:Name="TrackHttpButton" Text="Track http request" Clicked="TrackHttpButton_OnClicked" />
<Button x:Name="CrashButtom" Text="Crash app" Clicked="CrashButtom_OnClicked" />
<VerticalStackLayout Spacing="25">
<HorizontalStackLayout Spacing="10">

<Switch IsToggled="{Binding UseILogger, Mode=TwoWay}" />
<Label Text="Use ILogger" />
</HorizontalStackLayout>
<Button
x:Name="PageViewButton"
Clicked="PageViewButton_OnClicked"
Text="Track page view" />

<Button
x:Name="EventButton"
Clicked="EventButton_OnClicked"
Text="Track event" />
<Button
x:Name="ExceptionButton"
Clicked="ExceptionButton_OnClicked"
Text="Track exception" />
<Button
x:Name="TrackHttpButton"
Clicked="TrackHttpButton_OnClicked"
Text="Track http request" />
<Button
x:Name="CrashButtom"
Clicked="CrashButtom_OnClicked"
Text="Crash app" />
<Button Clicked="NewPageButton_Clicked" Text="Test page automatic page tracking" />

<Button Clicked="Button_Clicked" Text="clear gc" />
</VerticalStackLayout>
</ScrollView>

Expand Down
13 changes: 11 additions & 2 deletions TinyInsights.TestApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Logging;
using System.Diagnostics;

namespace TinyInsights.TestApp;

Expand All @@ -18,8 +19,6 @@ public MainPage(IInsights insights, InsightsMessageHandler insightsMessageHandle
insights.OverrideAnonymousUserId("TestUser");

InitializeComponent();


}

private bool useILogger;
Expand Down Expand Up @@ -95,4 +94,14 @@ private void CrashButtom_OnClicked(object? sender, EventArgs e)
{
throw new Exception("Crash Boom Bang!");
}

private async void NewPageButton_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new NewPage());
}

private void Button_Clicked(object sender, EventArgs e)
{
Debug.WriteLine($"Memory: {GC.GetTotalMemory(true)}");
}
}
9 changes: 6 additions & 3 deletions TinyInsights.TestApp/MauiProgram.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,14 @@ public static MauiApp CreateMauiApp()
.UseTinyInsights("InstrumentationKey=8b51208f-7926-4b7b-9867-16989206b950;IngestionEndpoint=https://swedencentral-0.in.applicationinsights.azure.com/;ApplicationId=0c04d3a0-9ee2-41a5-996e-526552dc730f",
(provider) =>
{
provider.IsTrackDependencyEnabled = true;
provider.IsTrackEventsEnabled = true;
provider.IsTrackErrorsEnabled = true;
provider.IsTrackPageViewsEnabled = true;
provider.IsTrackCrashesEnabled = true;
provider.IsTrackPageViewsEnabled = true;
provider.IsAutoTrackPageViewsEnabled = true;
provider.IsTrackEventsEnabled = true;
provider.IsTrackDependencyEnabled = true;
provider.IsAutoTrackPageViewsEnabled = true;
;
})
.UseTinyInsightsAsILogger("InstrumentationKey=8b51208f-7926-4b7b-9867-16989206b950;IngestionEndpoint=https://swedencentral-0.in.applicationinsights.azure.com/;ApplicationId=0c04d3a0-9ee2-41a5-996e-526552dc730f");

Expand Down
15 changes: 15 additions & 0 deletions TinyInsights.TestApp/NewPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage
x:Class="TinyInsights.TestApp.NewPage"
xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
Title="NewPage">
<VerticalStackLayout>
<Label
HorizontalOptions="Center"
Text="Welcome to .NET MAUI!"
VerticalOptions="Center" />

<Button Clicked="Button_Clicked" Text="Next page" />
</VerticalStackLayout>
</ContentPage>
28 changes: 28 additions & 0 deletions TinyInsights.TestApp/NewPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Diagnostics;

namespace TinyInsights.TestApp;

public partial class NewPage : ContentPage
{
public NewPage()
{
InitializeComponent();

Appearing += (_,_) =>
{
Debug.WriteLine("NewPage Appearing event");
};
}

protected override void OnAppearing()
{
base.OnAppearing();

Debug.WriteLine("NewPage OnAppearing override");
}

private async void Button_Clicked(object sender, EventArgs e)
{
await Navigation.PushAsync(new NewPage1());
}
}
12 changes: 12 additions & 0 deletions TinyInsights.TestApp/NewPage1.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="TinyInsights.TestApp.NewPage1"
Title="NewPage1">
<VerticalStackLayout>
<Label
Text="Welcome to .NET MAUI!"
VerticalOptions="Center"
HorizontalOptions="Center" />
</VerticalStackLayout>
</ContentPage>
9 changes: 9 additions & 0 deletions TinyInsights.TestApp/NewPage1.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TinyInsights.TestApp;

public partial class NewPage1 : ContentPage
{
public NewPage1()
{
InitializeComponent();
}
}
27 changes: 18 additions & 9 deletions TinyInsights.TestApp/TinyInsights.TestApp.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,30 +39,39 @@

<ItemGroup>
<!-- App Icon -->
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4"/>
<MauiIcon Include="Resources\AppIcon\appicon.svg" ForegroundFile="Resources\AppIcon\appiconfg.svg" Color="#512BD4" />

<!-- Splash Screen -->
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128"/>
<MauiSplashScreen Include="Resources\Splash\splash.svg" Color="#512BD4" BaseSize="128,128" />

<!-- Images -->
<MauiImage Include="Resources\Images\*"/>
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185"/>
<MauiImage Include="Resources\Images\*" />
<MauiImage Update="Resources\Images\dotnet_bot.png" Resize="True" BaseSize="300,185" />

<!-- Custom Fonts -->
<MauiFont Include="Resources\Fonts\*"/>
<MauiFont Include="Resources\Fonts\*" />

<!-- Raw Assets (also remove the "Resources\Raw" prefix) -->
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)"/>
<MauiAsset Include="Resources\Raw\**" LogicalName="%(RecursiveDir)%(Filename)%(Extension)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)"/>
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0"/>
<PackageReference Include="Microsoft.Maui.Controls" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Maui.Controls.Compatibility" Version="$(MauiVersion)" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\TinyInsights\TinyInsights.csproj" />
</ItemGroup>

<ItemGroup>
<MauiXaml Update="NewPage.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
<MauiXaml Update="NewPage1.xaml">
<Generator>MSBuild:Compile</Generator>
</MauiXaml>
</ItemGroup>

</Project>
77 changes: 40 additions & 37 deletions TinyInsights.Web/Pages/ErrorDetails.razor
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
@page "/diagnostics/crashes/details/{*Id}"
@page "/diagnostics/errors/details/{*Id}"
@using System.Web
@using System.Text.RegularExpressions

@inherits TinyInsightsComponentBase

@inject IInsightsService Service
@inject DialogService DialogService


<RadzenStack>
<RadzenRow JustifyContent="JustifyContent.SpaceBetween" AlignItems="AlignItems.Center">
<a href="@backUrl" title="Back">
<RadzenIcon Icon="arrow_back"/>
<RadzenIcon Icon="arrow_back" />
</a>
<GlobalFilters />

Expand All @@ -20,53 +23,53 @@

@if (isLoading)
{
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate"/>
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
}
else
{
<RadzenStack Orientation="Orientation.Horizontal" Wrap="FlexWrap.Wrap" Gap="20px">
<LabelValuePair Key="Count" Value="@data.Count.ToString()"/>
<LabelValuePair Key="Affected users" Value="@data.AffectedUsersCount.ToString()"/>
<LabelValuePair Key="Affected app versions" Value="@(string.Join(", ", data.AffectedAppVersions))"/>
<LabelValuePair Key="Affected operating systems" Value="@(string.Join(", ", data.AffectedOperatingSystems))"/>
<LabelValuePair Key="Count" Value="@data.Count.ToString()" />
<LabelValuePair Key="Affected users" Value="@data.AffectedUsersCount.ToString()" />
<LabelValuePair Key="Affected app versions" Value="@(string.Join(", ", data.AffectedAppVersions))" />
<LabelValuePair Key="Affected operating systems" Value="@(string.Join(", ", data.AffectedOperatingSystems))" />
</RadzenStack>
}

</RadzenCard>
<RadzenCard>
<h2>Message</h2>
<h2>Message</h2>
@if (isLoading)
{
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate"/>
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
}
else
{
<p class="stacktrace">
@if (data.Items.Count > 0 && data.Items.First().Message is not null)
{
@data.Items.First().Message

}
else
{
<span>No message available</span>
}
</p>
}
@if (data.Items.Count > 0 && data.Items.First().Message is not null)
{
@data.Items.First().Message
}
else
{
<span>No message available</span>
}
</p>
}
</RadzenCard>
<RadzenCard>
<h2>Stacktrace</h2>
@if (isLoading)
{
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate"/>
}
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
}
else
{
<p class="stacktrace">
@if (data.Items.Count > 0 && data.Items.First().StackTrace is not null)
{
@data.Items.First().StackTrace

<code>
@((MarkupString)Regex.Replace(HttpUtility.HtmlEncode(@data.Items.First().StackTrace ?? string.Empty), "\r?\n|\r", "<br />"));
</code>
}
else
{
Expand All @@ -79,25 +82,25 @@
<h2>@listHeader</h2>
@if (isLoading)
{
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate"/>
<RadzenProgressBarCircular Value="100" ShowValue="false" Mode="ProgressBarMode.Indeterminate" />
}
else
{
<RadzenDataGrid Data="data.Items">
<Columns>
<RadzenDataGridColumn TItem="ErrorItem" Title="Timestamp" Property="@nameof(ErrorItem.Timestamp)"/>
<RadzenDataGridColumn TItem="ErrorItem" Title="Device" Property="@nameof(ErrorItem.ClientModel)"/>
<RadzenDataGridColumn TItem="ErrorItem" Title="Device OS" Property="@nameof(ErrorItem.ClientOs)"/>
<RadzenDataGridColumn TItem="ErrorItem" Title="Device OS version" Property="@nameof(ErrorItem.ClientOsVersion)"/>
<RadzenDataGridColumn TItem="ErrorItem" Title="Country" Property="@nameof(ErrorItem.ClientCountry)"/>
<RadzenDataGridColumn TItem="ErrorItem" Title="Timestamp" Property="@nameof(ErrorItem.Timestamp)" />
<RadzenDataGridColumn TItem="ErrorItem" Title="Device" Property="@nameof(ErrorItem.ClientModel)" />
<RadzenDataGridColumn TItem="ErrorItem" Title="Device OS" Property="@nameof(ErrorItem.ClientOs)" />
<RadzenDataGridColumn TItem="ErrorItem" Title="Device OS version" Property="@nameof(ErrorItem.ClientOsVersion)" />
<RadzenDataGridColumn TItem="ErrorItem" Title="Country" Property="@nameof(ErrorItem.ClientCountry)" />
<RadzenDataGridColumn TItem="ErrorItem" Width="100px">
<Template>
<RadzenButton Icon="description" Click="@(async (args) => await ShowAllProperties(context))"/>
<RadzenButton Icon="description" Click="@(async (args) => await ShowAllProperties(context))" />
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="ErrorItem" Width="100px">
<Template>
<RadzenButton Icon="format_list_numbered" Click="@(async (args) => await ShowEvents(context))"/>
<RadzenButton Icon="format_list_numbered" Click="@(async (args) => await ShowEvents(context))" />
</Template>
</RadzenDataGridColumn>
</Columns>
Expand All @@ -110,16 +113,16 @@
@code {
[Parameter]
public required string Id { get; set; }

[CascadingParameter]
public required GlobalFilter GlobalFilter { get; set; }

private bool isLoading = true;
private bool isCrash;
private string backUrl = string.Empty,detailsHeader = string.Empty, listHeader = string.Empty;
private string backUrl = string.Empty, detailsHeader = string.Empty, listHeader = string.Empty;

private Services.Models.ErrorDetails data = new();

protected override async Task OnParametersSetAsync()
{
await base.OnParametersSetAsync();
Expand Down Expand Up @@ -162,14 +165,14 @@
{
await DialogService.OpenAsync<AllProperties>($"All properties",
new Dictionary<string, object>() { { "Properties", item.Data } },
new DialogOptions() { Width = "700px", Height = "512px", Resizable = true, Draggable = true});
new DialogOptions() { Width = "700px", Height = "512px", Resizable = true, Draggable = true });
}

private async Task ShowEvents(ErrorItem item)
{
await DialogService.OpenAsync<Events>($"Recent events",
new Dictionary<string, object>() { { "UserId", item.UserId }, { "Timestamp", item.Timestamp } },
new DialogOptions() { Width = "700px", Height = "512px", Resizable = true, Draggable = true});
new DialogOptions() { Width = "700px", Height = "512px", Resizable = true, Draggable = true });
}
}

Loading
Loading