@@ -3,26 +3,30 @@ import { initSentry } from '$lib/analytics/sentry';
3
3
import { AppSettings } from '$lib/config/appSettings' ;
4
4
import posthog from 'posthog-js' ;
5
5
6
- export function initAnalyticsIfEnabled ( appSettings : AppSettings , postHog : PostHogWrapper ) {
6
+ export async function initAnalyticsIfEnabled (
7
+ appSettings : AppSettings ,
8
+ postHog : PostHogWrapper ,
9
+ confirmedOverride ?: boolean
10
+ ) {
7
11
if ( import . meta. env . MODE === 'development' ) return ;
8
12
9
- appSettings . appAnalyticsConfirmed . onDisk ( ) . then ( async ( confirmed ) => {
10
- if ( confirmed ) {
11
- appSettings . appErrorReportingEnabled . onDisk ( ) . then ( ( enabled ) => {
12
- if ( enabled ) initSentry ( ) ;
13
- } ) ;
14
- await appSettings . appMetricsEnabled . onDisk ( ) . then ( async ( enabled ) => {
15
- if ( enabled ) {
16
- await postHog . init ( ) ;
17
- }
18
- } ) ;
19
- appSettings . appNonAnonMetricsEnabled . onDisk ( ) . then ( ( enabled ) => {
20
- if ( enabled ) {
21
- posthog . capture ( 'nonAnonMetricsEnabled' ) ;
22
- } else {
23
- posthog . capture ( 'nonAnonMetricsDisabled' ) ;
24
- }
25
- } ) ;
26
- }
27
- } ) ;
13
+ const confirmed = confirmedOverride ?? ( await appSettings . appAnalyticsConfirmed . onDisk ( ) ) ;
14
+
15
+ if ( confirmed ) {
16
+ appSettings . appErrorReportingEnabled . onDisk ( ) . then ( ( enabled ) => {
17
+ if ( enabled ) initSentry ( ) ;
18
+ } ) ;
19
+ await appSettings . appMetricsEnabled . onDisk ( ) . then ( async ( enabled ) => {
20
+ if ( enabled ) {
21
+ await postHog . init ( ) ;
22
+ }
23
+ } ) ;
24
+ appSettings . appNonAnonMetricsEnabled . onDisk ( ) . then ( ( enabled ) => {
25
+ if ( enabled ) {
26
+ posthog . capture ( 'nonAnonMetricsEnabled' ) ;
27
+ } else {
28
+ posthog . capture ( 'nonAnonMetricsDisabled' ) ;
29
+ }
30
+ } ) ;
31
+ }
28
32
}
0 commit comments