feat: Add universe-based analytics events to core services#72
Merged
roncodes merged 7 commits intodev-v0.3.11from Feb 11, 2026
Merged
feat: Add universe-based analytics events to core services#72roncodes merged 7 commits intodev-v0.3.11from
roncodes merged 7 commits intodev-v0.3.11from
Conversation
added 2 commits
February 8, 2026 21:13
- Add analytics event triggering to crud service (delete, bulk actions, import) - Add analytics event triggering to resource-action service (create, update, delete) - Add session analytics events (initialized, terminated with duration) - Emit both generic (resource.created) and specific (order.created) events - Use dot notation naming convention for all events - Non-breaking changes, events are optional and don't affect existing functionality
- Add resource.exported and {model}.exported events to crud service export method
- Remove incorrect session tracking from session service (was in wrong place)
- Session events should be tracked via current-user service's existing 'user.loaded' event
- Current-user service already extends Evented and triggers 'user.loaded' on lines 72 and 99
The current-user service is the proper place for user/session lifecycle events since it:
1. Already extends Evented mixin
2. Already triggers 'user.loaded' event when user is authenticated
3. Is called by session.loadCurrentUser() and session.promiseCurrentUser()
4. Has access to user and organization data
For logout/session termination tracking, consumers should subscribe to ember-simple-auth's
'invalidationSucceeded' event or add a 'user.logout' event to current-user service.
- Created centralized analytics service for event tracking - Refactored crud, resource-action, and current-user services to use analytics service - Removed scattered _triggerResourceEvent() methods - Added global service exports via host-services and services - Implemented private methods using native # syntax - Added comprehensive documentation in ANALYTICS_SERVICE.md Benefits: - Single responsibility: One service handles all analytics - Reusable: Any engine can inject and use it - Consistent API: Standardized methods for tracking - Cleaner services: CRUD/resource-action stay focused - Better testability: Can mock/stub analytics service easily
- Analytics service now extends Evented - Events fire on both analytics service and universe service - Allows local listeners (analytics.on) and cross-engine listeners (universe.on) - Updated documentation with dual event system examples - Follows Fleetbase patterns (like current-user service) Benefits: - Local listeners for UI updates and debugging - Cross-engine listeners for analytics integrations - More flexible event subscription options
11925ac to
62ad87a
Compare
- Renamed service from 'analytics' to 'events' for better clarity - Updated class name from AnalyticsService to EventsService - Updated all service injections (@service events) - Updated all method calls (this.events.*) - Updated configuration namespace (config.events) - Renamed documentation file to EVENTS_SERVICE.md - Updated global exports in host-services and services Rationale: - 'events' is more accurate - it's an event emitter - More generic and flexible - not limited to analytics use cases - Can be used for analytics, logging, UI updates, webhooks, etc. - Clearer purpose and intent
36cf7ca to
c54b9cd
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
This PR adds analytics-agnostic event tracking to core Fleetbase services using the universe service's built-in
Eventedsystem. Events are emitted using dot notation naming convention and can be consumed by any analytics provider (e.g., PostHog in the internals engine).Changes
CRUD Service (
addon/services/crud.js)universeservice injection_triggerResourceEvent()helper method to emit both generic and specific eventsresource.deletedand{model_name}.deletedevents after successful deletionresource.bulk_actionevent for bulk operationsresource.importedand{model_name}.importedevents after successful importResource Action Service (
addon/services/resource-action.js)universeservice injection_triggerResourceEvent()helper methodresource.createdand{model_name}.createdevents increateTaskresource.updatedand{model_name}.updatedevents inupdateTasksaveTaskbased on whether record is new or existingresource.deletedand{model_name}.deletedevents indeleteTaskSession Service (
addon/services/session.js)universeservice injectionsessionStartTimetracked property for duration calculationsession.initializedevent when user session is loadedsession.terminatedevent with session duration when user logs outEvent Naming Convention
All events use dot notation following existing Fleetbase patterns:
resource.{action}(e.g.,resource.created,resource.updated,resource.deleted){model_name}.{action}(e.g.,order.created,vehicle.updated,driver.deleted)session.{action}(e.g.,session.initialized,session.terminated)Event Payloads
resource.created(model)resource.updated(model)resource.deleted(model)resource.imported(modelName, response, files)resource.bulk_action(verb, selected, firstModel)session.initialized(user, organization)session.terminated(user, sessionDuration)Usage Example
In the
internalsengine (or any other consumer), subscribe to these events:Benefits
✅ Analytics-agnostic: No PostHog or analytics-specific code in core
✅ Non-breaking: Events are optional, existing functionality unchanged
✅ Extensible: Can be used for webhooks, audit logs, or any analytics provider
✅ Consistent naming: Follows existing Fleetbase dot notation convention
✅ Dual events: Both generic (
resource.created) and specific (order.created) events for flexibilityTesting
Tested locally by:
Next Steps
ember-uicomponents (buttons, modals, forms)internalsengine