Overview
The Analytics Summary functions provide comprehensive metrics and KPIs for analyzing user engagement, performance, and risk across the Dashboard Dilemas platform. These functions support filtering by date range, client, game, and user area.get_analytics_summary()
Retrieves a comprehensive summary of analytics metrics including user engagement, session statistics, and risk indicators.Function Signature
Parameters
Optional array of filter criteria
Returns
Total number of users in the system (unfiltered by date)
Number of users who have played sessions in the filtered period
Total number of game sessions in the filtered period
Average score across all sessions (percentage, 0-100)
Average session duration in seconds
Engagement percentage: (activeUsers / totalUsers) * 100
Percentage of sessions with score below 60% (failing threshold)
Knowledge improvement metric (currently static at 12)
Example Usage
Response Example
Performance Notes
This function uses caching with a 15-minute TTL (900 seconds) to improve performance. The cache is invalidated when filter parameters change.
get_performance_by_area()
Retrieves performance metrics grouped by user areas/departments.Function Signature
Parameters
Same filter options as
get_analytics_summary()Returns
Array of area performance objects:Name of the area/department
Number of distinct users in this area
Average score for this area (percentage, 0-100)
Total sessions played by users in this area
Example Usage
Response Example
get_hourly_distribution()
Returns session count distribution by hour of day.Function Signature
Parameters
Same filter options as
get_analytics_summary()Returns
Associative array with hour (0-23) as keys and session count as values.Example Usage
Response Example
get_game_performance()
Retrieves detailed performance metrics for all games.Function Signature
Parameters
Same filter options as
get_analytics_summary()Returns
Array of game performance objects:Game/dilemma title
Total number of sessions for this game
Average score (percentage, 0-100)
Sum of all points earned across sessions
Average session duration in seconds
Percentage of sessions with score >= 60%
Example Usage
Response Example
Additional Analytics Functions
get_activity_over_time()
Returns daily session counts for trend analysis.get_category_distribution()
Returns session distribution by game category/type.get_weekday_distribution()
Returns session distribution by day of week.get_score_distribution()
Returns session counts grouped by score ranges.get_top_users_engagement()
Returns top users by total score and session count.Number of top users to return
display_name, sessions, and total_score.
get_top_risk_questions()
Identifies questions with highest failure rates.Number of risky questions to return
text, category, total_answers, fail_count, and avg_score.
Filter Helper Function
get_analytics_query_parts()
Internal helper that builds SQL WHERE clauses and parameters from filters.Implementation Notes
Score Calculation
Scores are normalized to percentages (0-100) based on each game’s maximum possible score:- For “Angel vs Demonio” games:
questions_count * 3 - For standard games: Sum of question scores
- Default fallback: 100 points
Risk Threshold
Sessions with scores below 60% are considered “at risk” and contribute to the risk index.Performance Optimization
get_analytics_summary()uses a 15-minute cache- All queries use prepared statements with parameterized values
- Complex aggregations are handled in single SQL queries where possible
- LEFT JOINs are preferred over correlated subqueries
Error Handling
All analytics functions return safe defaults on error:- Empty arrays for list functions
- Zero values for count/metric functions
- Functions catch PDOException and log errors while returning gracefully