Implement analytics
This commit is contained in:
parent
fc4ce8e69e
commit
fe32505873
3 changed files with 91 additions and 8 deletions
36
src/index.ts
36
src/index.ts
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue