feat: Add universe-based analytics events to core services #72
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