ClickEvent
public struct ClickEvent : Sendable
Represents a captured click event with element metadata.
Contains all semantic information about the clicked element and its context.
Create a ClickEvent and pass it to mixpanel.autocapture.trackClick(_:) to
track click events with full element metadata.
All stored properties are value types (CGFloat, String, Bool), so the event can safely
cross threads — it is handed from the main thread, where it is extracted, to the queue that
emits it.
Warning
Experimental (beta). Autocapture may contain issues, and its API and the properties it captures may change in a future release before general availability. Pin your SDK version if you build reports on autocaptured events.-
Touch X coordinate in the window’s coordinate space (points).
The SDK captures this as
touch.location(in: window).x. When tracking manually, usetouch.location(in: view.window).x.Declaration
Swift
public let x: CGFloat -
Touch Y coordinate in the window’s coordinate space (points).
The SDK captures this as
touch.location(in: window).y. When tracking manually, usetouch.location(in: view.window).y.Declaration
Swift
public let y: CGFloat
-
A stable identifier for the tapped element, used to group clicks in analytics.
Autocapture resolves this in the following order (see
DefaultElementIdExtractor), and the same preferences apply when tracking manually:- React Native
nativeID— the JS-side prop, read through the Objective-C runtime (skipped for SwiftUI views, which React Native never renders) accessibilityIdentifier— stable and not user-visible<ClassName>_<hash>as a last resort, hashed from the element’s position in the hierarchy
accessibilityLabelis deliberately not a source: it is localized, so the same element would report a different identifier per language, and it can carry personal data.When constructing a
ClickEventyourself, prefer a stable, human-readable string such as"buy_button"or"settings_cell_notifications".Avoid dynamic values (e.g., cell index, timestamp) — they prevent meaningful grouping.
Declaration
Swift
public let elementId: String - React Native
-
The class name or component type of the tapped element.
Examples:
"UIButton","UITableViewCell","Button"(SwiftUI). UseString(describing: type(of: view))to get the class name. Set tonilif not available.Declaration
Swift
public let tagName: String? -
The semantic role describing what the element does.
Autocapture emits one of these exact values, resolved from the view’s class and then its accessibility traits (see
SemanticExtractor). They are Title Case — match on them verbatim when building reports on$attr-role:"Button","Link","Switch","Slider","Stepper","SegmentedControl","TextField","TextArea","SearchField","Text","Image","List","Grid","ScrollView","Header","TabBar","Adjustable".Set to
nilif the element has no specific role. When constructing aClickEventyourself, prefer one of the values above so manual and autocaptured events group together.Declaration
Swift
public let role: String? -
View hierarchy path from the tapped element up to 5 ancestor levels,
">"separated.Example:
"UIButton > UIStackView > UITableViewCell > UITableView > UIView". Useful for identifying where in the view tree the click occurred. Set tonilif not available.Declaration
Swift
public let elements: String? -
Creates a new ClickEvent.
Only
x,y, andelementIdare required. All other parameters have sensible defaults.Minimal usage:
let click = ClickEvent(x: 150, y: 300, elementId: "buy_button") mixpanel.autocapture.trackClick(click)Full usage:
let click = ClickEvent( x: touch.location(in: view.window).x, y: touch.location(in: view.window).y, elementId: button.accessibilityIdentifier ?? "buy_button", tagName: String(describing: type(of: button)), role: "button", elements: "UIButton > UIStackView > UIView" ) mixpanel.autocapture.trackClick(click)Declaration
Swift
public init( x: CGFloat, y: CGFloat, elementId: String, tagName: String? = nil, role: String? = nil, elements: String? = nil, isInteractive: Bool = true )Parameters
xTouch X coordinate in window points
yTouch Y coordinate in window points
elementIdStable identifier for the tapped element
tagNameClass name of the tapped element (defaults to nil)
roleSemantic role like
"button","switch","link"(defaults to nil)elementsView hierarchy path,
">"separated (defaults to nil)isInteractiveWhether the element is interactive (defaults to true)
View on GitHub