Files
element-x-android/plugins/src/main/kotlin/ModulesConfig.kt
T
joel.poyet 345a6bb8ec feat(analytics): disable analytics unless credentials are configured
Removes the onboarding opt-in screen, the Analytics settings entry and
the unused Posthog and Sentry SDKs.
2026-10-19 08:47:33 +02:00

42 lines
1.8 KiB
Kotlin

/*
* Copyright (c) 2025 Element Creations Ltd.
* Copyright 2024, 2025 New Vector Ltd.
*
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial.
* Please see LICENSE files in the repository root for full details.
*/
import config.AnalyticsConfig
import config.BuildTimeConfig
import config.PushProvidersConfig
object ModulesConfig {
val pushProvidersConfig = PushProvidersConfig(
includeFirebase = BuildTimeConfig.PUSH_CONFIG_INCLUDE_FIREBASE,
includeUnifiedPush = BuildTimeConfig.PUSH_CONFIG_INCLUDE_UNIFIED_PUSH,
)
// Analytics is enabled only when credentials are actually configured in BuildTimeConfig.
// Upstream applies this rule to enterprise builds only and hardcodes both providers on for
// FOSS builds; HealthChat ships no Posthog or Sentry credentials, so that hardcoding meant
// shipping both SDKs, prompting every new user with the analytics opt-in screen during the
// FTUE, and showing an Analytics settings entry — all while collecting nothing.
val analyticsConfig: AnalyticsConfig = run {
// Is Posthog configuration available?
val withPosthog = BuildTimeConfig.SERVICES_POSTHOG_APIKEY.isNullOrEmpty().not() &&
BuildTimeConfig.SERVICES_POSTHOG_HOST.isNullOrEmpty().not()
// Is Sentry configuration available?
val withSentry = BuildTimeConfig.SERVICES_SENTRY_DSN.isNullOrEmpty().not()
if (withPosthog || withSentry) {
println("Analytics enabled with Posthog: $withPosthog, Sentry: $withSentry")
AnalyticsConfig.Enabled(
withPosthog = withPosthog,
withSentry = withSentry,
)
} else {
println("Analytics disabled")
AnalyticsConfig.Disabled
}
}
}