separate opt-in for non-anonomous telemetry

This commit is contained in:
Kiril Videlov 2024-04-29 15:12:22 +02:00
parent 732a196505
commit 4414d29bbf
No known key found for this signature in database
3 changed files with 53 additions and 3 deletions

View File

@ -1,7 +1,12 @@
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';
import {
appMetricsEnabled,
appErrorReportingEnabled,
appNonAnonMetricsEnabled
} from '$lib/config/appSettings';
import posthog from 'posthog-js';
export function initAnalyticsIfEnabled() {
const analyticsConfirmed = appAnalyticsConfirmed();
@ -17,6 +22,13 @@ export function initAnalyticsIfEnabled() {
.then((enabled) => {
if (enabled) initPostHog();
});
appNonAnonMetricsEnabled()
.onDisk()
.then((enabled) => {
enabled
? posthog.capture('nonAnonMetricsEnabled')
: posthog.capture('nonAnonMetricsDisabled');
});
}
});
}

View File

@ -2,10 +2,15 @@
import Link from './Link.svelte';
import SectionCard from './SectionCard.svelte';
import Toggle from './Toggle.svelte';
import { appErrorReportingEnabled, appMetricsEnabled } from '$lib/config/appSettings';
import {
appErrorReportingEnabled,
appMetricsEnabled,
appNonAnonMetricsEnabled
} from '$lib/config/appSettings';
const errorReportingEnabled = appErrorReportingEnabled();
const metricsEnabled = appMetricsEnabled();
const nonAnonMetricsEnabled = appNonAnonMetricsEnabled();
function toggleErrorReporting() {
$errorReportingEnabled = !$errorReportingEnabled;
@ -14,13 +19,23 @@
function toggleMetrics() {
$metricsEnabled = !$metricsEnabled;
}
function toggleNonAnonMetrics() {
$nonAnonMetricsEnabled = !$nonAnonMetricsEnabled;
}
</script>
<section class="analytics-settings">
<div class="analytics-settings__content">
<p class="text-base-body-13 analytics-settings__text">
GitButler uses telemetry strictly to help us improve the client. We do not collect any
personal information.
personal information (<Link
target="_blank"
rel="noreferrer"
href="https://gitbutler.com/privacy"
>
privacy policy
</Link>).
</p>
<p class="text-base-body-13 analytics-settings__text">
We kindly ask you to consider keeping these settings enabled as it helps us catch issues more
@ -56,6 +71,20 @@
<Toggle id="metricsEnabledToggle" checked={$metricsEnabled} on:change={toggleMetrics} />
</svelte:fragment>
</SectionCard>
<SectionCard labelFor="metricsEnabledToggle" on:click={toggleMetrics} orientation="row">
<svelte:fragment slot="title">Non-anonymous usage metrics</svelte:fragment>
<svelte:fragment slot="caption"
>Toggle sharing of identifiable usage statistics.</svelte:fragment
>
<svelte:fragment slot="actions">
<Toggle
id="nonAnonMetricsEnabledToggle"
checked={$nonAnonMetricsEnabled}
on:change={toggleNonAnonMetrics}
/>
</svelte:fragment>
</SectionCard>
</div>
</section>

View File

@ -35,6 +35,15 @@ export function appErrorReportingEnabled() {
return persisted(true, 'appErrorReportingEnabled');
}
/**
* Provides a writable store for obtaining or setting the current state of non-anonemous application metrics.
* The setting can be enabled or disabled by setting the value of the store to true or false.
* @returns A writable store with the appNonAnonMetricsEnabled config.
*/
export function appNonAnonMetricsEnabled() {
return persisted(false, 'appNonAnonMetricsEnabled');
}
function persisted<T>(initial: T, key: string): Writable<T> & { onDisk: () => Promise<T> } {
async function setAndPersist(value: T, set: (value: T) => void) {
await store.set(key, value);