Skip to content

Commit 581f159

Browse files
committedMar 8, 2024
Add conditionals for using mixpanel and cookiebot - turn off in prod
1 parent 546b4cf commit 581f159

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed
 

‎packages/office/src/lib/client/featureSet.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ export enum FeatureName {
2323
const features: Record<FeatureName, FeatureState> = {
2424
editor: FeatureState.UnderDevelopment,
2525
dashboard: FeatureState.UnderDevelopment,
26-
userBehavior: FeatureState.StageAndProd,
27-
cookieBot: FeatureState.OnlyInProd
26+
userBehavior: FeatureState.NotInProd,
27+
cookieBot: FeatureState.NotInProd
2828
};
2929

3030
/**

‎packages/office/src/lib/client/util/sendEvents.ts

+12-9
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { analyticsEnabled } from '../stores/analytics';
55
import { minutesToMilliSeconds } from '$lib/utils';
66
import type { MCUser } from '$lib/mermaidChartApi';
77
import log from '$lib/log';
8+
import { FeatureName, shouldUseFeature } from '../featureSet';
89

910
let initialized = false;
1011

@@ -75,16 +76,18 @@ const delaysPerEvent: Record<string, number> = {
7576
const timeouts: Record<string, number> = {};
7677

7778
export function sendBehaviorEvent(description: string, event: BehaviorEvent) {
78-
if (timeouts[event.eventID]) {
79-
clearTimeout(timeouts[event.eventID]);
80-
}
81-
if (delaysPerEvent[event.eventID] === undefined) {
82-
sendEvent(description, event);
83-
} else {
84-
timeouts[event.eventID] = window.setTimeout(() => {
79+
if(shouldUseFeature(FeatureName.UserBehavior)) {
80+
if (timeouts[event.eventID]) {
81+
clearTimeout(timeouts[event.eventID]);
82+
}
83+
if (delaysPerEvent[event.eventID] === undefined) {
8584
sendEvent(description, event);
86-
delete timeouts[event.eventID];
87-
}, delaysPerEvent[event.eventID]);
85+
} else {
86+
timeouts[event.eventID] = window.setTimeout(() => {
87+
sendEvent(description, event);
88+
delete timeouts[event.eventID];
89+
}, delaysPerEvent[event.eventID]);
90+
}
8891
}
8992
}
9093

‎packages/office/src/routes/+layout.svelte

+13-11
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,20 @@
1515
let syncDiagramsInDocument: () => Promise<void>;
1616
1717
onMount(() => {
18-
initializeMixPanel(
19-
publicEnv.PUBLIC_MIXPANEL_TOKEN,
20-
$sessionStore.id,
21-
$sessionStore);
18+
if(shouldUseFeature(FeatureName.UserBehavior)) {
19+
initializeMixPanel(
20+
publicEnv.PUBLIC_MIXPANEL_TOKEN,
21+
$sessionStore.id,
22+
$sessionStore);
2223
23-
window.addEventListener(
24-
'CookiebotOnConsentReady',
25-
() => {
26-
updateConsent(window.Cookiebot?.consent);
27-
},
28-
false
29-
);
24+
window.addEventListener(
25+
'CookiebotOnConsentReady',
26+
() => {
27+
updateConsent(window.Cookiebot?.consent);
28+
},
29+
false
30+
);
31+
}
3032
});
3133
</script>
3234

0 commit comments

Comments
 (0)
Failed to load comments.