Skip to content

Commit 09a0f00

Browse files
committed
Add privacy overrides
1 parent 149a1ac commit 09a0f00

File tree

7 files changed

+186
-51
lines changed

7 files changed

+186
-51
lines changed

BenchmarkTests/CatalogSwiftUI/ContentView.swift

Lines changed: 47 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,7 @@ public struct ContentView: View {
4040
startRadiusFraction: 0.3,
4141
endRadiusFraction: 5)
4242

43-
private let monitor: DatadogMonitor
44-
45-
public init(monitor: DatadogMonitor) {
46-
self.monitor = monitor
47-
43+
public init() {
4844
// change the background of all the tables
4945
UITableView.appearance().backgroundColor = .clear
5046
}
@@ -70,7 +66,7 @@ public struct ContentView: View {
7066
}
7167
.scrollContentBackground(.hidden)
7268
.navigationTitle("SwiftUI Catalog")
73-
.modifier(monitor.viewModifier(name: "SwiftUI Catalog"))
69+
.trackView(name: "SwiftUI Catalog")
7470
}
7571

7672
}
@@ -88,6 +84,7 @@ public struct ContentView: View {
8884
.padding(.top, 24)
8985
.padding(.bottom, 16)
9086
.foregroundColor(.white)
87+
.privacyOverride(text: .maskAll)
9188

9289
HStack(alignment: .center, spacing: 2) {
9390
Spacer()
@@ -114,31 +111,31 @@ public struct ContentView: View {
114111
.font(.title)
115112
.modifier(ListSectionFontModifier())) {
116113
Group {
117-
Link(destination: ButtonsComponentsView().modifier(monitor.viewModifier(name: "Buttons")),
114+
Link(destination: ButtonsComponentsView().trackView(name: "Buttons"),
118115
label: "Buttons")
119-
Link(destination: ImagesComponentView().modifier(monitor.viewModifier(name: "Images")),
116+
Link(destination: ImagesComponentView().trackView(name: "Images"),
120117
label: "Images")
121-
Link(destination: TextsComponentsView().modifier(monitor.viewModifier(name: "Texts")),
118+
Link(destination: TextsComponentsView().trackView(name: "Texts"),
122119
label: "Texts")
123-
Link(destination: LabelsView().modifier(monitor.viewModifier(name: "Labels")),
120+
Link(destination: LabelsView().trackView(name: "Labels"),
124121
label: "Labels")
125-
Link(destination: MenusComponentView().modifier(monitor.viewModifier(name: "Menus")),
122+
Link(destination: MenusComponentView().trackView(name: "Menus"),
126123
label: "Menus")
127124
}
128125
Group {
129-
Link(destination: TogglesView().modifier(monitor.viewModifier(name: "Toggles")),
126+
Link(destination: TogglesView().trackView(name: "Toggles"),
130127
label: "Toggles")
131-
Link(destination: SlidersView().modifier(monitor.viewModifier(name: "Sliders")),
128+
Link(destination: SlidersView().trackView(name: "Sliders"),
132129
label: "Sliders")
133-
Link(destination: SteppersView().modifier(monitor.viewModifier(name: "Steppers")),
130+
Link(destination: SteppersView().trackView(name: "Steppers"),
134131
label: "Steppers")
135-
Link(destination: PickersView().modifier(monitor.viewModifier(name: "Pickers")),
132+
Link(destination: PickersView().trackView(name: "Pickers"),
136133
label: "Pickers")
137-
Link(destination: DatePickersView().modifier(monitor.viewModifier(name: "Date Pickers")),
134+
Link(destination: DatePickersView().trackView(name: "Date Pickers"),
138135
label: "Date Pickers")
139-
Link(destination: ColorPickersView().modifier(monitor.viewModifier(name: "Color Pickers")),
136+
Link(destination: ColorPickersView().trackView(name: "Color Pickers"),
140137
label: "Color Pickers")
141-
Link(destination: ProgressViews().modifier(monitor.viewModifier(name: "Progress View")),
138+
Link(destination: ProgressViews().trackView(name: "Progress View"),
142139
label: "Progress View")
143140
}
144141
}
@@ -151,7 +148,7 @@ public struct ContentView: View {
151148
.modifier(ListSectionFontModifier())) {
152149
Group {
153150
Link(destination: ExampleProductView(productId: "product.consumable.example.1", productImageName: "giftcard.fill"),
154-
label: "Consumable Product View").modifier(monitor.viewModifier(name: "Consumable Product View"))
151+
label: "Consumable Product View").trackView(name: "Consumable Product View")
155152
}
156153
}
157154
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -162,17 +159,17 @@ public struct ContentView: View {
162159
Section(header: Text("Layouts")
163160
.font(.title)
164161
.modifier(ListSectionFontModifier())) {
165-
Link(destination: ListsComponentView().modifier(monitor.viewModifier(name: "Lists")),
162+
Link(destination: ListsComponentView().trackView(name: "Lists"),
166163
label: "Lists")
167-
Link(destination: StacksView().modifier(monitor.viewModifier(name: "Stacks")),
164+
Link(destination: StacksView().trackView(name: "Stacks"),
168165
label: "Stacks")
169-
Link(destination: GridsView().modifier(monitor.viewModifier(name: "Grids")),
166+
Link(destination: GridsView().trackView(name: "Grids"),
170167
label: "Grids")
171-
Link(destination: ContainersView().modifier(monitor.viewModifier(name: "Containers")),
168+
Link(destination: ContainersView().trackView(name: "Containers"),
172169
label: "Containers")
173-
Link(destination: ScrollViewsView().modifier(monitor.viewModifier(name: "Scrollviews")),
170+
Link(destination: ScrollViewsView().trackView(name: "Scrollviews"),
174171
label: "Scrollviews")
175-
Link(destination: TableViews().modifier(monitor.viewModifier(name: "Table Views")),
172+
Link(destination: TableViews().trackView(name: "Table Views"),
176173
label: "Table Views")
177174
}
178175
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -181,13 +178,13 @@ public struct ContentView: View {
181178
var hierachicalViews: some View {
182179
Section(header: Text("Hierachical Views") .font(.title)
183180
.modifier(ListSectionFontModifier())) {
184-
Link(destination: NavigationBarsComponentView().modifier(monitor.viewModifier(name: "Navigation")),
181+
Link(destination: NavigationBarsComponentView().trackView(name: "Navigation"),
185182
label: "Navigation")
186-
Link(destination: OutlinesGroupsView().modifier(monitor.viewModifier(name: "Outlines")),
183+
Link(destination: OutlinesGroupsView().trackView(name: "Outlines"),
187184
label: "Outlines")
188-
Link(destination: DisclosureGroupsView().modifier(monitor.viewModifier(name: "Disclosures")),
185+
Link(destination: DisclosureGroupsView().trackView(name: "Disclosures"),
189186
label: "Disclosures")
190-
Link(destination: TabsView().modifier(monitor.viewModifier(name: "Tabs")),
187+
Link(destination: TabsView().trackView(name: "Tabs"),
191188
label: "Tabs")
192189
}
193190
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -198,15 +195,15 @@ public struct ContentView: View {
198195
Section(header: Text("Drawing and animations")
199196
.font(.title)
200197
.modifier(ListSectionFontModifier())) {
201-
Link(destination: CanvasView().modifier(monitor.viewModifier(name: "Canvas")),
198+
Link(destination: CanvasView().trackView(name: "Canvas"),
202199
label: "Canvas")
203-
Link(destination: GraphicContextsView().modifier(monitor.viewModifier(name: "Graphic Context")),
200+
Link(destination: GraphicContextsView().trackView(name: "Graphic Context"),
204201
label: "Graphic Context")
205-
Link(destination: ShapesView().modifier(monitor.viewModifier(name: "Shapes")),
202+
Link(destination: ShapesView().trackView(name: "Shapes"),
206203
label: "Shapes")
207-
Link(destination: AnimationsView().modifier(monitor.viewModifier(name: "Animations")),
204+
Link(destination: AnimationsView().trackView(name: "Animations"),
208205
label: "Animations")
209-
Link(destination: GeometriesView().modifier(monitor.viewModifier(name: "Geometries")),
206+
Link(destination: GeometriesView().trackView(name: "Geometries"),
210207
label: "Geometries")
211208
}
212209
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -218,7 +215,7 @@ public struct ContentView: View {
218215
Section(header: Text("Charts")
219216
.font(.title)
220217
.modifier(ListSectionFontModifier())) {
221-
Link(destination: ChartsViews().modifier(monitor.viewModifier(name: "Swift Charts")),
218+
Link(destination: ChartsViews().trackView(name: "Swift Charts"),
222219
label: "Swift Charts")
223220
}
224221
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -229,11 +226,11 @@ public struct ContentView: View {
229226
Section(header: Text("Gestures")
230227
.font(.title)
231228
.modifier(ListSectionFontModifier())) {
232-
Link(destination: GesturesView().modifier(monitor.viewModifier(name: "Gestures")),
229+
Link(destination: GesturesView().trackView(name: "Gestures"),
233230
label: "Gestures")
234-
Link(destination: ComposingGesturesView().modifier(monitor.viewModifier(name: "Composing Gestures")),
231+
Link(destination: ComposingGesturesView().trackView(name: "Composing Gestures"),
235232
label: "Composing Gestures")
236-
Link(destination: SensoryFeedbackInViews().modifier(monitor.viewModifier(name: "Sensory Feedback")),
233+
Link(destination: SensoryFeedbackInViews().trackView(name: "Sensory Feedback"),
237234
label: "Sensory Feedback")
238235
}
239236
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -244,11 +241,11 @@ public struct ContentView: View {
244241
Section(header: Text("View modifiers")
245242
.font(.title)
246243
.modifier(ListSectionFontModifier())) {
247-
Link(destination: TextModifiersView().modifier(monitor.viewModifier(name: "Text modifiers")),
244+
Link(destination: TextModifiersView().trackView(name: "Text modifiers"),
248245
label: "Text modifiers")
249-
Link(destination: EffectsModifiersView().modifier(monitor.viewModifier(name: "Effect modifiers")),
246+
Link(destination: EffectsModifiersView().trackView(name: "Effect modifiers"),
250247
label: "Effect modifiers")
251-
Link(destination: LayoutModifiersView().modifier(monitor.viewModifier(name: "Layout modifiers")),
248+
Link(destination: LayoutModifiersView().trackView(name: "Layout modifiers"),
252249
label: "Layout modifiers")
253250

254251
}
@@ -261,7 +258,7 @@ public struct ContentView: View {
261258
.font(.title)
262259
.modifier(ListSectionFontModifier())) {
263260

264-
Link(destination: AccesibilityView().modifier(monitor.viewModifier(name: "Accesibility")),
261+
Link(destination: AccesibilityView().trackView(name: "Accesibility"),
265262
label: "Accesibility")
266263
}
267264
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -272,7 +269,7 @@ public struct ContentView: View {
272269
Section(header: Text("Status and tool bars")
273270
.font(.title)
274271
.modifier(ListSectionFontModifier())) {
275-
Link(destination: ToolbarsComponentView().modifier(monitor.viewModifier(name: "Tool Bars")),
272+
Link(destination: ToolbarsComponentView().trackView(name: "Tool Bars"),
276273
label: "Tool Bars")
277274
}
278275
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -284,7 +281,7 @@ public struct ContentView: View {
284281
.font(.title)
285282
.modifier(ListSectionFontModifier())) {
286283

287-
Link(destination: StylesView().modifier(monitor.viewModifier(name: "Styles")),
284+
Link(destination: StylesView().trackView(name: "Styles"),
288285
label: "Styles")
289286
}
290287
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -298,7 +295,7 @@ public struct ContentView: View {
298295

299296
// Link(destination: PopoversComponentView(),
300297
// label: "Popovers")
301-
Link(destination: SheetsView().modifier(monitor.viewModifier(name: "Sheets")),
298+
Link(destination: SheetsView().trackView(name: "Sheets"),
302299
label: "Sheets")
303300
// Link(destination: AlertsComponentView(),
304301
// label: "Alerts")
@@ -315,13 +312,13 @@ public struct ContentView: View {
315312
Section(header: Text("Composed components to help speed up development")
316313
.font(.title)
317314
.modifier(ListSectionFontModifier())) {
318-
Link(destination: CommonlyUsedViews().modifier(monitor.viewModifier(name: "Commonly used views")),
315+
Link(destination: CommonlyUsedViews().trackView(name: "Commonly used views"),
319316
label: "Commonly used views")
320-
Link(destination: CollectionsViews().modifier(monitor.viewModifier(name: "Collections of components")),
317+
Link(destination: CollectionsViews().trackView(name: "Collections of components"),
321318
label: "Collections of components")
322-
Link(destination: StackedCardsView<CardView>(elementsCount: 22).modifier(monitor.viewModifier(name: "Stacked cards with dragging")),
319+
Link(destination: StackedCardsView<CardView>(elementsCount: 22).trackView(name: "Stacked cards with dragging"),
323320
label: "Stacked cards with dragging")
324-
Link(destination: InterfacingWithUIKitView(pages: ModelData().features.map { FeatureCardView(landmark: $0) }).modifier(monitor.viewModifier(name: "UIKit Interface")),
321+
Link(destination: InterfacingWithUIKitView(pages: ModelData().features.map { FeatureCardView(landmark: $0) }).trackView(name: "UIKit Interface"),
325322
label: "UIKit Interface")
326323
}
327324
.listRowBackground(Color(sectionColor, bundle: .module))
@@ -337,7 +334,7 @@ public struct ContentView: View {
337334
#Preview {
338335

339336
Group {
340-
ContentView(monitor: NOPDatadogMonitor())
337+
ContentView()
341338
.preferredColorScheme(.dark)
342339
}
343340
}

BenchmarkTests/CatalogSwiftUI/DatadogMonitor.swift

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,85 @@
66

77
import SwiftUI
88

9+
@frozen public enum TextPrivacyLevel {
10+
case maskSensitiveInputs
11+
case maskAllInputs
12+
case maskAll
13+
}
14+
15+
@frozen public enum ImagePrivacyLevel {
16+
case maskNonBundledOnly
17+
case maskAll
18+
case maskNone
19+
}
20+
21+
@frozen public enum TouchPrivacyLevel {
22+
case show
23+
case hide
24+
}
25+
926
public protocol DatadogMonitor {
1027
func viewModifier(name: String) -> AnyViewModifier
1128
func actionModifier(name: String) -> AnyViewModifier
29+
func privacyOverride(
30+
text: TextPrivacyLevel?,
31+
image: ImagePrivacyLevel?,
32+
touch: TouchPrivacyLevel?,
33+
hide: Bool?
34+
) -> AnyViewModifier
1235
}
1336

1437
struct NOPDatadogMonitor: DatadogMonitor {
1538
func viewModifier(name: String) -> AnyViewModifier { AnyViewModifier() }
1639
func actionModifier(name: String) -> AnyViewModifier { AnyViewModifier() }
40+
func privacyOverride(
41+
text _: TextPrivacyLevel?,
42+
image _: ImagePrivacyLevel?,
43+
touch _: TouchPrivacyLevel?,
44+
hide _: Bool?
45+
) -> AnyViewModifier {
46+
AnyViewModifier()
47+
}
48+
}
49+
50+
extension EnvironmentValues {
51+
@Entry public var datadogMonitor: any DatadogMonitor = NOPDatadogMonitor()
52+
}
53+
54+
extension View {
55+
func trackView(name: String) -> some View {
56+
modifier(TrackViewModifier(name: name))
57+
}
58+
59+
func privacyOverride(
60+
text: TextPrivacyLevel? = nil,
61+
image: ImagePrivacyLevel? = nil,
62+
touch: TouchPrivacyLevel? = nil,
63+
hide: Bool? = nil
64+
) -> some View {
65+
modifier(PrivacyOverrideModifier(text: text, image: image, touch: touch, hide: hide))
66+
}
67+
}
68+
69+
private struct TrackViewModifier: ViewModifier {
70+
@Environment(\.datadogMonitor) private var monitor
71+
72+
var name: String
73+
74+
func body(content: Content) -> some View {
75+
content.modifier(monitor.viewModifier(name: name))
76+
}
77+
}
78+
79+
private struct PrivacyOverrideModifier: ViewModifier {
80+
@Environment(\.datadogMonitor) private var monitor
81+
82+
var text: TextPrivacyLevel?
83+
var image: ImagePrivacyLevel?
84+
var touch: TouchPrivacyLevel?
85+
var hide: Bool?
86+
87+
func body(content: Content) -> some View {
88+
content.modifier(monitor.privacyOverride(text: text, image: image, touch: touch, hide: hide))
89+
}
1790
}

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/ButtonsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ struct ButtonsComponentsView: View, Comparable {
109109
styledButtons
110110
.modifier(Divided())
111111
}
112+
.privacyOverride(touch: .hide)
112113

113114
ContributedByView(name: "Barbara Martina",
114115
link: "https://github.com/barbaramartina")

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/ImagesView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct ImagesComponentView: View, Comparable {
5252
.modifier(Divided())
5353
fixedFrameImages
5454
.modifier(Divided())
55+
.privacyOverride(image: .maskAll)
5556

5657
ContributedByView(name: "Barbara Martina",
5758
link: "https://github.com/barbaramartina")

BenchmarkTests/CatalogSwiftUI/Views/Sections/Controls/TextsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ struct TextsComponentsView: View, Comparable {
6161
textDates
6262
.modifier(Divided())
6363
textControls
64+
.privacyOverride(text: .maskAllInputs)
6465

6566
ContributedByView(name: "Barbara Martina",
6667
link: "https://github.com/barbaramartina")

BenchmarkTests/CatalogSwiftUI/Views/Sections/View Layouts/ListsView.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ struct ListsComponentView: View, Comparable {
5656

5757
list1
5858
.modifier(Divided())
59+
.privacyOverride(text: .maskAll)
5960
list2
6061
.modifier(Divided())
6162
list3

0 commit comments

Comments
 (0)