Event Tracking
Custom Events
// Simple event
AttributeHQ.shared.track(eventName: "signup_completed")
// Event with properties
AttributeHQ.shared.track(eventName: "product_viewed", properties: [
"product_id": "sku_123",
"category": "electronics",
"price": 15000
])Revenue Events
// Basic revenue (defaults to NGN)
AttributeHQ.shared.trackRevenue(amount: 5000)
// With currency
AttributeHQ.shared.trackRevenue(amount: 25.99, currency: "USD")
// With properties
AttributeHQ.shared.trackRevenue(amount: 5000, currency: "NGN", properties: [
"product": "premium_plan",
"payment_method": "card"
])Revenue events are stored with dedicated fields for LTV and ROAS calculations.
User Identification
AttributeHQ.shared.identify(userId: "user_12345", properties: [
"email": "user@example.com",
"plan": "premium"
])Get Attribution
if let attribution = AttributeHQ.shared.getAttribution() {
print("Match type: \(attribution.matchType)")
print("Confidence: \(attribution.confidence)%")
print("Source: \(attribution.mediaSource ?? "organic")")
print("Campaign: \(attribution.campaignId ?? "none")")
print("Organic: \(attribution.isOrganic)")
}Returns nil if install tracking hasn’t completed yet.
Flush Events
Events are automatically flushed based on batchSize and flushInterval. To force a flush:
AttributeHQ.shared.flush()Background Behavior
When the app enters background (UIApplication.didEnterBackgroundNotification):
- The SDK starts a
beginBackgroundTask - All queued events are flushed
- Background task ends when flush completes or times out
This ensures events are delivered even when the user switches apps.
Offline Queue
Events are persisted to disk. If a flush fails (no network), events stay in the queue and are retried on the next flush cycle. The NWPathMonitor detects connectivity changes to optimize flush timing.
If the queue exceeds maxQueueSize (default: 100), the oldest events are dropped.