feat: telemetry using posthog

This commit is contained in:
Ankush Menat 2023-04-19 13:34:51 +05:30
parent 0d1c7fee42
commit 87a88195ec
6 changed files with 52 additions and 0 deletions

View file

@ -44,6 +44,7 @@ repos:
.*boilerplate.*|
frappe/www/website_script.js|
frappe/templates/includes/.*|
.*telemetry.bundle.js|
frappe/public/js/lib/.*
)$

View file

@ -29,6 +29,7 @@ app_include_js = [
"form.bundle.js",
"controls.bundle.js",
"report.bundle.js",
"telemetry.bundle.js",
]
app_include_css = [
"desk.bundle.css",
@ -419,3 +420,7 @@ after_job = [
"frappe.monitor.stop",
"frappe.utils.file_lock.release_document_locks",
]
extend_bootinfo = [
"frappe.utils.telemetry.add_bootinfo",
]

View file

@ -0,0 +1 @@
!function(t,e){var o,n,p,r;e.__SV||(window.posthog=e,e._i=[],e.init=function(i,s,a){function g(t,e){var o=e.split(".");2==o.length&&(t=t[o[0]],e=o[1]),t[e]=function(){t.push([e].concat(Array.prototype.slice.call(arguments,0)))}}(p=t.createElement("script")).type="text/javascript",p.async=!0,p.src=s.api_host+"/static/array.js",(r=t.getElementsByTagName("script")[0]).parentNode.insertBefore(p,r);var u=e;for(void 0!==a?u=e[a]=[]:a="posthog",u.people=u.people||[],u.toString=function(t){var e="posthog";return"posthog"!==a&&(e+="."+a),t||(e+=" (stub)"),e},u.people.toString=function(){return u.toString(1)+".people (stub)"},o="capture identify alias people.set people.set_once set_config register register_once unregister opt_out_capturing has_opted_out_capturing opt_in_capturing reset isFeatureEnabled onFeatureFlags".split(" "),n=0;n<o.length;n++)g(u,o[n]);e._i.push([i,s,a])},e.__SV=1)}(document,window.posthog||[]);

View file

@ -0,0 +1 @@
import "./telemetry/index.js";

View file

@ -0,0 +1,34 @@
import "../lib/posthog.js";
class TelemetryManager {
constructor() {
this.enabled = false;
this.project_id = frappe.boot.posthog_project_id;
this.telemetry_host = frappe.boot.posthog_host;
if (cint(frappe.boot.enable_telemetry) && this.project_id && this.telemetry_host) {
this.enabled = true;
}
}
initialize() {
if (!this.enabled) return;
posthog.init(this.project_id, {
api_host: this.telemetry_host,
autocapture: false,
capture_pageview: false,
capture_pageleave: false,
});
// posthog.identify("site", "")
}
log_event(event, app) {
if (!this.enabled) return;
posthog.capture(`${event}_${app}`);
}
}
frappe.telemetry = new TelemetryManager();
frappe.telemetry.initialize();

10
frappe/utils/telemetry.py Normal file
View file

@ -0,0 +1,10 @@
import frappe
def add_bootinfo(bootinfo):
if not frappe.get_system_settings("enable_telemetry"):
return
bootinfo.posthog_host = frappe.conf.posthog_host
bootinfo.posthog_project_id = frappe.conf.posthog_project_id
bootinfo.enable_telemetry = True