diff --git a/.idea/dictionaries/bmarty.xml b/.idea/dictionaries/bmarty.xml index e143720aa9..a2e408b50d 100644 --- a/.idea/dictionaries/bmarty.xml +++ b/.idea/dictionaries/bmarty.xml @@ -24,6 +24,7 @@ pbkdf pids pkcs + posthog previewable previewables pstn diff --git a/vector/build.gradle b/vector/build.gradle index ff81c4d721..1b6e81848d 100644 --- a/vector/build.gradle +++ b/vector/build.gradle @@ -233,6 +233,10 @@ android { // Set to true if you want to enable strict mode in debug buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false" + // Analytics. Set to empty strings to just disable analytics + buildConfigField "String", "ANALYTICS_POSTHOG_HOST", "\"https://posthog.hss.element.io/\"" + buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"TODO\"" + signingConfig signingConfigs.debug } @@ -243,6 +247,10 @@ android { buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false" buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false" + // Analytics. Set to empty strings to just disable analytics + buildConfigField "String", "ANALYTICS_POSTHOG_HOST", "\"https://posthog-poc.lab.element.dev/\"" + buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"TODO\"" + postprocessing { removeUnusedCode true removeUnusedResources true diff --git a/vector/src/main/java/im/vector/app/features/analytics/AnalyticsConfig.kt b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsConfig.kt new file mode 100644 index 0000000000..9a8d2e627d --- /dev/null +++ b/vector/src/main/java/im/vector/app/features/analytics/AnalyticsConfig.kt @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2021 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.analytics + +import im.vector.app.BuildConfig +import timber.log.Timber + +data class AnalyticsConfig( + val postHogHost: String, + val postHogApiKey: String +) { + companion object { + /** + * Read the analytics config from the Build config + */ + fun getConfig(): AnalyticsConfig? { + val postHogHost = BuildConfig.ANALYTICS_POSTHOG_HOST.takeIf { it.isNotEmpty() } + ?: return null.also { Timber.w("Analytics is disabled, ANALYTICS_POSTHOG_HOST is empty") } + val postHogApiKey = BuildConfig.ANALYTICS_POSTHOG_API_KEY.takeIf { it.isNotEmpty() } + ?: return null.also { Timber.w("Analytics is disabled, ANALYTICS_POSTHOG_API_KEY is empty") } + + return AnalyticsConfig( + postHogHost = postHogHost, + postHogApiKey = postHogApiKey + ) + } + + fun isAnalyticsEnabled(): Boolean { + return getConfig() != null + } + } +} diff --git a/vector/src/main/java/im/vector/app/features/login/LoginSplashFragment.kt b/vector/src/main/java/im/vector/app/features/login/LoginSplashFragment.kt index d719ab6b31..e045ba11b1 100644 --- a/vector/src/main/java/im/vector/app/features/login/LoginSplashFragment.kt +++ b/vector/src/main/java/im/vector/app/features/login/LoginSplashFragment.kt @@ -27,6 +27,7 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder import im.vector.app.BuildConfig import im.vector.app.R import im.vector.app.databinding.FragmentLoginSplashBinding +import im.vector.app.features.analytics.AnalyticsConfig import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewActions import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewModel import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewState @@ -64,6 +65,7 @@ class LoginSplashFragment @Inject constructor( private fun setupViews() { views.loginSplashSubmit.debouncedClicks { getStarted() } // setOnCheckedChangeListener is to annoying since it does not distinguish user changes and code changes + views.loginSplashAnalyticsConsent.isVisible = AnalyticsConfig.isAnalyticsEnabled() views.loginSplashAnalyticsConsent.setOnClickListener { analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent( views.loginSplashAnalyticsConsent.isChecked diff --git a/vector/src/main/res/layout/fragment_login_splash.xml b/vector/src/main/res/layout/fragment_login_splash.xml index 90a33594c3..89a684be01 100644 --- a/vector/src/main/res/layout/fragment_login_splash.xml +++ b/vector/src/main/res/layout/fragment_login_splash.xml @@ -214,8 +214,10 @@ android:layout_width="0dp" android:layout_height="wrap_content" android:text="@string/analytics_consent_splash" + android:visibility="gone" app:layout_constraintBottom_toBottomOf="parent" app:layout_constraintEnd_toEndOf="parent" - app:layout_constraintStart_toStartOf="parent" /> + app:layout_constraintStart_toStartOf="parent" + tools:visibility="visible" />