SwiftUI support
The Swizzling technique used for tracking events in UIKit components does not work for SwiftUI components. As a result, the PAPulse SDK is unable to automatically track click and page_load/page_view events in SwiftUI in the same manner as it does for UIKit.
To address this limitation, the PAPulse SDK offers a SwiftUI native API based on view methods logClick() and logView(). These methods can be used as a substitute for the automatic events, allowing you to manually track click and page_load/page_view events in SwiftUI components.
The modifiers ship in the separate PAPulseSwiftUI SPM product, so import it explicitly:
import SwiftUI
import PAPulseSwiftUI
struct ContentView: View {
var body: some View {
VStack {
Button("Submit") {
print("do work")
}
.logClick(trackingName: "button-submit")
Text("Price")
.logClick(trackingName: "label-price")
}
.logView(trackingName: "test-open")
}
}
API
func logView(
trackingName: String,
title: String? = nil,
additionalProperties: [String: Any]? = nil,
additionalIDs: [String: Any]? = nil
) -> some View
func logClick(
trackingName: String,
title: String? = nil,
additionalProperties: [String: Any]? = nil,
additionalIDs: [String: Any]? = nil
) -> some View
trackingName— view class name or other identifier; reported as the element name.title— title of the view (controller).additionalProperties/additionalIDs— key-value pairs included in the resulting event'sdata.additionalProperties/data.additionalIDsfields.
logView logs page_load on the first appearance and page_view on every appearance.