Skip to content

Commit

Permalink
Fix analytics enabling and disabling
Browse files Browse the repository at this point in the history
  • Loading branch information
ttmx committed Oct 5, 2024
1 parent 26ab3b4 commit 3c2e5ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
9 changes: 9 additions & 0 deletions src/lib/analytics.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import posthog from 'posthog-js';
import { appSettings } from './settings';

const POSTHOG_URL = 'https://posthog.tteles.dev';
const POSTHOG_API_KEY = 'phc_TzcytD0DrmirOxFVVSYR8azP3jpsNiWXcSLZ5qd8kFj';
Expand All @@ -9,6 +10,14 @@ export function initAnalytics() {
api_host: POSTHOG_URL,
person_profiles: 'identified_only', // or 'always' to create profiles for anonymous users as well
});
appSettings.subscribe(settings => {
if (settings.analytics) {
console.debug('opting in to analytics');
optInAnalytics();
} else {
optOutAnalytics();
}
});
}

export function captureEvent(event: string, properties?: Record<string, any>) {
Expand Down
5 changes: 3 additions & 2 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@
onMount(() => {
loadUserCreds();
loadSettings();
initAnalytics();
loadSettings().then(() => {
initAnalytics();
});
App.addListener('resume', () => {
if ($token != null && $token.refreshToken != null) {
console.debug('Refreshing token because app was reopened');
Expand Down

0 comments on commit 3c2e5ea

Please sign in to comment.