feat: add python posthog library
This commit is contained in:
parent
6c3f29efe7
commit
f63c420798
5 changed files with 42 additions and 3 deletions
|
|
@ -178,7 +178,7 @@ frappe.setup.SetupWizard = class SetupWizard extends frappe.ui.Slides {
|
|||
}
|
||||
|
||||
action_on_complete() {
|
||||
frappe.telemetry.log("completed", "setup");
|
||||
frappe.telemetry.capture("initated_client_side", "setup");
|
||||
if (!this.current_slide.set_values()) return;
|
||||
this.update_values();
|
||||
this.show_working_state();
|
||||
|
|
@ -347,7 +347,7 @@ frappe.setup.SetupWizardSlide = class SetupWizardSlide extends frappe.ui.Slide {
|
|||
let me = this;
|
||||
this.fields.filter(frappe.model.is_value_type).forEach((field) => {
|
||||
me.get_input(field.fieldname).on("change", function () {
|
||||
frappe.telemetry.log(`${field.fieldname}_set`, "setup");
|
||||
frappe.telemetry.capture(`${field.fieldname}_set`, "setup");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -64,6 +64,9 @@ def setup_complete(args):
|
|||
|
||||
@frappe.task()
|
||||
def process_setup_stages(stages, user_input, is_background_task=False):
|
||||
from frappe.utils.telemetry import capture
|
||||
|
||||
capture("initated_server_side", "setup")
|
||||
try:
|
||||
frappe.flags.in_setup_wizard = True
|
||||
current_task = None
|
||||
|
|
@ -88,6 +91,7 @@ def process_setup_stages(stages, user_input, is_background_task=False):
|
|||
)
|
||||
else:
|
||||
run_setup_success(user_input)
|
||||
capture("completed_server_side", "setup")
|
||||
if not is_background_task:
|
||||
return {"status": "ok"}
|
||||
frappe.publish_realtime("setup_task", {"status": "ok"}, user=frappe.session.user)
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@ class TelemetryManager {
|
|||
}
|
||||
}
|
||||
|
||||
log(event, app) {
|
||||
capture(event, app) {
|
||||
if (!this.enabled) return;
|
||||
posthog.capture(`${app}_${event}`);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,12 @@
|
|||
""" Basic telemetry for improving apps.
|
||||
|
||||
WARNING: Everything in this file should be treated "internal" and is subjected to change or get
|
||||
removed without any warning.
|
||||
"""
|
||||
from contextlib import suppress
|
||||
|
||||
from posthog import Posthog
|
||||
|
||||
import frappe
|
||||
|
||||
|
||||
|
|
@ -8,3 +17,28 @@ def add_bootinfo(bootinfo):
|
|||
bootinfo.posthog_host = frappe.conf.posthog_host
|
||||
bootinfo.posthog_project_id = frappe.conf.posthog_project_id
|
||||
bootinfo.enable_telemetry = True
|
||||
|
||||
|
||||
def init_telemetry():
|
||||
"""Init posthog for server side telemetry."""
|
||||
if hasattr(frappe.local, "posthog"):
|
||||
return
|
||||
|
||||
if not frappe.get_system_settings("enable_telemetry"):
|
||||
return
|
||||
|
||||
posthog_host = frappe.conf.posthog_host
|
||||
posthog_project_id = frappe.conf.posthog_project_id
|
||||
|
||||
if not posthog_host or not posthog_project_id:
|
||||
return
|
||||
|
||||
with suppress(Exception):
|
||||
frappe.local.posthog = Posthog(posthog_project_id, host=posthog_host)
|
||||
|
||||
|
||||
def capture(event, app):
|
||||
init_telemetry()
|
||||
ph: Posthog = getattr(frappe.local, "posthog", None)
|
||||
with suppress(Exception):
|
||||
ph and ph.capture(frappe.local.site, f"{app}_{event}")
|
||||
|
|
|
|||
|
|
@ -79,6 +79,7 @@ dependencies = [
|
|||
"google-api-python-client~=2.2.0",
|
||||
"google-auth-oauthlib~=0.4.4",
|
||||
"google-auth~=1.29.0",
|
||||
"posthog~=3.0.1",
|
||||
]
|
||||
|
||||
[build-system]
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue