From 76c3e630cc52a81ee8179a535ce80bb777f251c9 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Fri, 13 Sep 2024 11:18:17 +0530 Subject: [PATCH] chore: analytics for course completion --- frontend/src/components/CourseCardOverlay.vue | 4 ++++ lms/lms/doctype/course_chapter/course_chapter.py | 3 +-- lms/lms/doctype/course_lesson/course_lesson.py | 10 +++++++--- lms/lms/doctype/lms_course/lms_course.py | 3 --- lms/www/lms.py | 3 +-- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/frontend/src/components/CourseCardOverlay.vue b/frontend/src/components/CourseCardOverlay.vue index 3b8aa1702..98f82fb23 100644 --- a/frontend/src/components/CourseCardOverlay.vue +++ b/frontend/src/components/CourseCardOverlay.vue @@ -117,6 +117,7 @@ import { BookOpen, Users, Star } from 'lucide-vue-next' import { computed, inject } from 'vue' import { Button, createResource } from 'frappe-ui' import { createToast } from '@/utils/' +import { capture } from '@/telemetry' import { useRouter } from 'vue-router' const router = useRouter() @@ -155,6 +156,9 @@ function enrollStudent() { course: props.course.data.name, }) .then(() => { + capture('enrolled_in_course', { + course: props.course.data.name, + }) createToast({ title: 'Enrolled Successfully', icon: 'check', diff --git a/lms/lms/doctype/course_chapter/course_chapter.py b/lms/lms/doctype/course_chapter/course_chapter.py index d980e26a0..930fc34c9 100644 --- a/lms/lms/doctype/course_chapter/course_chapter.py +++ b/lms/lms/doctype/course_chapter/course_chapter.py @@ -7,5 +7,4 @@ class CourseChapter(Document): - def after_insert(self): - capture("chapter_created", "lms") + pass diff --git a/lms/lms/doctype/course_lesson/course_lesson.py b/lms/lms/doctype/course_lesson/course_lesson.py index a12165ff8..6157d1100 100644 --- a/lms/lms/doctype/course_lesson/course_lesson.py +++ b/lms/lms/doctype/course_lesson/course_lesson.py @@ -24,9 +24,6 @@ def on_update(self): for section in dynamic_documents: self.update_lesson_name_in_document(section) - def after_insert(self): - capture("lesson_created", "lms") - def update_lesson_name_in_document(self, section): doctype_map = {"Exercise": "LMS Exercise", "Quiz": "LMS Quiz"} macros = find_macros(self.body) @@ -116,6 +113,8 @@ def save_progress(lesson, course): ).save(ignore_permissions=True) progress = get_course_progress(course) + capture_progress_for_analytics(progress, course) + # Had to get doc, as on_change doesn't trigger when you use set_value. The trigger is necesary for badge to get assigned. enrollment = frappe.get_doc("LMS Enrollment", membership) enrollment.progress = progress @@ -125,6 +124,11 @@ def save_progress(lesson, course): return progress +def capture_progress_for_analytics(progress, course): + if progress in [25, 50, 75, 100]: + capture("lesson_progress", "lms", {"course": course, "progress": progress}) + + def get_quiz_progress(lesson): lesson_details = frappe.db.get_value( "Course Lesson", lesson, ["body", "content"], as_dict=1 diff --git a/lms/lms/doctype/lms_course/lms_course.py b/lms/lms/doctype/lms_course/lms_course.py index d07b02acf..aaf60d57a 100644 --- a/lms/lms/doctype/lms_course/lms_course.py +++ b/lms/lms/doctype/lms_course/lms_course.py @@ -48,9 +48,6 @@ def on_update(self): if not self.upcoming and self.has_value_changed("upcoming"): self.send_email_to_interested_users() - def after_insert(self): - capture("course_created", "lms") - def send_email_to_interested_users(self): interested_users = frappe.get_all( "LMS Course Interest", {"course": self.name}, ["name", "user"] diff --git a/lms/www/lms.py b/lms/www/lms.py index 6a75ce06e..ca95db480 100644 --- a/lms/www/lms.py +++ b/lms/www/lms.py @@ -17,8 +17,7 @@ def get_context(): csrf_token = frappe.sessions.get_csrf_token() frappe.db.commit() # nosemgrep context.csrf_token = csrf_token - if frappe.session.user != "Guest": - capture("active_site", "lms") + capture("active_site", "lms") return context