Get User Analytics
curl --request GET \
--url https://api.example.com/api/user/analyticsimport requests
url = "https://api.example.com/api/user/analytics"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/api/user/analytics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/user/analytics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/user/analytics"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/user/analytics")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/user/analytics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"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
}
]
}
]
}
}
User API
Get User Analytics
Retrieve comprehensive learning analytics including time tracking, course breakdown, and daily statistics
GET
/
api
/
user
/
analytics
Get User Analytics
curl --request GET \
--url https://api.example.com/api/user/analyticsimport requests
url = "https://api.example.com/api/user/analytics"
response = requests.get(url)
print(response.text)const options = {method: 'GET'};
fetch('https://api.example.com/api/user/analytics', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.example.com/api/user/analytics",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"net/http"
"io"
)
func main() {
url := "https://api.example.com/api/user/analytics"
req, _ := http.NewRequest("GET", url, nil)
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := io.ReadAll(res.Body)
fmt.Println(string(body))
}HttpResponse<String> response = Unirest.get("https://api.example.com/api/user/analytics")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.example.com/api/user/analytics")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Get.new(url)
response = http.request(request)
puts response.read_body{
"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. TheuserId is automatically extracted from the authentication token.
Response
boolean
required
Indicates whether the request was successful
object
Analytics data object
Show analytics properties
Show analytics properties
number
Total learning time in seconds (excludes Home, Browse Courses, Course Details, Analytics, and Other pages)
number
Total number of learning sessions tracked
array
array
array
Course-by-course learning analytics sorted by total time (learning + quiz)
Show course breakdown item
Show course breakdown item
string
Course unique identifier
string
Course title (or “Unknown Course” if not found)
string | null
URL to course thumbnail image
number
Time spent in course player (/player/:courseId) in seconds
number
Number of course player sessions
number
Total time spent on quizzes across all chapters in seconds
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 Code | Description |
|---|---|
| 200 | Success |
| 401 | Unauthorized - Invalid or missing authentication token |
| 500 | Internal 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 0Sorting
- 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
⌘I