Analytics & Crashlytics
Relevant source files
The following files were used as context for generating this wiki page:
- README.md
- Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift
- Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift
- Features/AnalyticsFeature/Tests/AnalyticsFeatureTests/Views/Analytics/AnalyticsViewModelTests.swift
- Features/SettingsFeature/Tests/SettingsFeatureTests/Views/Paywall/PaywallViewModelTests.swift
- Features/CategoriesFeature/Tests/CategoriesFeatureTests/Views/CategoryForm/CategoryFormViewModelTests.swift
- Features/TagsFeature/Tests/TagsFeatureTests/Views/TagForm/TagFormViewModelTests.swift
The Analytics & Crashlytics system in Trackurr provides comprehensive tracking of user behavior, application health, and business performance metrics. It is primarily built upon the Firebase SDK, integrating both Firebase Analytics for event tracking and Firebase Crashlytics for error reporting and stability monitoring.
The system is designed with a protocol-oriented approach, abstracting the underlying tracking engines to ensure modularity and testability. Analytics are triggered throughout the application—from view lifecycle events and form submissions to in-app purchase flows—allowing developers to gain insights into subscription management trends and user engagement.
Sources: README.md:46-46, README.md:65-65
System Architecture
The analytics architecture follows a centralized pattern where event names and parameter keys are defined as static constants within the Interfaces package. This ensures consistency across different feature modules and prevents "stringly-typed" errors. View models interact with an AppAnalytics service (typically injected via the Factory DI container) to log specific user actions or system states.
Core Components
| Component | Description |
|---|---|
AppAnalyticsEvent | A collection of static constants defining every trackable event in the app. |
AppAnalyticsParam | Static constants for parameter keys used to provide context to events. |
AnalyticsViewModel | Orchestrates screen-level tracking and captures error states during data loading. |
AppAnalytics Service | The primary interface used by ViewModels to send data to the underlying engines. |
Sources: Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift:3-80, Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift:65-71
Data Flow Diagram
This diagram illustrates how a user action in a feature module (such as creating a category) triggers an analytics event that flows through the internal service to the Firebase backend.
Event Categories
The application tracks events across several functional domains, enabling detailed analysis of how users interact with their subscription data.
1. Feature Interaction Tracking
Events are triggered whenever a user creates, edits, or deletes core entities such as subscriptions, categories, tags, or payment methods.
- Subscriptions:
subscription_created,subscription_edited,subscription_deleted,subscription_stopped. - Categories:
category_created,category_edited,category_deleted. - Tags:
tag_created,tag_edited.
Sources: Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift:6-21, Features/CategoriesFeature/Tests/CategoriesFeatureTests/Views/CategoryForm/CategoryFormViewModelTests.swift:363-373
2. Screen and Lifecycle Tracking
Automated and manual tracking is used to monitor screen views and system states, such as empty data views or error alerts.
- Screen Views: Logged when a view's
onAppearlifecycle method is called. - Empty States: Triggered if a dashboard or list is loaded but contains no data (e.g.,
empty_state_shown). - Errors: Logged when service calls fail, including the
error_typeas a parameter.
Sources: Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift:67-71, Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift:97-101, Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift:76-78
3. Monetization and Paywall Tracking
Specific events monitor the performance of StoreKit 2 integrations and the premium conversion funnel.
- Paywall Visibility:
paywall_shownincludes thepaywall_source(e.g., "settings", "subscriptionLimit") to identify which feature prompted the paywall. - Purchase Results:
premium_purchased,premium_purchase_cancelled, orpremium_restored.
Sources: Features/SettingsFeature/Tests/SettingsFeatureTests/Views/Paywall/PaywallViewModelTests.swift:293-316, Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift:58-65
Implementation Details
View Model Integration
View models use dependency injection to access the analytics service. The following snippet demonstrates the standard pattern for logging a screen view:
// Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift
func onScreenAppear() {
appAnalytics.logEvent(AppAnalyticsEvent.screenViewed, parameters: [
AppAnalyticsParam.screenName: "analytics",
])
}
Sources: Features/AnalyticsFeature/Sources/AnalyticsFeature/Views/Analytics/AnalyticsViewModel.swift:67-71
Analytical Parameters
Parameters provide granulary to events. The system uses a strict set of keys defined in AppAnalyticsParam.
| Parameter Key | Usage |
|---|---|
screen_name | Identifies the specific view (e.g., "analytics", "tag_form", "settings"). |
paywall_source | Tracks the entry point to the purchase flow (e.g., "dataExport", "customCategory"). |
error_type | Categorizes failure points (e.g., "load_failed"). |
category_name | Captures the name of a newly created or edited category. |
Sources: Packages/Interfaces/Sources/Interfaces/Analytics/AppAnalyticsEvent.swift:83-97, Features/SettingsFeature/Tests/SettingsFeatureTests/Views/Paywall/PaywallViewModelTests.swift:328-338
Testing Analytics
The project uses AppAnalyticsMock and TrackingAnalytics classes in tests to verify that events are fired correctly during user workflows. Tests assert both the presence of the event and the correctness of its associated parameters.
Summary
The Analytics & Crashlytics module provides the necessary instrumentation to monitor the Trackurr app's performance and user engagement. By centralizing event definitions and utilizing a protocol-driven approach, the system maintains high code quality and ensures that business-critical flows, like subscription tracking and premium upgrades, are fully observable.