Skip to content

Commit 8d3f394

Browse files
committedFeb 19, 2024
Add send behavior events for mixpanel
1 parent 6dbf7c6 commit 8d3f394

File tree

4 files changed

+42
-4
lines changed

4 files changed

+42
-4
lines changed
 

‎packages/office/src/lib/client/clientApi/PowerPointService.ts

+6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { showUserMessage } from '../stores/messaging';
55
import type { Diagram } from './officeManager';
66
import { authStore } from '../stores/auth';
77
import { OfficeService } from './OfficeService';
8+
import { sendBehaviorEvent } from '../util/sendEvents';
89
export class PowerPointService extends OfficeService {
910
authToken = authStore.accessKey();
1011

@@ -73,6 +74,11 @@ export class PowerPointService extends OfficeService {
7374
const docDetails = splitReferenceToken(tag);
7475
const document = await this.mermaidChartApi.getDocument(docDetails.documentID);
7576
if(!document) {
77+
sendBehaviorEvent(
78+
'Could not find document in presentation', {
79+
area: 'sync-diagrams',
80+
eventID: `REPLACE_DIAGRAM_POWERPOINT`
81+
});
7682
throw new DiagramNotFoundError(docDetails.documentID);
7783
}
7884

‎packages/office/src/lib/client/clientApi/WordService.ts

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { ContentControlsNotFoundError, DiagramNotFoundError, RefreshError } from
66
import type { Diagram } from './officeManager';
77
import { authStore } from '../stores/auth';
88
import { OfficeService } from './OfficeService';
9+
import { sendBehaviorEvent } from '../util/sendEvents';
910

1011
export class WordService extends OfficeService {
1112
authToken = authStore.accessKey();
@@ -56,6 +57,11 @@ export class WordService extends OfficeService {
5657
public async syncDiagrams() {
5758
const controlTagsToUpdate = await this.getContentControlTagsToUpdate().catch((error) => {
5859
if(error instanceof ContentControlsNotFoundError) {
60+
sendBehaviorEvent(
61+
'No diagrams found in document to sync', {
62+
area: 'sync-diagrams',
63+
eventID: `SYNC_DIAGRAM_WORD`
64+
});
5965
showUserMessage(
6066
'No diagrams found in document',
6167
'info'

‎packages/office/src/lib/client/clientApi/officeManager.ts

+28
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { PowerPointService } from './PowerPointService';
77
import { WordService } from './WordService';
88
import { InvalidTokenError } from '$lib/errors';
99
import { ExcelService } from './ExcelService';
10+
import { sendBehaviorEvent } from '../util/sendEvents';
1011

1112
export interface Diagram {
1213
base64Image: string;
@@ -19,9 +20,11 @@ export interface Diagram {
1920
export class OfficeManager {
2021
officeService: OfficeService;
2122
mermaidChartApi: MermaidChart;
23+
host: Office.HostType;
2224

2325
constructor(host: Office.HostType, api: MermaidChart) {
2426
this.mermaidChartApi = api;
27+
this.host = host;
2528
switch(host) {
2629
case Office.HostType.Word: {
2730
this.officeService = new WordService(this.mermaidChartApi);
@@ -65,13 +68,28 @@ export class OfficeManager {
6568
};
6669

6770
await this.officeService.insertDiagram(diagram);
71+
sendBehaviorEvent(
72+
'Insert PNG of diagram', {
73+
area: 'insert-diagram',
74+
eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}`
75+
});
6876
} catch (error) {
6977
if(error instanceof InvalidTokenError) {
78+
sendBehaviorEvent(
79+
'Auth token invalid or not found', {
80+
area: 'insert-diagram',
81+
eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}`
82+
});
7083
showUserMessage(
7184
'Auth token invalid or not found, please make sure that you are authenticated, or contact support',
7285
'error'
7386
);
7487
} else {
88+
sendBehaviorEvent(
89+
'Error generating PNG', {
90+
area: 'insert-diagram',
91+
eventID: `DIAGRAM_INSERT_${this.host.toString().toUpperCase()}`
92+
});
7593
showUserMessage(
7694
'Error generating image, or image not found. Please contact support',
7795
'error'
@@ -86,7 +104,17 @@ export class OfficeManager {
86104
try {
87105
loading.setState(true, 'Syncing diagrams in document...');
88106
await this.officeService.syncDiagrams();
107+
sendBehaviorEvent(
108+
'Sync diagrams with mermaid chart', {
109+
area: 'sync-diagrams',
110+
eventID: `SYNC_DIAGRAM_${this.host.toString().toUpperCase()}`
111+
});
89112
} catch {
113+
sendBehaviorEvent(
114+
'Sync diagrams failed', {
115+
area: 'insert-diagram',
116+
eventID: `SYNC_DIAGRAM_${this.host.toString().toUpperCase()}`
117+
});
90118
showUserMessage(
91119
'Error refreshing diagrams. Please contact support',
92120
'error'

‎packages/office/src/lib/client/components/DocumentCard.svelte

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
<script lang="ts">
22
import type { OfficeManager } from '$lib/client/clientApi/officeManager';
3-
import { createEventDispatcher } from 'svelte';
43
import { documentStore } from '../stores/documents';
54
import { storePopup } from '@skeletonlabs/skeleton';
65
import { computePosition, autoUpdate, offset, shift, flip, arrow } from '@floating-ui/dom';
7-
import { C } from '$lib/constants';
8-
import { loading } from '../stores/loading';
9-
import RawView from './Editor/RawView.svelte';
6+
7+
import RawView from './Editor/RawView.svelte';
108
119
storePopup.set({ computePosition, autoUpdate, offset, shift, flip, arrow });
1210

0 commit comments

Comments
 (0)
Failed to load comments.