Implement analytics

This commit is contained in:
MassiveBox 2025-04-16 23:56:24 +02:00
parent fc4ce8e69e
commit fe32505873
Signed by: massivebox
GPG key ID: 9B74D3A59181947D
3 changed files with 91 additions and 8 deletions

View file

@ -9,10 +9,12 @@ import {
import {migrate} from "@/migration";
import {EditorManager, PluginEditor} from "@/editor";
import {PluginConfig, PluginConfigViewer} from "@/config";
import {Analytics} from "@/analytics";
export default class DrawJSPlugin extends Plugin {
config: PluginConfig;
analytics: Analytics;
async onload() {
@ -20,16 +22,15 @@ export default class DrawJSPlugin extends Plugin {
EditorManager.registerTab(this);
migrate()
this.config = new PluginConfig();
await this.config.load();
let configViewer = new PluginConfigViewer(this.config, this);
await configViewer.load();
await this.startConfig();
await this.startAnalytics();
this.protyleSlash = [{
id: "insert-drawing",
filter: ["Insert Drawing", "Add drawing", "whiteboard", "freehand", "graphics", "jsdraw"],
html: getMenuHTML("iconDraw", this.i18n.insertDrawing),
callback: (protyle: Protyle) => {
void this.analytics.sendEvent('create');
const fileID = generateRandomString();
const syncID = generateTimeString() + '-' + generateRandomString();
protyle.insert(getMarkdownBlock(fileID, syncID), true, false);
@ -44,6 +45,7 @@ export default class DrawJSPlugin extends Plugin {
icon: "iconDraw",
label: "Edit with js-draw",
click: () => {
void this.analytics.sendEvent('edit');
new EditorManager(new PluginEditor(ids.fileID, ids.syncID)).open(this)
}
})
@ -51,4 +53,30 @@ export default class DrawJSPlugin extends Plugin {
}
onunload() {
void this.analytics.sendEvent("unload");
}
uninstall() {
void this.analytics.sendEvent("uninstall");
}
private async startConfig() {
this.config = new PluginConfig();
await this.config.load();
let configViewer = new PluginConfigViewer(this.config, this);
await configViewer.load();
}
private async startAnalytics() {
this.analytics = new Analytics(this.config.options.analytics);
if(this.config.getFirstRun()) {
await this.config.save();
void this.analytics.sendEvent('install');
}else{
void this.analytics.sendEvent('load');
}
}
}