From 7d156f3511cf8aa076b05d8392cc9553b3b5fbaa Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:31:24 +0000 Subject: [PATCH 1/9] Initial plan From 194a5648d4135460dc18a6d24cbec00e5438441a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:36:01 +0000 Subject: [PATCH 2/9] Migrate Application Insights to v3 with OpenTelemetry Co-authored-by: dpvreony <170983+dpvreony@users.noreply.github.com> --- src/Directory.Packages.props | 2 +- .../ApplicationInsightsViewTracking.cs | 51 ++++++++++++------- .../ApplicationInsightsViewTrackingTests.cs | 12 ++--- 3 files changed, 37 insertions(+), 28 deletions(-) diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index c950ffba8..6168eaef0 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -10,7 +10,7 @@ - + diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index e4676648d..0dabcecac 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -3,8 +3,7 @@ // ReactiveUI licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using Microsoft.ApplicationInsights; -using Microsoft.ApplicationInsights.DataContracts; +using System.Diagnostics; using Splat.ApplicationPerformanceMonitoring; @@ -13,27 +12,43 @@ namespace Splat; /// /// Provides view tracking functionality that records page view navigation events using Application Insights telemetry. /// -/// This class is typically used to integrate view navigation tracking into applications that utilize -/// Application Insights for telemetry. It implements the IViewTracking interface to standardize view tracking across -/// different telemetry providers. -/// The Application Insights telemetry client used to send page view tracking data. Cannot be null. -public sealed class ApplicationInsightsViewTracking(TelemetryClient telemetryClient) : IViewTracking +/// +/// This class uses OpenTelemetry Activities with ActivityKind.Server to track view navigation in Application Insights v3. +/// Activities appear as requests in Application Insights, with the duration automatically tracked from activity start to stop. +/// The implementation follows semantic conventions for HTTP requests while adding custom tags for view-specific filtering. +/// +/// The OpenTelemetry ActivitySource used to create activities for tracking page views. Cannot be null. +public sealed class ApplicationInsightsViewTracking(ActivitySource activitySource) : IViewTracking { + private Activity? _currentPageActivity; + /// /// Track a view navigation using just a name. /// /// Name of the view. - public void OnViewNavigation(string name) => telemetryClient.TrackPageView(name); - - /// - /// Track a View Navigation with Extended Data. - /// - /// Telemetry data. - public void OnViewNavigation(PageViewTelemetry telemetry) + public void OnViewNavigation(string name) { - _ = GetPageViewTelemetry(); - telemetryClient.TrackPageView(telemetry); - } + // Stop the previous page view activity if one exists + _currentPageActivity?.Stop(); + + // Start a new activity for the current page view + // ActivityKind.Server ensures it appears as a request in Application Insights + _currentPageActivity = activitySource.StartActivity( + name: $"PageView: {name}", + kind: ActivityKind.Server); - internal static PageViewTelemetry GetPageViewTelemetry() => new(); + if (_currentPageActivity is not null) + { + // Add standard HTTP semantic convention tags + _currentPageActivity.SetTag("http.url", $"view://{name}") + .SetTag("http.method", "GET") + .SetTag("http.scheme", "view") + .SetTag("url.scheme", "view") + .SetTag("url.path", $"/{name}") + + // Add custom tags for filtering and analysis + .SetTag("view.name", name) + .SetTag("view.type", "page"); + } + } } diff --git a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs index 5f309050f..3a95e9453 100644 --- a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs +++ b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs @@ -3,8 +3,7 @@ // ReactiveUI licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using Microsoft.ApplicationInsights; -using Microsoft.ApplicationInsights.Extensibility; +using System.Diagnostics; namespace Splat.Tests.ApplicationPerformanceMonitoring; @@ -20,13 +19,8 @@ public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod< /// protected override ApplicationInsightsViewTracking GetViewTracking() { - var telemetryConfiguration = new TelemetryConfiguration - { - DisableTelemetry = true, - }; - var telemetryClient = new TelemetryClient(telemetryConfiguration); - - return new(telemetryClient); + var activitySource = new ActivitySource("Splat.ApplicationInsights.Tests"); + return new(activitySource); } } } From aad4a94945a716dccc01d8be2e82a1fe5fce3ae0 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Feb 2026 09:40:48 +0000 Subject: [PATCH 3/9] Add thread-safety documentation to ApplicationInsightsViewTracking Co-authored-by: dpvreony <170983+dpvreony@users.noreply.github.com> --- src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index 0dabcecac..62b624b1a 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -16,6 +16,7 @@ namespace Splat; /// This class uses OpenTelemetry Activities with ActivityKind.Server to track view navigation in Application Insights v3. /// Activities appear as requests in Application Insights, with the duration automatically tracked from activity start to stop. /// The implementation follows semantic conventions for HTTP requests while adding custom tags for view-specific filtering. +/// This class is not thread-safe; each instance should be used on a single thread. /// /// The OpenTelemetry ActivitySource used to create activities for tracking page views. Cannot be null. public sealed class ApplicationInsightsViewTracking(ActivitySource activitySource) : IViewTracking From b1352fea1a522f264154103893a7beba875a820f Mon Sep 17 00:00:00 2001 From: David Vreony Date: Wed, 11 Feb 2026 09:53:34 +0000 Subject: [PATCH 4/9] remove thread safety issue --- .../ApplicationInsightsViewTracking.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index 62b624b1a..aceee674c 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -16,12 +16,11 @@ namespace Splat; /// This class uses OpenTelemetry Activities with ActivityKind.Server to track view navigation in Application Insights v3. /// Activities appear as requests in Application Insights, with the duration automatically tracked from activity start to stop. /// The implementation follows semantic conventions for HTTP requests while adding custom tags for view-specific filtering. -/// This class is not thread-safe; each instance should be used on a single thread. /// /// The OpenTelemetry ActivitySource used to create activities for tracking page views. Cannot be null. public sealed class ApplicationInsightsViewTracking(ActivitySource activitySource) : IViewTracking { - private Activity? _currentPageActivity; + private readonly ActivitySource _activitySource = activitySource ?? throw new ArgumentNullException(nameof(activitySource)); /// /// Track a view navigation using just a name. @@ -29,27 +28,24 @@ public sealed class ApplicationInsightsViewTracking(ActivitySource activitySourc /// Name of the view. public void OnViewNavigation(string name) { - // Stop the previous page view activity if one exists - _currentPageActivity?.Stop(); + var tags = new KeyValuePair[] + { + new("http.url", $"view://{name}"), + new("http.method", "GET"), + new("http.scheme", "view"), + new("url.scheme", "view"), + new("url.path", $"/{name}"), + new("view.name", name), + new("view.type", "page") + }; // Start a new activity for the current page view // ActivityKind.Server ensures it appears as a request in Application Insights - _currentPageActivity = activitySource.StartActivity( - name: $"PageView: {name}", - kind: ActivityKind.Server); - - if (_currentPageActivity is not null) - { - // Add standard HTTP semantic convention tags - _currentPageActivity.SetTag("http.url", $"view://{name}") - .SetTag("http.method", "GET") - .SetTag("http.scheme", "view") - .SetTag("url.scheme", "view") - .SetTag("url.path", $"/{name}") + var activity = _activitySource.StartActivity( + kind: ActivityKind.Server, + tags: tags, + name: $"PageView: {name}"); - // Add custom tags for filtering and analysis - .SetTag("view.name", name) - .SetTag("view.type", "page"); - } + activity?.Stop(); } } From c89045bac85d1e81b311d9ffed281049bde15159 Mon Sep 17 00:00:00 2001 From: David Vreony Date: Wed, 11 Feb 2026 10:44:25 +0000 Subject: [PATCH 5/9] fake connectionstring to deal with DisableTelemetry bug in v3 --- .../ApplicationInsightsFeatureUsageTrackingSessionTests.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsFeatureUsageTrackingSessionTests.cs b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsFeatureUsageTrackingSessionTests.cs index c12896712..0ea9297f7 100644 --- a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsFeatureUsageTrackingSessionTests.cs +++ b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsFeatureUsageTrackingSessionTests.cs @@ -25,6 +25,7 @@ protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsag var telemetryConfiguration = new TelemetryConfiguration { DisableTelemetry = true, + ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000", }; var telemetryClient = new TelemetryClient(telemetryConfiguration); @@ -42,6 +43,7 @@ protected override ApplicationInsightsFeatureUsageTrackingSession GetFeatureUsag var telemetryConfiguration = new TelemetryConfiguration { DisableTelemetry = true, + ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000", }; var telemetryClient = new TelemetryClient(telemetryConfiguration); From cb5117f5bdcbf139c6b19ac3561b25674ff3d766 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Sun, 15 Feb 2026 15:27:40 +1100 Subject: [PATCH 6/9] Replace ActivitySource view tracking with TelemetryClient.TrackEvent for AppInsights v3 ApplicationInsights v3 removed TrackPageView/PageViewTelemetry with no official replacement. The prior commit used ActivitySource which introduced fake HTTP semantics, silent null activities, zero-duration telemetry, and a breaking constructor change from TelemetryClient to ActivitySource. Replace with TelemetryClient.TrackEvent("PageView", {Name: viewName}) which: - Preserves the existing TelemetryClient constructor (non-breaking) - Stays consistent with how feature tracking already uses TelemetryClient - Matches the AppCenter and Exceptionless view tracking patterns - Records reliably without requiring ActivityListener configuration Also adds XML documentation to all undocumented members in the ApplicationInsights project. --- ...tionInsightsFeatureUsageTrackingSession.cs | 23 +++++++++- .../ApplicationInsightsViewTracking.cs | 45 +++++-------------- .../ApplicationInsightsViewTrackingTests.cs | 17 ++++--- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs b/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs index a0338423b..446248c38 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsFeatureUsageTrackingSession.cs @@ -20,13 +20,16 @@ namespace Splat.ApplicationInsights; /// should be used on a single thread. public sealed class ApplicationInsightsFeatureUsageTrackingSession : IFeatureUsageTrackingSession { + /// + /// The Application Insights telemetry client used to send events and exceptions. + /// private readonly TelemetryClient _telemetryClient; /// /// Initializes a new instance of the class. /// - /// The name of the feature. - /// The Application Insights telemetry client instance to use. + /// The name of the feature being tracked. + /// The Application Insights telemetry client instance to use for sending telemetry data. public ApplicationInsightsFeatureUsageTrackingSession( string featureName, TelemetryClient telemetryClient) @@ -34,6 +37,13 @@ public ApplicationInsightsFeatureUsageTrackingSession( { } + /// + /// Initializes a new instance of the class + /// with a parent reference for sub-feature tracking. + /// + /// The name of the feature being tracked. + /// The unique identifier of the parent feature session, or if this is a top-level session. + /// The Application Insights telemetry client instance to use for sending telemetry data. internal ApplicationInsightsFeatureUsageTrackingSession( string featureName, Guid parentReference, @@ -75,6 +85,10 @@ public void OnException(Exception exception) _telemetryClient.TrackException(telemetry); } + /// + /// Tracks a feature usage event with the specified event name to Application Insights. + /// + /// The name of the event to track (e.g., "Feature Usage Start" or "Feature Usage End"). private void TrackEvent(string eventName) { var eventTelemetry = new EventTelemetry(eventName); @@ -83,6 +97,11 @@ private void TrackEvent(string eventName) _telemetryClient.TrackEvent(eventTelemetry); } + /// + /// Populates the standard feature tracking properties on a telemetry item. + /// + /// The type of telemetry item that supports custom properties. + /// The telemetry item to populate with feature name, reference, and optional parent reference properties. private void PrepareEventData(TTelemetry eventTelemetry) where TTelemetry : ISupportProperties { diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index aceee674c..08d69b466 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -1,9 +1,9 @@ -// Copyright (c) 2026 ReactiveUI. All rights reserved. +// Copyright (c) 2026 ReactiveUI. All rights reserved. // Licensed to ReactiveUI under one or more agreements. // ReactiveUI licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System.Diagnostics; +using Microsoft.ApplicationInsights; using Splat.ApplicationPerformanceMonitoring; @@ -12,40 +12,19 @@ namespace Splat; /// /// Provides view tracking functionality that records page view navigation events using Application Insights telemetry. /// -/// -/// This class uses OpenTelemetry Activities with ActivityKind.Server to track view navigation in Application Insights v3. -/// Activities appear as requests in Application Insights, with the duration automatically tracked from activity start to stop. -/// The implementation follows semantic conventions for HTTP requests while adding custom tags for view-specific filtering. -/// -/// The OpenTelemetry ActivitySource used to create activities for tracking page views. Cannot be null. -public sealed class ApplicationInsightsViewTracking(ActivitySource activitySource) : IViewTracking +/// This class is typically used to integrate view navigation tracking into applications that utilize +/// Application Insights for telemetry. It implements the IViewTracking interface to standardize view tracking across +/// different telemetry providers. In Application Insights v3, page views are tracked as custom events since the +/// PageViewTelemetry type has been removed. +/// The Application Insights telemetry client used to send page view tracking data. Cannot be null. +public sealed class ApplicationInsightsViewTracking(TelemetryClient telemetryClient) : IViewTracking { - private readonly ActivitySource _activitySource = activitySource ?? throw new ArgumentNullException(nameof(activitySource)); - /// /// Track a view navigation using just a name. /// /// Name of the view. - public void OnViewNavigation(string name) - { - var tags = new KeyValuePair[] - { - new("http.url", $"view://{name}"), - new("http.method", "GET"), - new("http.scheme", "view"), - new("url.scheme", "view"), - new("url.path", $"/{name}"), - new("view.name", name), - new("view.type", "page") - }; - - // Start a new activity for the current page view - // ActivityKind.Server ensures it appears as a request in Application Insights - var activity = _activitySource.StartActivity( - kind: ActivityKind.Server, - tags: tags, - name: $"PageView: {name}"); - - activity?.Stop(); - } + public void OnViewNavigation(string name) => + telemetryClient.TrackEvent( + "PageView", + new Dictionary { ["Name"] = name }); } diff --git a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs index 3a95e9453..0a5965ed7 100644 --- a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs +++ b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs @@ -1,14 +1,15 @@ -// Copyright (c) 2026 ReactiveUI. All rights reserved. +// Copyright (c) 2026 ReactiveUI. All rights reserved. // Licensed to ReactiveUI under one or more agreements. // ReactiveUI licenses this file to you under the MIT license. // See the LICENSE file in the project root for full license information. -using System.Diagnostics; +using Microsoft.ApplicationInsights; +using Microsoft.ApplicationInsights.Extensibility; namespace Splat.Tests.ApplicationPerformanceMonitoring; /// -/// Unit Tests for Application Insights Feature Usage Tracking. +/// Unit Tests for Application Insights View Tracking. /// public static class ApplicationInsightsViewTrackingTests { @@ -19,8 +20,14 @@ public sealed class ConstructorMethod : BaseViewTrackingTests.ConstructorMethod< /// protected override ApplicationInsightsViewTracking GetViewTracking() { - var activitySource = new ActivitySource("Splat.ApplicationInsights.Tests"); - return new(activitySource); + var telemetryConfiguration = new TelemetryConfiguration + { + DisableTelemetry = true, + ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000", + }; + var telemetryClient = new TelemetryClient(telemetryConfiguration); + + return new(telemetryClient); } } } From 4b3e46f5bd95e70e814e23ac65fac41f487b278b Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Sun, 15 Feb 2026 16:05:01 +1100 Subject: [PATCH 7/9] Add OnViewNavigation unit tests for ApplicationInsightsViewTracking Test that TrackEvent("PageView") is called without throwing for various inputs: normal view names, multiple consecutive navigations, empty names, and names with special characters. AppInsights v3 has no ITelemetryClient interface, no ITelemetryChannel, and TrackEvent does not emit interceptable OpenTelemetry Activities, so behavioral verification of the SDK call is not feasible. Tests verify the integration does not throw under expected usage patterns. --- .../ApplicationInsightsViewTrackingTests.cs | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs index 0a5965ed7..4da568abd 100644 --- a/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs +++ b/src/tests/Splat.ApplicationInsights.Tests/ApplicationInsightsViewTrackingTests.cs @@ -30,4 +30,84 @@ protected override ApplicationInsightsViewTracking GetViewTracking() return new(telemetryClient); } } + + /// + /// Tests for the method. + /// + public sealed class OnViewNavigationMethod + { + /// + /// Verifies that tracking a page view with a valid name does not throw. + /// + /// A representing the asynchronous operation. + [Test] + public async Task TracksPageView() + { + var viewTracking = CreateViewTracking(); + + viewTracking.OnViewNavigation("HomePage"); + + await Assert.That(viewTracking).IsNotNull(); + } + + /// + /// Verifies that tracking multiple consecutive page views does not throw. + /// + /// A representing the asynchronous operation. + [Test] + public async Task TracksMultiplePageViews() + { + var viewTracking = CreateViewTracking(); + + viewTracking.OnViewNavigation("HomePage"); + viewTracking.OnViewNavigation("SettingsPage"); + viewTracking.OnViewNavigation("ProfilePage"); + + await Assert.That(viewTracking).IsNotNull(); + } + + /// + /// Verifies that tracking a page view with an empty name does not throw. + /// + /// A representing the asynchronous operation. + [Test] + public async Task TracksEmptyViewName() + { + var viewTracking = CreateViewTracking(); + + viewTracking.OnViewNavigation(string.Empty); + + await Assert.That(viewTracking).IsNotNull(); + } + + /// + /// Verifies that tracking a page view with a name containing special characters does not throw. + /// + /// A representing the asynchronous operation. + [Test] + public async Task TracksViewNameWithSpecialCharacters() + { + var viewTracking = CreateViewTracking(); + + viewTracking.OnViewNavigation("Views/Home Page (Main)"); + + await Assert.That(viewTracking).IsNotNull(); + } + + /// + /// Creates an instance configured for testing. + /// + /// A new instance with telemetry disabled. + private static ApplicationInsightsViewTracking CreateViewTracking() + { + var telemetryConfiguration = new TelemetryConfiguration + { + DisableTelemetry = true, + ConnectionString = "InstrumentationKey=00000000-0000-0000-0000-000000000000", + }; + var telemetryClient = new TelemetryClient(telemetryConfiguration); + + return new(telemetryClient); + } + } } From e11d650f6161d693cddf7ef02e1e8b883c3f9b07 Mon Sep 17 00:00:00 2001 From: Glenn Watson Date: Sun, 15 Feb 2026 16:44:43 +1100 Subject: [PATCH 8/9] Use non-nullable dictionary for TrackEvent properties The name parameter is non-nullable and the v3 TrackEvent signature accepts IDictionary, so Dictionary was unnecessarily nullable. --- .../ApplicationInsightsViewTracking.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index 08d69b466..5f2a08ed6 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -26,5 +26,5 @@ public sealed class ApplicationInsightsViewTracking(TelemetryClient telemetryCli public void OnViewNavigation(string name) => telemetryClient.TrackEvent( "PageView", - new Dictionary { ["Name"] = name }); + new Dictionary { ["Name"] = name }); } From 504995185d617b7a6a9061444e24a670b3228277 Mon Sep 17 00:00:00 2001 From: David Vreony Date: Tue, 17 Feb 2026 09:04:50 +0000 Subject: [PATCH 9/9] add extended properties. adjust pagename based on BASE readme --- .../ApplicationInsightsViewTracking.cs | 25 +++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs index 5f2a08ed6..2c44cb117 100644 --- a/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs +++ b/src/Splat.ApplicationInsights/ApplicationInsightsViewTracking.cs @@ -23,8 +23,29 @@ public sealed class ApplicationInsightsViewTracking(TelemetryClient telemetryCli /// Track a view navigation using just a name. /// /// Name of the view. - public void OnViewNavigation(string name) => + public void OnViewNavigation(string name) => OnViewNavigation( + name, + new Dictionary()); + + /// + /// Track a view navigation using name and extended properties. + /// + /// + /// See https://github.com/microsoft/ApplicationInsights-dotnet/tree/main/BASE#tracking-page-views for details on underlying usage. + /// + /// Name of the view. + /// Set of extended properties to send with the event. NOTE: if you set PageName in the collection, it will be overridden using . + public void OnViewNavigation( + string name, + IDictionary extendedProperties) + { + // need to look at whether the standard properties of the Javascript SDK are supported in the .NET SDK (or rather the Azure Monitor when it rewrites the payload), but for now we'll just leave as minimal and allow injection by caller. + // reference: https://github.com/microsoft/ApplicationInsights-JS/blob/b6de144e27629b2d50e05ceb3885ee51b4fa0e2b/API-reference.md + extendedProperties ??= new Dictionary(); + extendedProperties["PageName"] = name; + telemetryClient.TrackEvent( "PageView", - new Dictionary { ["Name"] = name }); + extendedProperties); + } }