From 8d3f3942924a93cbb946fb2fcdebe993bd842604 Mon Sep 17 00:00:00 2001 From: Justin Greywolf Date: Sun, 18 Feb 2024 16:23:35 -0800 Subject: [PATCH] Add send behavior events for mixpanel --- .../lib/client/clientApi/PowerPointService.ts | 6 ++++ .../src/lib/client/clientApi/WordService.ts | 6 ++++ .../src/lib/client/clientApi/officeManager.ts | 28 +++++++++++++++++++ .../lib/client/components/DocumentCard.svelte | 6 ++-- 4 files changed, 42 insertions(+), 4 deletions(-) diff --git a/packages/office/src/lib/client/clientApi/PowerPointService.ts b/packages/office/src/lib/client/clientApi/PowerPointService.ts index 856a8f7..5420123 100644 --- a/packages/office/src/lib/client/clientApi/PowerPointService.ts +++ b/packages/office/src/lib/client/clientApi/PowerPointService.ts @@ -5,6 +5,7 @@ import { showUserMessage } from '../stores/messaging'; import type { Diagram } from './officeManager'; import { authStore } from '../stores/auth'; import { OfficeService } from './OfficeService'; +import { sendBehaviorEvent } from '../util/sendEvents'; export class PowerPointService extends OfficeService { authToken = authStore.accessKey(); @@ -73,6 +74,11 @@ export class PowerPointService extends OfficeService { const docDetails = splitReferenceToken(tag); const document = await this.mermaidChartApi.getDocument(docDetails.documentID); if(!document) { + sendBehaviorEvent( + 'Could not find document in presentation', { + area: 'sync-diagrams', + eventID: `REPLACE_DIAGRAM_POWERPOINT` + }); throw new DiagramNotFoundError(docDetails.documentID); } diff --git a/packages/office/src/lib/client/clientApi/WordService.ts b/packages/office/src/lib/client/clientApi/WordService.ts index 9fdf061..90ba8db 100644 --- a/packages/office/src/lib/client/clientApi/WordService.ts +++ b/packages/office/src/lib/client/clientApi/WordService.ts @@ -6,6 +6,7 @@ import { ContentControlsNotFoundError, DiagramNotFoundError, RefreshError } from import type { Diagram } from './officeManager'; import { authStore } from '../stores/auth'; import { OfficeService } from './OfficeService'; +import { sendBehaviorEvent } from '../util/sendEvents'; export class WordService extends OfficeService { authToken = authStore.accessKey(); @@ -56,6 +57,11 @@ export class WordService extends OfficeService { public async syncDiagrams() { const controlTagsToUpdate = await this.getContentControlTagsToUpdate().catch((error) => { if(error instanceof ContentControlsNotFoundError) { + sendBehaviorEvent( + 'No diagrams found in document to sync', { + area: 'sync-diagrams', + eventID: `SYNC_DIAGRAM_WORD` + }); showUserMessage( 'No diagrams found in document', 'info' diff --git a/packages/office/src/lib/client/clientApi/officeManager.ts b/packages/office/src/lib/client/clientApi/officeManager.ts index 3045fab..795362c 100644 --- a/packages/office/src/lib/client/clientApi/officeManager.ts +++ b/packages/office/src/lib/client/clientApi/officeManager.ts @@ -7,6 +7,7 @@ import { PowerPointService } from './PowerPointService'; import { WordService } from './WordService'; import { InvalidTokenError } from '$lib/errors'; import { ExcelService } from './ExcelService'; +import { sendBehaviorEvent } from '../util/sendEvents'; export interface Diagram { base64Image: string; @@ -19,9 +20,11 @@ export interface Diagram { export class OfficeManager { officeService: OfficeService; mermaidChartApi: MermaidChart; + host: Office.HostType; constructor(host: Office.HostType, api: MermaidChart) { this.mermaidChartApi = api; + this.host = host; switch(host) { case Office.HostType.Word: { this.officeService = new WordService(this.mermaidChartApi); @@ -65,13 +68,28 @@ export class OfficeManager { }; await this.officeService.insertDiagram(diagram); + sendBehaviorEvent( + 'Insert PNG of diagram', { + area: 'insert-diagram', + eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}` + }); } catch (error) { if(error instanceof InvalidTokenError) { + sendBehaviorEvent( + 'Auth token invalid or not found', { + area: 'insert-diagram', + eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}` + }); showUserMessage( 'Auth token invalid or not found, please make sure that you are authenticated, or contact support', 'error' ); } else { + sendBehaviorEvent( + 'Error generating PNG', { + area: 'insert-diagram', + eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}` + }); showUserMessage( 'Error generating image, or image not found. Please contact support', 'error' @@ -86,7 +104,17 @@ export class OfficeManager { try { loading.setState(true, 'Syncing diagrams in document...'); await this.officeService.syncDiagrams(); + sendBehaviorEvent( + 'Sync diagrams with mermaid chart', { + area: 'sync-diagrams', + eventID: `SYNC_DIAGRAM_${this.host.toString().toUpperCase()}` + }); } catch { + sendBehaviorEvent( + 'Sync diagrams failed', { + area: 'insert-diagram', + eventID: `SYNC_DIAGRAM_${this.host.toString().toUpperCase()}` + }); showUserMessage( 'Error refreshing diagrams. Please contact support', 'error' diff --git a/packages/office/src/lib/client/components/DocumentCard.svelte b/packages/office/src/lib/client/components/DocumentCard.svelte index 8d15c89..7c897be 100644 --- a/packages/office/src/lib/client/components/DocumentCard.svelte +++ b/packages/office/src/lib/client/components/DocumentCard.svelte @@ -1,12 +1,10 @@