fix: dont initialize posthog / sentry analytics before onboarding complete

This commit is contained in:
Kiril Videlov 2024-04-29 14:25:45 +02:00
parent d6a882b1ba
commit 732a196505
No known key found for this signature in database
4 changed files with 26 additions and 25 deletions

View File

@ -0,0 +1,22 @@
import { initPostHog } from '$lib/analytics/posthog';
import { initSentry } from '$lib/analytics/sentry';
import { appAnalyticsConfirmed } from '$lib/config/appSettings';
import { appMetricsEnabled, appErrorReportingEnabled } from '$lib/config/appSettings';
export function initAnalyticsIfEnabled() {
const analyticsConfirmed = appAnalyticsConfirmed();
analyticsConfirmed.onDisk().then((confirmed) => {
if (confirmed) {
appErrorReportingEnabled()
.onDisk()
.then((enabled) => {
if (enabled) initSentry();
});
appMetricsEnabled()
.onDisk()
.then((enabled) => {
if (enabled) initPostHog();
});
}
});
}

View File

@ -1,6 +1,7 @@
<script lang="ts">
import AnalyticsSettings from './AnalyticsSettings.svelte';
import Button from './Button.svelte';
import { initAnalyticsIfEnabled } from '$lib/analytics/analytics';
import type { Writable } from 'svelte/store';
export let analyticsConfirmed: Writable<boolean>;
@ -17,6 +18,7 @@
icon="chevron-right-small"
on:click={() => {
$analyticsConfirmed = true;
initAnalyticsIfEnabled();
}}
>
Continue

View File

@ -1,5 +1,4 @@
<script lang="ts">
import InfoMessage from './InfoMessage.svelte';
import Link from './Link.svelte';
import SectionCard from './SectionCard.svelte';
import Toggle from './Toggle.svelte';
@ -7,16 +6,13 @@
const errorReportingEnabled = appErrorReportingEnabled();
const metricsEnabled = appMetricsEnabled();
let updatedTelemetrySettings = false;
function toggleErrorReporting() {
$errorReportingEnabled = !$errorReportingEnabled;
updatedTelemetrySettings = true;
}
function toggleMetrics() {
$metricsEnabled = !$metricsEnabled;
updatedTelemetrySettings = true;
}
</script>
@ -60,14 +56,6 @@
<Toggle id="metricsEnabledToggle" checked={$metricsEnabled} on:change={toggleMetrics} />
</svelte:fragment>
</SectionCard>
{#if updatedTelemetrySettings}
<InfoMessage>
<svelte:fragment slot="content"
>Changes will take effect on the next application start.</svelte:fragment
>
</InfoMessage>
{/if}
</div>
</section>

View File

@ -1,13 +1,11 @@
import { AIService } from '$lib/ai/service';
import { initPostHog } from '$lib/analytics/posthog';
import { initSentry } from '$lib/analytics/sentry';
import { initAnalyticsIfEnabled } from '$lib/analytics/analytics';
import { AuthService } from '$lib/backend/auth';
import { GitConfigService } from '$lib/backend/gitConfigService';
import { HttpClient } from '$lib/backend/httpClient';
import { ProjectService } from '$lib/backend/projects';
import { PromptService } from '$lib/backend/prompt';
import { UpdaterService } from '$lib/backend/updater';
import { appMetricsEnabled, appErrorReportingEnabled } from '$lib/config/appSettings';
import { GitHubService } from '$lib/github/service';
import { UserService } from '$lib/stores/user';
import lscache from 'lscache';
@ -24,16 +22,7 @@ export const prerender = false;
export const csr = true;
export async function load() {
appErrorReportingEnabled()
.onDisk()
.then((enabled) => {
if (enabled) initSentry();
});
appMetricsEnabled()
.onDisk()
.then((enabled) => {
if (enabled) initPostHog();
});
initAnalyticsIfEnabled();
// TODO: Find a workaround to avoid this dynamic import
// https://github.com/sveltejs/kit/issues/905