Merge branch 'develop' of https://github.com/frappe/lms into zoom-refactor
This commit is contained in:
@@ -9,18 +9,14 @@
|
|||||||
<script setup>
|
<script setup>
|
||||||
import { FrappeUIProvider } from 'frappe-ui'
|
import { FrappeUIProvider } from 'frappe-ui'
|
||||||
import { Dialogs } from '@/utils/dialogs'
|
import { Dialogs } from '@/utils/dialogs'
|
||||||
import { computed, onMounted, onUnmounted, ref } from 'vue'
|
import { computed, onUnmounted, ref } from 'vue'
|
||||||
import { useScreenSize } from './utils/composables'
|
import { useScreenSize } from './utils/composables'
|
||||||
import DesktopLayout from './components/DesktopLayout.vue'
|
import DesktopLayout from './components/DesktopLayout.vue'
|
||||||
import MobileLayout from './components/MobileLayout.vue'
|
import MobileLayout from './components/MobileLayout.vue'
|
||||||
import NoSidebarLayout from './components/NoSidebarLayout.vue'
|
import NoSidebarLayout from './components/NoSidebarLayout.vue'
|
||||||
import { stopSession } from '@/telemetry'
|
|
||||||
import { init as initTelemetry } from '@/telemetry'
|
|
||||||
import { usersStore } from '@/stores/user'
|
|
||||||
import { useRouter } from 'vue-router'
|
import { useRouter } from 'vue-router'
|
||||||
|
|
||||||
const screenSize = useScreenSize()
|
const screenSize = useScreenSize()
|
||||||
let { userResource } = usersStore()
|
|
||||||
const router = useRouter()
|
const router = useRouter()
|
||||||
const noSidebar = ref(false)
|
const noSidebar = ref(false)
|
||||||
|
|
||||||
@@ -44,10 +40,6 @@ const Layout = computed(() => {
|
|||||||
return DesktopLayout
|
return DesktopLayout
|
||||||
})
|
})
|
||||||
|
|
||||||
onMounted(async () => {
|
|
||||||
if (userResource.data) await initTelemetry()
|
|
||||||
})
|
|
||||||
|
|
||||||
onUnmounted(() => {
|
onUnmounted(() => {
|
||||||
noSidebar.value = false
|
noSidebar.value = false
|
||||||
stopSession()
|
stopSession()
|
||||||
|
|||||||
@@ -1,98 +1,96 @@
|
|||||||
import { useStorage } from "@vueuse/core";
|
import '../../../frappe/frappe/public/js/lib/posthog.js'
|
||||||
import { call } from "frappe-ui";
|
import { createResource } from 'frappe-ui'
|
||||||
import "../../../frappe/frappe/public/js/lib/posthog.js";
|
|
||||||
|
|
||||||
const APP = "lms";
|
|
||||||
const SITENAME = window.location.hostname;
|
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
interface Window {
|
interface Window {
|
||||||
posthog: any;
|
posthog: any
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
type PosthogSettings = {
|
||||||
const telemetry = useStorage("telemetry", {
|
posthog_project_id: string
|
||||||
enabled: false,
|
posthog_host: string
|
||||||
project_id: "",
|
enable_telemetry: boolean
|
||||||
host: "",
|
telemetry_site_age: number
|
||||||
});
|
|
||||||
|
|
||||||
export async function init() {
|
|
||||||
await set_enabled();
|
|
||||||
if (!telemetry.value.enabled) return;
|
|
||||||
try {
|
|
||||||
await set_credentials();
|
|
||||||
window.posthog.init(telemetry.value.project_id, {
|
|
||||||
api_host: telemetry.value.host,
|
|
||||||
autocapture: false,
|
|
||||||
person_profiles: "always",
|
|
||||||
capture_pageview: true,
|
|
||||||
capture_pageleave: true,
|
|
||||||
disable_session_recording: false,
|
|
||||||
session_recording: {
|
|
||||||
maskAllInputs: false,
|
|
||||||
maskInputOptions: {
|
|
||||||
password: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
loaded: (posthog) => {
|
|
||||||
window.posthog = posthog;
|
|
||||||
window.posthog.identify(SITENAME);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (e) {
|
|
||||||
console.trace("Failed to initialize telemetry", e);
|
|
||||||
telemetry.value.enabled = false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function set_enabled() {
|
|
||||||
if (telemetry.value.enabled) return;
|
|
||||||
|
|
||||||
await call("lms.lms.telemetry.is_enabled").then((res) => {
|
|
||||||
telemetry.value.enabled = res;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
async function set_credentials() {
|
|
||||||
if (!telemetry.value.enabled) return;
|
|
||||||
if (telemetry.value.project_id && telemetry.value.host) return;
|
|
||||||
|
|
||||||
await call("lms.lms.telemetry.get_credentials").then((res) => {
|
|
||||||
telemetry.value.project_id = res.project_id;
|
|
||||||
telemetry.value.host = res.telemetry_host;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CaptureOptions {
|
interface CaptureOptions {
|
||||||
data: {
|
data: {
|
||||||
user: string;
|
user: string
|
||||||
[key: string]: string | number | boolean | object;
|
[key: string]: string | number | boolean | object
|
||||||
};
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function capture(
|
let posthog: typeof window.posthog = window.posthog
|
||||||
|
|
||||||
|
// Posthog Settings
|
||||||
|
let posthogSettings = createResource({
|
||||||
|
url: 'lms.lms.telemetry.get_posthog_settings',
|
||||||
|
cache: 'posthog_settings',
|
||||||
|
onSuccess: (ps: PosthogSettings) => initPosthog(ps),
|
||||||
|
})
|
||||||
|
|
||||||
|
let isTelemetryEnabled = () => {
|
||||||
|
if (!posthogSettings.data) return false
|
||||||
|
|
||||||
|
return (
|
||||||
|
posthogSettings.data.enable_telemetry &&
|
||||||
|
posthogSettings.data.posthog_project_id &&
|
||||||
|
posthogSettings.data.posthog_host
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posthog Initialization
|
||||||
|
function initPosthog(ps: PosthogSettings) {
|
||||||
|
if (!isTelemetryEnabled()) return
|
||||||
|
|
||||||
|
posthog.init(ps.posthog_project_id, {
|
||||||
|
api_host: ps.posthog_host,
|
||||||
|
person_profiles: 'identified_only',
|
||||||
|
autocapture: false,
|
||||||
|
capture_pageview: true,
|
||||||
|
capture_pageleave: true,
|
||||||
|
enable_heatmaps: false,
|
||||||
|
disable_session_recording: false,
|
||||||
|
loaded: (ph: typeof posthog) => {
|
||||||
|
window.posthog = ph
|
||||||
|
ph.identify(window.location.hostname)
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
// Posthog Functions
|
||||||
|
function capture(
|
||||||
event: string,
|
event: string,
|
||||||
options: CaptureOptions = { data: { user: "" } }
|
options: CaptureOptions = { data: { user: '' } },
|
||||||
) {
|
) {
|
||||||
if (!telemetry.value.enabled) return;
|
if (!isTelemetryEnabled()) return
|
||||||
window.posthog.capture(`${APP}_${event}`, options);
|
window.posthog.capture(`lms_${event}`, options)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function recordSession() {
|
function startRecording() {
|
||||||
if (!telemetry.value.enabled) return;
|
if (!isTelemetryEnabled()) return
|
||||||
if (window.posthog && window.posthog.__loaded) {
|
if (window.posthog?.__loaded) {
|
||||||
window.posthog.startSessionRecording();
|
window.posthog.startSessionRecording()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function stopSession() {
|
function stopRecording() {
|
||||||
if (!telemetry.value.enabled) return;
|
if (!isTelemetryEnabled()) return
|
||||||
if (
|
if (window.posthog?.__loaded && window.posthog.sessionRecordingStarted()) {
|
||||||
window.posthog &&
|
window.posthog.stopSessionRecording()
|
||||||
window.posthog.__loaded &&
|
}
|
||||||
window.posthog.sessionRecordingStarted()
|
}
|
||||||
) {
|
|
||||||
window.posthog.stopSessionRecording();
|
// Posthog Plugin
|
||||||
}
|
function posthogPlugin(app: any) {
|
||||||
|
app.config.globalProperties.posthog = posthog
|
||||||
|
if (!window.posthog?.length) posthogSettings.fetch()
|
||||||
|
}
|
||||||
|
|
||||||
|
export {
|
||||||
|
posthog,
|
||||||
|
posthogSettings,
|
||||||
|
posthogPlugin,
|
||||||
|
capture,
|
||||||
|
startRecording,
|
||||||
|
stopRecording,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
__version__ = "2.28.1"
|
__version__ = "2.29.0"
|
||||||
|
|||||||
@@ -1,18 +1,12 @@
|
|||||||
import frappe
|
import frappe
|
||||||
|
from frappe.utils.telemetry import POSTHOG_HOST_FIELD, POSTHOG_PROJECT_FIELD
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def is_enabled():
|
def get_posthog_settings():
|
||||||
return bool(
|
|
||||||
frappe.get_system_settings("enable_telemetry")
|
|
||||||
and frappe.conf.get("posthog_host")
|
|
||||||
and frappe.conf.get("posthog_project_id")
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
|
||||||
def get_credentials():
|
|
||||||
return {
|
return {
|
||||||
"project_id": frappe.conf.get("posthog_project_id"),
|
"posthog_project_id": frappe.conf.get(POSTHOG_PROJECT_FIELD),
|
||||||
"telemetry_host": frappe.conf.get("posthog_host"),
|
"posthog_host": frappe.conf.get(POSTHOG_HOST_FIELD),
|
||||||
|
"enable_telemetry": frappe.get_system_settings("enable_telemetry"),
|
||||||
|
"telemetry_site_age": frappe.utils.telemetry.site_age(),
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user