Skip to content

Commit

Permalink
Fix posthog pageview capturing
Browse files Browse the repository at this point in the history
- should have rtfm
  • Loading branch information
mtsgrd committed Nov 29, 2024
1 parent 39e16cf commit 5aab7ec
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apps/desktop/src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,14 @@
} from '@gitbutler/shared/sharedRoutes';
import { LineManagerFactory } from '@gitbutler/ui/commitLines/lineManager';
import { LineManagerFactory as StackingLineManagerFactory } from '@gitbutler/ui/commitLines/lineManager';
import posthog from 'posthog-js';
import { onMount, setContext, type Snippet } from 'svelte';
import { Toaster } from 'svelte-french-toast';
import type { LayoutData } from './$types';
import { dev } from '$app/environment';
import { browser } from '$app/environment';
import { goto } from '$app/navigation';
import { beforeNavigate, afterNavigate } from '$app/navigation';
import { env } from '$env/dynamic/public';
const { data, children }: { data: LayoutData; children: Snippet } = $props();
Expand Down Expand Up @@ -87,6 +90,12 @@
const accessToken = $derived($user?.github_access_token);
const octokit = $derived(accessToken ? octokitFromAccessToken(accessToken) : undefined);
// Special initialization to capture pageviews for single page apps.
if (browser) {
beforeNavigate(() => posthog.capture('$pageleave'));
afterNavigate(() => posthog.capture('$pageview'));
}
// This store is literally only used once, on GitHub oauth, to set the
// gh username on the user object. Furthermore, it isn't used anywhere.
// TODO: Remove the gh username completely?
Expand Down

0 comments on commit 5aab7ec

Please sign in to comment.