Skip to content

Commit

Permalink
Merge pull request #1015 from pateljannat/course-completion-funnel
Browse files Browse the repository at this point in the history
chore: analytics for course completion
  • Loading branch information
pateljannat authored Sep 13, 2024
2 parents d44c7cd + ba66c25 commit 9549f3a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 10 deletions.
4 changes: 4 additions & 0 deletions frontend/src/components/CourseCardOverlay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions lms/lms/doctype/course_chapter/course_chapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,4 @@


class CourseChapter(Document):
def after_insert(self):
capture("chapter_created", "lms")
pass
10 changes: 7 additions & 3 deletions lms/lms/doctype/course_lesson/course_lesson.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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("course_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
Expand Down
3 changes: 0 additions & 3 deletions lms/lms/doctype/lms_course/lms_course.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
3 changes: 1 addition & 2 deletions lms/www/lms.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit 9549f3a

Please sign in to comment.