Skip to content

Commit 19e33de

Browse files
1 parent 58649b8 commit 19e33de

File tree

6 files changed

+107
-1
lines changed

6 files changed

+107
-1
lines changed

CommunityToolkit.App.Shared/App.xaml.cs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,13 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using Windows.UI;
5+
using CommunityToolkit.App.Shared.Helpers;
6+
7+
#if WINAPPSDK
8+
using UnhandledExceptionEventArgs = Microsoft.UI.Xaml.UnhandledExceptionEventArgs;
9+
#else
10+
using UnhandledExceptionEventArgs = Windows.UI.Xaml.UnhandledExceptionEventArgs;
11+
#endif
612

713
namespace CommunityToolkit.App.Shared;
814

@@ -26,6 +32,13 @@ public sealed partial class App : Application
2632
public App()
2733
{
2834
this.InitializeComponent();
35+
36+
UnhandledException += this.App_UnhandledException;
37+
}
38+
39+
private void App_UnhandledException(object sender, UnhandledExceptionEventArgs e)
40+
{
41+
TrackingManager.TrackException(e.Exception);
2942
}
3043

3144
/// <summary>

CommunityToolkit.App.Shared/CommunityToolkit.App.Shared.projitems

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
<Compile Include="$(MSBuildThisFileDirectory)DocOrSampleTemplateSelector.cs" />
3333
<Compile Include="$(MSBuildThisFileDirectory)Helpers\IconHelper.cs" />
3434
<Compile Include="$(MSBuildThisFileDirectory)Helpers\NavigationViewHelper.cs" />
35+
<Compile Include="$(MSBuildThisFileDirectory)Helpers\TrackingManager.cs" />
3536
<Compile Include="$(MSBuildThisFileDirectory)Pages\GettingStartedPage.xaml.cs">
3637
<DependentUpon>GettingStartedPage.xaml</DependentUpon>
3738
</Compile>
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
7+
#if !DEBUG && WINDOWS_UWP && !HAS_UNO
8+
// See https://learn.microsoft.com/windows/uwp/monetize/log-custom-events-for-dev-center
9+
using Microsoft.Services.Store.Engagement;
10+
#endif
11+
12+
namespace CommunityToolkit.App.Shared.Helpers;
13+
14+
#if DEBUG || !WINDOWS_UWP || HAS_UNO
15+
// Stub for non-UWP platforms and DEBUG mode
16+
internal class StoreServicesCustomEventLogger
17+
{
18+
public static StoreServicesCustomEventLogger GetDefault() => new();
19+
20+
public void Log(string message)
21+
{
22+
Debug.WriteLine($"Log - {message}");
23+
}
24+
}
25+
#endif
26+
27+
public static class TrackingManager
28+
{
29+
private static StoreServicesCustomEventLogger? logger;
30+
31+
static TrackingManager()
32+
{
33+
try
34+
{
35+
logger = StoreServicesCustomEventLogger.GetDefault();
36+
}
37+
catch
38+
{
39+
// Ignoring error
40+
}
41+
}
42+
43+
public static void TrackException(Exception ex)
44+
{
45+
try
46+
{
47+
logger?.Log($"exception - {ex.Message} - {ex.StackTrace}");
48+
}
49+
catch
50+
{
51+
// Ignore error
52+
}
53+
}
54+
55+
public static void TrackSample(string name)
56+
{
57+
try
58+
{
59+
logger?.Log($"sample - {name}");
60+
}
61+
catch
62+
{
63+
// Ignore error
64+
}
65+
}
66+
67+
public static void TrackPage(string pageName)
68+
{
69+
try
70+
{
71+
logger?.Log($"openpage - {pageName}");
72+
}
73+
catch
74+
{
75+
// Ignore error
76+
}
77+
}
78+
}

CommunityToolkit.App.Shared/Pages/Shell.xaml.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,20 +71,23 @@ private void NavView_ItemInvoked(MUXC.NavigationView sender, MUXC.NavigationView
7171
if (NavigationFrame.CurrentSourcePageType != typeof(SettingsPage))
7272
{
7373
NavigationFrame.Navigate(typeof(SettingsPage));
74+
TrackingManager.TrackPage("Settings");
7475
}
7576
}
7677

7778
// Check if Getting Started page
7879
else if (selectedItem.Tag != null && selectedItem.Tag.GetType() == typeof(string))
7980
{
8081
NavigationFrame.Navigate(typeof(GettingStartedPage), samplePages);
82+
TrackingManager.TrackPage("GettingStarted");
8183
}
8284
else
8385
{
8486
var selectedMetadata = selectedItem.Tag as ToolkitFrontMatter;
8587
if (selectedMetadata is null)
8688
return;
8789
NavigationFrame.Navigate(typeof(ToolkitDocumentationRenderer), selectedMetadata);
90+
TrackingManager.TrackSample(selectedMetadata.Title!);
8891
}
8992
}
9093

@@ -93,10 +96,12 @@ public void NavigateToSample(ToolkitFrontMatter? sample)
9396
if (sample is null)
9497
{
9598
NavigationFrame.Navigate(typeof(GettingStartedPage), samplePages);
99+
TrackingManager.TrackPage("GettingStarted");
96100
}
97101
else
98102
{
99103
NavigationFrame.Navigate(typeof(ToolkitDocumentationRenderer), sample);
104+
TrackingManager.TrackSample(sample.Title!);
100105
}
101106

102107
EnsureNavigationSelection(sample?.FilePath);

ProjectHeads/AllComponents/Uwp/CommunityToolkit.App.Uwp.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
<WinUIMajorVersion>2</WinUIMajorVersion>
1111

1212
<IsAllExperimentHead>true</IsAllExperimentHead>
13+
<AppxBundle>Always</AppxBundle>
14+
<AppxBundlePlatforms>x86|x64|arm64</AppxBundlePlatforms>
1315
</PropertyGroup>
1416

1517
<Import Project="$(ToolingDirectory)\MultiTarget\EnabledTargetFrameworks.props" />

ProjectHeads/App.Head.Uwp.Dependencies.props

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,11 @@
66
<PackageReference Include="Microsoft.Xaml.Behaviors.Uwp.Managed" Version="3.0.0" />
77
<PackageReference Include="System.Collections.Immutable" Version="9.0.0" />
88
</ItemGroup>
9+
10+
<ItemGroup Condition=" '$(Configuration)' == 'Release' ">
11+
<PackageReference Include="Microsoft.Services.Store.Engagement" Version="10.2307.3001" />
12+
<SDKReference Include="Microsoft.Services.Store.Engagement, Version=10.0">
13+
<Name>Microsoft Engagement Framework</Name>
14+
</SDKReference>
15+
</ItemGroup>
916
</Project>

0 commit comments

Comments
 (0)