CLASS
Tracker
public class Tracker: TrackerProtocol
Tracks events and user interactions
Methods
init(httpClient:userProvider:exploreClient:)
public init(httpClient: HttpClientProtocol, userProvider: UserProviderProtocol, exploreClient: ExploreClientProtocol? = nil)
Initialize tracker - Parameters: - httpClient: HTTP client for sending tracking data - userProvider: User provider for user information - exploreClient: Optional explore client reference
Parameters
| Name | Description |
|---|---|
| httpClient | HTTP client for sending tracking data |
| userProvider | User provider for user information |
| exploreClient | Optional explore client reference |
trackPageView(_:)
public func trackPageView(_ url: String? = nil) async throws
Track a page view event - Parameter url: The URL being viewed (optional) - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| url | The URL being viewed (optional) |
trackVariationView()
public func trackVariationView() async throws
Track variation view events for current decisions - Throws: TrackerError for various error conditions
track(_:value:details:)
public func track(_ event: String, value: Any? = nil, details: [String: Any]? = nil) async throws
Track a custom event (goal) - Parameters: - event: The event name (goal name) - value: Optional value associated with the event (can be String, Number, or any type) - details: Optional additional details for the event - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| event | The event name (goal name) |
| value | Optional value associated with the event (can be String, Number, or any type) |
| details | Optional additional details for the event |
setContext(_:)
public func setContext(_ context: Context)
Set the current context for tracking - Parameter context: The context to use for tracking
Parameters
| Name | Description |
|---|---|
| context | The context to use for tracking |
setClient(_:)
public func setClient(_ client: ExploreClientProtocol?)
Set the explore client reference - Parameter client: The explore client
Parameters
| Name | Description |
|---|---|
| client | The explore client |
trackGoal(_:value:details:)
public func trackGoal(_ goalName: String, value: Any? = nil, details: [String: Any]? = nil) async throws
Track a goal conversion event - Parameters: - goalName: The name of the goal - value: The value of the conversion (can be String, Number, or any type) - details: Additional details about the conversion (e.g., transaction ID, SKUs, currency) - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| goalName | The name of the goal |
| value | The value of the conversion (can be String, Number, or any type) |
| details | Additional details about the conversion (e.g., transaction ID, SKUs, currency) |
trackGoal(_:value:)
public func trackGoal(_ goalName: String, value: Any?) async throws
Track a goal conversion event with value only - Parameters: - goalName: The name of the goal - value: The value of the conversion - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| goalName | The name of the goal |
| value | The value of the conversion |
trackGoal(_:)
public func trackGoal(_ goalName: String) async throws
Track a goal conversion event without value or details - Parameter goalName: The name of the goal - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| goalName | The name of the goal |
trackPurchase(transactionId:value:products:)
public func trackPurchase(transactionId: String, value: Any, products: [[String: Any]]? = nil) async throws
Track an e-commerce purchase - Parameters: - transactionId: The transaction identifier - value: The transaction value - products: Array of product information - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| transactionId | The transaction identifier |
| value | The transaction value |
| products | Array of product information |
trackAddToCart(productId:productName:value:quantity:)
public func trackAddToCart(productId: String, productName: String, value: Any, quantity: Int = 1) async throws
Track add to cart event - Parameters: - productId: The product identifier - productName: The product name - value: The product value - quantity: The quantity added - Throws: TrackerError for various error conditions
Parameters
| Name | Description |
|---|---|
| productId | The product identifier |
| productName | The product name |
| value | The product value |
| quantity | The quantity added |