From 93f0f8ab4477b5b1de6c5a68994509c71ae1d4a2 Mon Sep 17 00:00:00 2001 From: Jannat Patel Date: Thu, 18 May 2023 14:26:48 +0530 Subject: [PATCH] fix: telemetry capture on client side --- lms/hooks.py | 1 + lms/lms/utils.py | 16 ++++++++++++++++ lms/public/css/style.css | 2 +- lms/public/js/website.bundle.js | 1 - lms/templates/lms_base.html | 13 +++++++++++++ 5 files changed, 31 insertions(+), 2 deletions(-) diff --git a/lms/hooks.py b/lms/hooks.py index 2a6e7f15d..d838d31e3 100644 --- a/lms/hooks.py +++ b/lms/hooks.py @@ -235,6 +235,7 @@ "lms.lms.utils.get_filtered_membership", "lms.lms.utils.show_start_learing_cta", "lms.lms.utils.can_create_courses", + "lms.lms.utils.get_telemetry_boot_info", ], "filters": [], } diff --git a/lms/lms/utils.py b/lms/lms/utils.py index e8c2554dc..effa09cd8 100644 --- a/lms/lms/utils.py +++ b/lms/lms/utils.py @@ -698,3 +698,19 @@ def get_course_completion_data(): } ], } + + +def get_telemetry_boot_info(): + POSTHOG_PROJECT_FIELD = "posthog_project_id" + POSTHOG_HOST_FIELD = "posthog_host" + + if not frappe.conf.get(POSTHOG_HOST_FIELD) or not frappe.conf.get( + POSTHOG_PROJECT_FIELD + ): + return {} + + return { + "posthog_host": frappe.conf.get(POSTHOG_HOST_FIELD), + "posthog_project_id": frappe.conf.get(POSTHOG_PROJECT_FIELD), + "enable_telemetry": 1, + } diff --git a/lms/public/css/style.css b/lms/public/css/style.css index c04f26b1c..c8e35a677 100644 --- a/lms/public/css/style.css +++ b/lms/public/css/style.css @@ -124,7 +124,7 @@ textarea.field-input { border-bottom: none; } -.outline-lesson .level { +.outline-lesson .level, .chapter-container .level { justify-content: start; } diff --git a/lms/public/js/website.bundle.js b/lms/public/js/website.bundle.js index b5fc1f1b7..7d1dfd83a 100644 --- a/lms/public/js/website.bundle.js +++ b/lms/public/js/website.bundle.js @@ -1,4 +1,3 @@ import "./profile.js"; import "./common_functions.js"; import "../../../../frappe/frappe/public/js/frappe/ui/chart.js"; -import "../../../../frappe/frappe/public/js/telemetry/index.js"; diff --git a/lms/templates/lms_base.html b/lms/templates/lms_base.html index 507589971..33fc770db 100644 --- a/lms/templates/lms_base.html +++ b/lms/templates/lms_base.html @@ -7,3 +7,16 @@ Hello, world! {% endblock %} {% endblock %} + +{%- block script -%} + {{ super() }} + {% if frappe.get_system_settings("enable_telemetry") %} + {% set telemetry_boot_info = get_telemetry_boot_info() %} + + {{ include_script("telemetry.bundle.js") }} + {% endif %} +{%- endblock -%} \ No newline at end of file