Skip to content

Commit

Permalink
Add conditionals for using mixpanel and cookiebot - turn off in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
jgreywolf committed Mar 8, 2024
1 parent 546b4cf commit 581f159
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 22 deletions.
4 changes: 2 additions & 2 deletions packages/office/src/lib/client/featureSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export enum FeatureName {
const features: Record<FeatureName, FeatureState> = {
editor: FeatureState.UnderDevelopment,
dashboard: FeatureState.UnderDevelopment,
userBehavior: FeatureState.StageAndProd,
cookieBot: FeatureState.OnlyInProd
userBehavior: FeatureState.NotInProd,
cookieBot: FeatureState.NotInProd
};

/**
Expand Down
21 changes: 12 additions & 9 deletions packages/office/src/lib/client/util/sendEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { analyticsEnabled } from '../stores/analytics';
import { minutesToMilliSeconds } from '$lib/utils';
import type { MCUser } from '$lib/mermaidChartApi';
import log from '$lib/log';
import { FeatureName, shouldUseFeature } from '../featureSet';

let initialized = false;

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

export function sendBehaviorEvent(description: string, event: BehaviorEvent) {
if (timeouts[event.eventID]) {
clearTimeout(timeouts[event.eventID]);
}
if (delaysPerEvent[event.eventID] === undefined) {
sendEvent(description, event);
} else {
timeouts[event.eventID] = window.setTimeout(() => {
if(shouldUseFeature(FeatureName.UserBehavior)) {
if (timeouts[event.eventID]) {
clearTimeout(timeouts[event.eventID]);
}
if (delaysPerEvent[event.eventID] === undefined) {
sendEvent(description, event);
delete timeouts[event.eventID];
}, delaysPerEvent[event.eventID]);
} else {
timeouts[event.eventID] = window.setTimeout(() => {
sendEvent(description, event);
delete timeouts[event.eventID];
}, delaysPerEvent[event.eventID]);
}
}
}

Expand Down
24 changes: 13 additions & 11 deletions packages/office/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,20 @@
let syncDiagramsInDocument: () => Promise<void>;
onMount(() => {
initializeMixPanel(
publicEnv.PUBLIC_MIXPANEL_TOKEN,
$sessionStore.id,
$sessionStore);
if(shouldUseFeature(FeatureName.UserBehavior)) {
initializeMixPanel(
publicEnv.PUBLIC_MIXPANEL_TOKEN,
$sessionStore.id,
$sessionStore);
window.addEventListener(
'CookiebotOnConsentReady',
() => {
updateConsent(window.Cookiebot?.consent);
},
false
);
window.addEventListener(
'CookiebotOnConsentReady',
() => {
updateConsent(window.Cookiebot?.consent);
},
false
);
}
});
</script>

Expand Down

0 comments on commit 581f159

Please sign in to comment.