Skip to content

Emit analytics events for XP/level change (users module) #506

Description

@phertyameen

Description

Use the app's existing EventEmitterModule (already configured in app.module.ts) to emit xp_awarded / user_leveled_up events from the users module, then add a listener in analytics that persists them to AnalyticsEvent. Prefer emitting events over calling the analytics service directly, to avoid tight coupling between users and analytics.

Why this matters

Analytics is only useful if activity in users actually reaches the event log; this is the instrumentation step for that module.

Files to touch

  • backend/src/users/providers/xp-level.service.ts
  • backend/src/analytics/listeners/users-analytics.listener.ts
  • backend/src/analytics/analytics.module.ts

Acceptance Criteria

  • xp_awarded event is emitted at the correct point in the users flow
  • A listener in analytics persists the event with relevant metadata (userId, timestamp, entity id)
  • Emitting the event never blocks or throws inside the original request path (fire-and-forget)
  • Unit test asserts the event is emitted with the expected payload shape

Notes

This issue is part of the new analytics module effort (tracking, aggregation,
and reporting on player/game activity). Please keep new code inside
backend/src/analytics/ following the same module/controller/service/provider
layout used by existing modules (e.g. progress, streak, quests).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions