chore: track route views for first few days
Identifying where users drop off is tricky without knowing what they are doing in system. Tracking first few days routes will likely give some insights.
This commit is contained in:
parent
8440ba1d3c
commit
5b881636bb
2 changed files with 24 additions and 0 deletions
|
|
@ -6,6 +6,7 @@ class TelemetryManager {
|
|||
|
||||
this.project_id = frappe.boot.posthog_project_id;
|
||||
this.telemetry_host = frappe.boot.posthog_host;
|
||||
this.site_age = frappe.boot.telemetry_site_age;
|
||||
|
||||
if (cint(frappe.boot.enable_telemetry) && this.project_id && this.telemetry_host) {
|
||||
this.enabled = true;
|
||||
|
|
@ -24,6 +25,7 @@ class TelemetryManager {
|
|||
});
|
||||
posthog.identify(frappe.boot.sitename);
|
||||
this.send_heartbeat();
|
||||
this.register_pageview_handler();
|
||||
} catch (e) {
|
||||
console.trace("Failed to initialize telemetry", e);
|
||||
this.enabled = false;
|
||||
|
|
@ -50,6 +52,16 @@ class TelemetryManager {
|
|||
this.capture("heartbeat", "frappe");
|
||||
}
|
||||
}
|
||||
|
||||
register_pageview_handler() {
|
||||
if (this.site_age && this.site_age > 5) {
|
||||
return;
|
||||
}
|
||||
|
||||
frappe.router.on("change", () => {
|
||||
posthog.capture("$pageview");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
frappe.telemetry = new TelemetryManager();
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ from contextlib import suppress
|
|||
from posthog import Posthog
|
||||
|
||||
import frappe
|
||||
from frappe.utils import getdate
|
||||
from frappe.utils.caching import site_cache
|
||||
|
||||
POSTHOG_PROJECT_FIELD = "posthog_project_id"
|
||||
POSTHOG_HOST_FIELD = "posthog_host"
|
||||
|
|
@ -20,6 +22,16 @@ def add_bootinfo(bootinfo):
|
|||
bootinfo.posthog_host = frappe.conf.get(POSTHOG_HOST_FIELD)
|
||||
bootinfo.posthog_project_id = frappe.conf.get(POSTHOG_PROJECT_FIELD)
|
||||
bootinfo.enable_telemetry = True
|
||||
bootinfo.telemetry_site_age = site_age()
|
||||
|
||||
|
||||
@site_cache(ttl=60 * 60 * 12)
|
||||
def site_age():
|
||||
try:
|
||||
est_creation = frappe.db.get_value("User", "Administrator", "creation")
|
||||
return (getdate() - getdate(est_creation)).days
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
|
||||
def init_telemetry():
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue