Skip to content

Gayatri - Add backend for Job Analytics device-specific engagement metrics (Ticket #34) - #2332

Open
sawantgayatri19 wants to merge 1 commit into
developmentfrom
gayatri/job-analytics-device-breakdown-backend
Open

Gayatri - Add backend for Job Analytics device-specific engagement metrics (Ticket #34)#2332
sawantgayatri19 wants to merge 1 commit into
developmentfrom
gayatri/job-analytics-device-breakdown-backend

Conversation

@sawantgayatri19

Copy link
Copy Markdown

Description
Adds the missing backend endpoint for Ticket #34 (Job Analytics Page - Add Device-Specific Engagement Metrics). This is the companion backend for frontend PR #4998, which currently uses mock data.

New Endpoint
GET /api/applicant-analytics/device-breakdown?startDate=YYYY-MM-DD&endDate=YYYY-MM-DD

Returns real, computed per-device engagement metrics from the existing AnonymousInteraction collection:

  • sessions (distinct session count per device)
  • bounceRate (% of sessions with only 1 interaction)
  • avgEngagementTime (average session duration)
  • value / previousValue (% share of total sessions, current vs. previous period of equal length)

Response shape matches exactly what the frontend's generateMockAnalyticsData().deviceBreakdown already expects, so wiring it in should be a drop-in replacement of the mock.

Related PR

Frontend: #4998 (needs this backend, per its own description: "This frontend PR is not related to any backend PR")

How to test

  1. Check out this branch, run npm install and npm run dev
  2. Get a valid JWT for an Administrator/Owner user
  3. curl -H "Authorization: <token>" "http://localhost:4500/api/applicant-analytics/device-breakdown?startDate=2025-08-01&endDate=2025-08-31"
  4. Confirm the response includes Desktop/Mobile/Tablet entries with sessions, bounceRate, avgEngagementTime, value, previousValue

Testing
Added 7 new unit tests covering: permission checks, date validation, the core aggregation math (verified against hand-calculated expected values), no-data edge case, and error handling. All existing tests (150/151 suites) and lint pass — the one pre-existing failure (reasonSchedulingController) is a local MongoDB timeout unrelated to this change.

Also manually verified live against the dev database — confirmed real session/bounce-rate/engagement-time data is correctly aggregated and returned.

…agement metrics (sessions, bounce rate, avg engagement time)
@sonarqubecloud

sonarqubecloud Bot commented Sep 3, 2026

Copy link
Copy Markdown

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants