Track pageviews and custom events to understand user behavior across your application.
Pageview Tracking
Pageviews are the fundamental tracking unit. They capture when a user views a page or screen.
Automatic Pageviews
With autoPushPageview: true (default), a pageview is tracked automatically on initialization.
Manual Pageviews
For single-page applications or custom navigation:
// Track a pageview manually
alkeAnalytics.pushPageView();
The SDK automatically captures:
- Current URL (normalized, without tracking parameters)
- Page title
- Referrer
- Session data
pushPageView()
// Basic pageview
AlkeAnalytics.pushPageView(
url: "myapp://home",
title: "Home Screen"
)
// With custom data
AlkeAnalytics.pushPageView(
url: "myapp://article/123",
title: "Article Title",
customData: [
1: "category_tech",
2: "author_john"
]
)
When to call
Call pushPageView() in onAppear (SwiftUI) or viewDidAppear (UIKit).
pushPageView()
// Basic pageview
AlkeAnalytics.pushPageView(
url = "myapp://home",
title = "Home Screen"
)
// With custom data
AlkeAnalytics.pushPageView(
url = "myapp://article/123",
title = "Article Title",
customData = mapOf(
1 to "category_tech",
2 to "author_john"
)
)
When to call
Call pushPageView() in onResume() of your Activity or Fragment.
Custom Events
Track specific user interactions beyond pageviews.
pushEvent()
// Simple event
alkeAnalytics.pushEvent('button_click', 'share_button');
// Event with custom data included
alkeAnalytics.pushEvent('purchase', 99.99, true);
| Parameter | Type | Description |
|---|
eventName | stringrequired | Name of the event (e.g., 'button_click', 'video_play') |
eventValue | string|number|booleanoptional | Optional value associated with the event |
includeCustomData | booleanoptional | Include current custom data with this event. Default: `false` |
pushEvent()
// Simple event
AlkeAnalytics.pushEvent(name: "button_click")
// Event with value
AlkeAnalytics.pushEvent(
name: "video_progress",
value: 50 // 50% watched
)
// Event with custom data
AlkeAnalytics.pushEvent(
name: "purchase",
value: 99.99,
customData: [
1: "product_abc",
2: "electronics"
]
)
pushEvent()
// Simple event
AlkeAnalytics.pushEvent(name = "button_click")
// Event with value
AlkeAnalytics.pushEvent(
name = "video_progress",
value = 50 // 50% watched
)
// Event with custom data
AlkeAnalytics.pushEvent(
name = "purchase",
value = 99.99,
customData = mapOf(
1 to "product_abc",
2 to "electronics"
)
)
Flushing Events
Events are automatically sent when:
- The page/app goes to background
- The page is about to unload (web)
- A new pageview is tracked
You can also manually flush:
Events are flushed automatically on visibilitychange and pagehide. Manual flush is rarely needed.
// Flush all pending events
AlkeAnalytics.flush()
// Async version
await AlkeAnalytics.flushAsync()
// Flush all pending events
AlkeAnalytics.flush()
Engagement Tracking
Track how much of the content users actually consume.
Scroll engagement is tracked automatically. The SDK records the maximum scroll depth as a percentage (0-100).
// Override with custom engagement (e.g., video progress)
alkeAnalytics.setEngagementPercent(75);
// Update engagement as user progresses
AlkeAnalytics.setEngagementPercent(25) // 25% read
AlkeAnalytics.setEngagementPercent(50) // 50% read
AlkeAnalytics.setEngagementPercent(100) // Finished
// Update engagement as user progresses
AlkeAnalytics.setEngagementPercent(25) // 25% read
AlkeAnalytics.setEngagementPercent(50) // 50% read
AlkeAnalytics.setEngagementPercent(100) // Finished