From 2194ae3c712ca7cb3a17f808ebfa3b15be879a87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Sun, 3 Nov 2024 23:55:44 +0100 Subject: [PATCH] Add documentation on new SwiftUI modifier to track navigation --- articles/navigation-signals.md | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/articles/navigation-signals.md b/articles/navigation-signals.md index dcfbd02..aebf566 100644 --- a/articles/navigation-signals.md +++ b/articles/navigation-signals.md @@ -63,7 +63,7 @@ Examples: Since TelemetryDeck navigation signals are slightly cumbersome to create manually, we're aiming to provide convenience methods for our SDKs that will automatically track navigation signals for you. These methods will be in one of two flavors, either a method that you call with a source and destination, or a method that you call with just a destination. -### `TelemetryDeck.navigationPathChanged(from: , to )` +### `TelemetryDeck.navigationPathChanged(from: , to: )` Calling this method will automatically create a navigation signal with the given source and destination. @@ -75,3 +75,23 @@ This is convenient, but might produce incorrect graphs if you don't call it from Suppose you have 3 tabs "Home", "User" and "Settings", but only set up navigation in "Home" and "Settings". If a user taps "Home", "User" and "Settings" in that order, that'll produce an incorrect navigation signal with source "Home" and destination "Settings", a path that the user did not take. + +#### SwiftUI Convenience + +If you're using SwiftUI, you can use the `.trackNavigation(path:)` view modifier as a convenient wrapper around `navigationPathChanged(to:)`. It will automatically send the navigation signal when the view appears: + +```swift +struct SettingsView: View { + var body: some View { + Form { + NavigationLink("Account") { + AccountSettingsView() + .trackNavigation(path: "settings.account") + } + } + .trackNavigation(path: "settings") + } +} +``` + +The same considerations about consistent application apply - make sure to use the modifier on all navigation destinations to avoid incorrect navigation paths.