Skip to main content
GET
/
api
/
user
/
analytics
Get User Analytics
curl --request GET \
  --url https://api.example.com/api/user/analytics
{
  "success": true,
  "analytics": {
    "totalDuration": 18450,
    "totalSessions": 87,
    "pageStats": [
      {
        "page": "Course Player",
        "path": "/player/60d5ec49f1b2c72b8c8e4f1a",
        "totalDuration": 12600,
        "visits": 42
      },
      {
        "page": "Quiz",
        "path": "/quiz/60d5ec49f1b2c72b8c8e4f1a/chapter1",
        "totalDuration": 3420,
        "visits": 15
      },
      {
        "page": "Profile",
        "path": "/profile",
        "totalDuration": 2430,
        "visits": 30
      }
    ],
    "dailyStats": [
      { "date": "2024-03-15", "duration": 2100 },
      { "date": "2024-03-16", "duration": 3600 },
      { "date": "2024-03-17", "duration": 1800 },
      { "date": "2024-03-18", "duration": 4200 },
      { "date": "2024-03-19", "duration": 2700 },
      { "date": "2024-03-20", "duration": 3150 },
      { "date": "2024-03-21", "duration": 900 }
    ],
    "courseBreakdown": [
      {
        "courseId": "60d5ec49f1b2c72b8c8e4f1a",
        "courseTitle": "Complete Web Development Bootcamp",
        "courseThumbnail": "https://res.cloudinary.com/skillrise/image/upload/v1234567890/courses/web-dev.jpg",
        "learningDuration": 12600,
        "learningSessions": 42,
        "totalQuizDuration": 3420,
        "chapters": [
          {
            "chapterId": "chapter1",
            "chapterTitle": "HTML Fundamentals",
            "quizDuration": 1200,
            "quizSessions": 5
          },
          {
            "chapterId": "chapter2",
            "chapterTitle": "CSS Styling",
            "quizDuration": 1080,
            "quizSessions": 4
          },
          {
            "chapterId": "chapter3",
            "chapterTitle": "JavaScript Basics",
            "quizDuration": 1140,
            "quizSessions": 6
          }
        ]
      },
      {
        "courseId": "60d5ec49f1b2c72b8c8e4f1b",
        "courseTitle": "Python for Data Science",
        "courseThumbnail": "https://res.cloudinary.com/skillrise/image/upload/v1234567890/courses/python-ds.jpg",
        "learningDuration": 2100,
        "learningSessions": 8,
        "totalQuizDuration": 330,
        "chapters": [
          {
            "chapterId": "chapter1",
            "chapterTitle": "Python Basics",
            "quizDuration": 330,
            "quizSessions": 2
          }
        ]
      }
    ]
  }
}

Authentication

This endpoint requires authentication via Clerk. The userId is automatically extracted from the authentication token.

Response

success
boolean
required
Indicates whether the request was successful
analytics
object
Analytics data object
message
string
Error message if success is false

Response Example

{
  "success": true,
  "analytics": {
    "totalDuration": 18450,
    "totalSessions": 87,
    "pageStats": [
      {
        "page": "Course Player",
        "path": "/player/60d5ec49f1b2c72b8c8e4f1a",
        "totalDuration": 12600,
        "visits": 42
      },
      {
        "page": "Quiz",
        "path": "/quiz/60d5ec49f1b2c72b8c8e4f1a/chapter1",
        "totalDuration": 3420,
        "visits": 15
      },
      {
        "page": "Profile",
        "path": "/profile",
        "totalDuration": 2430,
        "visits": 30
      }
    ],
    "dailyStats": [
      { "date": "2024-03-15", "duration": 2100 },
      { "date": "2024-03-16", "duration": 3600 },
      { "date": "2024-03-17", "duration": 1800 },
      { "date": "2024-03-18", "duration": 4200 },
      { "date": "2024-03-19", "duration": 2700 },
      { "date": "2024-03-20", "duration": 3150 },
      { "date": "2024-03-21", "duration": 900 }
    ],
    "courseBreakdown": [
      {
        "courseId": "60d5ec49f1b2c72b8c8e4f1a",
        "courseTitle": "Complete Web Development Bootcamp",
        "courseThumbnail": "https://res.cloudinary.com/skillrise/image/upload/v1234567890/courses/web-dev.jpg",
        "learningDuration": 12600,
        "learningSessions": 42,
        "totalQuizDuration": 3420,
        "chapters": [
          {
            "chapterId": "chapter1",
            "chapterTitle": "HTML Fundamentals",
            "quizDuration": 1200,
            "quizSessions": 5
          },
          {
            "chapterId": "chapter2",
            "chapterTitle": "CSS Styling",
            "quizDuration": 1080,
            "quizSessions": 4
          },
          {
            "chapterId": "chapter3",
            "chapterTitle": "JavaScript Basics",
            "quizDuration": 1140,
            "quizSessions": 6
          }
        ]
      },
      {
        "courseId": "60d5ec49f1b2c72b8c8e4f1b",
        "courseTitle": "Python for Data Science",
        "courseThumbnail": "https://res.cloudinary.com/skillrise/image/upload/v1234567890/courses/python-ds.jpg",
        "learningDuration": 2100,
        "learningSessions": 8,
        "totalQuizDuration": 330,
        "chapters": [
          {
            "chapterId": "chapter1",
            "chapterTitle": "Python Basics",
            "quizDuration": 330,
            "quizSessions": 2
          }
        ]
      }
    ]
  }
}
{
  "success": false,
  "message": "An unexpected error occurred"
}

Error Codes

Status CodeDescription
200Success
401Unauthorized - Invalid or missing authentication token
500Internal server error

Analytics Calculation Details

Page Filtering

The following pages are excluded from analytics calculations:
  • Home
  • Browse Courses
  • Course Details
  • Analytics
  • Other

Course Learning Time

Tracked from sessions where the path starts with /player/:courseId

Quiz Time

Tracked from sessions where the path starts with /quiz/:courseId/:chapterId

Daily Statistics

Provides a 7-day rolling window with data for each day, even if duration is 0

Sorting

  • pageStats: Sorted by totalDuration (descending)
  • courseBreakdown: Sorted by total time (learning + quiz duration, descending)
  • chapters: Sorted by quizDuration (descending)

Use Cases

  • Display user’s learning dashboard
  • Track study habits and patterns
  • Identify most engaged courses
  • Generate progress reports
  • Visualize daily learning trends
  • Show chapter-level quiz performance