-
Notifications
You must be signed in to change notification settings - Fork 0
Frontend Integration Analytics Guide
The Analytics Service provides aggregated statistics about phishing simulations, user reports, education completions, XP, click tracking, campaigns, and department breakdowns. It is part of the PhishShield microservices backend and powers the Analytics Dashboard requested by the frontend team.
The Analytics Service does not need to be called directly to record data. It listens to events published by other services via RabbitMQ and maintains a local event store, as well as dedicated tables for users, campaigns, clicks, and simulation sends.
-
Accounts Service – publishes
user.created,user.updated, anduser.deletedonaccounts-event-exchange.Analytics mirrors user data into
analytics_usersfor department-based analysis and at-risk user lists.
-
Mailing Service (including the former Waves Service) – publishes mailing events on
mailing-event-exchange:mailing.send/mailing.schedulefor single emails. These events includeauth0Id.mailing.batch_send/mailing.batch_schedulefor batch sends. Entries includeauth0Id,waveId, andemailId.-
Also publishes wave lifecycle events on
waves-event-exchange:wave.createdwave.updatedwave.completed
Analytics stores every individual send in
simulation_sends, keyed byemailId, so that click events can be attributed to the correct user and campaign.
-
Report Service – publishes
report.submittedonreport-event-exchange.Analytics counts submitted reports and, via
xp.giveevents, infers confirmed phishing reports.
-
Education Service – publishes
education.assignandeducation.completed.Analytics counts false-positive reports, education assignments, and education completions.
-
XP Service – publishes
xp.giveandxp.givenonxp-event-exchange.When the reason includes
"phishing", Analytics marks the report as confirmed.When the reason includes
"compromised", Analytics records a click event as a fallback for cases where the Resend webhook may not have been received.
-
Resend Webhook (via API Gateway) – forwards
email.clickedevents to Analytics'/email-status/createendpoint.The
EmailStatusControllercallsrecordClickFromEmailId, which creates aClickEventlinked to the correct user and campaign usingsimulation_sends.
All aggregated data is queried via a REST API exposed through the API Gateway.
All analytics endpoints are JWT protected.
Required role: analyst or admin (enforced by the API Gateway's
RolesGuard).Include the JWT in the
Authorizationheader asBearer <token>.
All Analytics endpoints are accessed through the API Gateway:
http(s)://<gateway-host>/api/analytics
For local development:
http://localhost:3001/api/analytics
Adjust the port if your API Gateway runs on a different port.
GET /api/analytics/summary?period=7d|30d|90d
The period parameter is optional and defaults to 30d.
{
"detectionRate": {
"value": 40,
"delta": -5
},
"clickRate": {
"value": 12,
"delta": 3
},
"totalSimulations": {
"value": 120,
"delta": 20
},
"atRiskUsers": {
"value": 8,
"delta": -2
},
"trainingCompletion": {
"value": 55,
"delta": 10
}
}
valueis the current period's metric.deltais the percentage change compared to the previous period of equal length.
GET /api/analytics/detection-rate-over-time?period=7d|30d|90d
Returns daily buckets for the requested period.
[
{
"date": "2026-08-01",
"detectionRate": 50,
"clickRate": 10
},
{
"date": "2026-08-02",
"detectionRate": 66.67,
"clickRate": 20
}
]
GET /api/analytics/by-department?period=7d|30d|90d
[
{
"department": "Finance",
"sent": 30,
"reported": 12,
"detectionRate": 42.86,
"clickRate": 15
},
{
"department": "IT & Security",
"sent": 20,
"reported": 5,
"detectionRate": 60,
"clickRate": 25
}
]
sent= number of phishing emails sent to users in that department.reported= number of reports submitted by users in that department.detectionRate=confirmed / reported * 100ifreported > 0.clickRate=clicks / sent * 100ifsent > 0.
GET /api/analytics/at-risk-users?period=7d|30d|90d&limit=10
The limit parameter is optional and defaults to 10.
[
{
"auth0Id": "auth0|abc123",
"name": "John Doe",
"department": "Finance",
"clickRate": 80,
"riskLevel": "high"
}
]
clickRate= percentage of simulated emails that the user clicked.riskLevel=highifclickRate > 60, otherwisemedium.
GET /api/analytics/campaigns
Returns all campaigns (waves) ordered by start date in descending order.
Campaigns with an endDate in the past are automatically marked as completed.
[
{
"id": "wave-uuid",
"name": "Summer Phishing Wave",
"status": "completed",
"targetDepartments": [
"Finance",
"HR"
],
"startDate": "2026-08-01T09:00:00.000Z",
"endDate": "2026-08-10T17:00:00.000Z",
"createdBy": "auth0|admin"
}
]
GET /api/analytics/overview
Returns raw totals for simple counters.
The frontend should prefer /summary for the dashboard KPI cards.
{
"totalEmailsSent": 120,
"totalReports": 45,
"confirmedPhishing": 18,
"falsePositives": 27,
"totalXpGiven": 350,
"educationAssigned": 27,
"educationCompleted": 15
}
GET /api/analytics/reports?from=2026-01-01&to=2026-12-31
Both from and to are optional ISO date strings.
{
"submitted": 45,
"confirmed": 18,
"falsePositive": 27,
"detectionRate": 40
}
GET /api/analytics/mailing?from=2026-01-01&to=2026-12-31
Both from and to are optional ISO date strings.
{
"totalSent": 120,
"scheduled": 8
}
GET /api/analytics/timeseries?from=2026-08-01&to=2026-08-10
Returns daily counts of reports, emails sent, and XP given.
GET /api/analytics/leaderboard?limit=5
The limit parameter is optional and defaults to 10.
GET /api/analytics/users/:auth0Id
Returns analytics for the specified user.
The Analytics Service now implements the main features requested by the original frontend specification.
Feature from Specification | Current Status | Notes -- | -- | -- Total Simulations KPI | ✅ Available | /summary → totalSimulations Detection Rate KPI | ✅ Available | /summary → detectionRate Click Rate KPI | ✅ Available | /summary → clickRate (uses Resend webhook + XP fallback) At-Risk Users | ✅ Available | /at-risk-users Training Completion % KPI | ✅ Available | /summary → trainingCompletion KPI Deltas | ✅ Available | /summary returns value and delta Line Chart: Detection Rate Over Time | ✅ Available | /detection-rate-over-time Department Breakdown | ✅ Available | /by-department Campaign Performance Table | ✅ Available | /campaigns (data from waves)No polling needed — the frontend should call these endpoints on page load or on user-triggered refresh. Data is updated asynchronously.
JWT token — use the same Auth0 token and send it with every request.
-
Error handling:
401means the user should be redirected to login.403means the authenticated user does not have the required role.5xxerrors should display a generic error message. Backend logs should be checked for details.
All analytics endpoints are gated at the API Gateway using
RolesGuard, requiring either theadminoranalystrole.
Although the main dashboard features are now implemented, several enhancements are possible.
Extend /campaigns to include aggregate statistics such as:
Total emails sent.
Total clicks.
Total reports.
Detection rate.
Click rate.
The current at-risk calculation is primarily based on click rate.
Future versions could incorporate:
Time-to-click.
Multiple clicks by the same user.
Number of phishing simulations clicked.
Historical user behaviour.
Repeated failures across campaigns.
Ensure that Resend webhooks are consistently delivered and processed.
The existing XP fallback already provides additional coverage for cases where the Resend webhook is not received.
Add an endpoint that provides a user's complete analytics history, including:
Click history.
Report history.
Campaign participation.
Detection rate over time.
Education assignments and completions.
XP history.