Skip to content

Commit

Permalink
Merge pull request #104 from TelemetryDeck/feature/navigation-modifier
Browse files Browse the repository at this point in the history
Add documentation on new SwiftUI modifier to track navigation
  • Loading branch information
Jeehut authored Nov 5, 2024
2 parents 44cb75e + 2194ae3 commit 351b1a7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion articles/navigation-signals.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: <source>, to <destination>)`
### `TelemetryDeck.navigationPathChanged(from: <source>, to: <destination>)`

Calling this method will automatically create a navigation signal with the given source and destination.

Expand All @@ -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.

0 comments on commit 351b1a7

Please sign in to comment.