-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b956c4e
commit 703fafd
Showing
19 changed files
with
151 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
import { useStorage } from "@vueuse/core"; | ||
import { call } from "frappe-ui"; | ||
import "../../../frappe/frappe/public/js/lib/posthog.js"; | ||
|
||
const APP = "lms"; | ||
const SITENAME = window.location.hostname; | ||
|
||
declare global { | ||
interface Window { | ||
posthog: any; | ||
} | ||
} | ||
|
||
const telemetry = useStorage("telemetry", { | ||
enabled: false, | ||
project_id: "", | ||
host: "", | ||
}); | ||
|
||
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 { | ||
data: { | ||
user: string; | ||
[key: string]: string | number | boolean | object; | ||
}; | ||
} | ||
|
||
export function capture( | ||
event: string, | ||
options: CaptureOptions = { data: { user: "" } } | ||
) { | ||
if (!telemetry.value.enabled) return; | ||
window.posthog.capture(`${APP}_${event}`, options); | ||
} | ||
|
||
export function recordSession() { | ||
if (!telemetry.value.enabled) return; | ||
if (window.posthog && window.posthog.__loaded) { | ||
window.posthog.startSessionRecording(); | ||
} | ||
} | ||
|
||
export function stopSession() { | ||
if (!telemetry.value.enabled) return; | ||
if ( | ||
window.posthog && | ||
window.posthog.__loaded && | ||
window.posthog.sessionRecordingStarted() | ||
) { | ||
window.posthog.stopSessionRecording(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.