Analytics: add config to build.gradle

This commit is contained in:
Benoit Marty 2021-11-23 15:26:17 +01:00
parent 5606a5bfe7
commit 8608230fa0
5 changed files with 60 additions and 1 deletions

View file

@ -24,6 +24,7 @@
<w>pbkdf</w>
<w>pids</w>
<w>pkcs</w>
<w>posthog</w>
<w>previewable</w>
<w>previewables</w>
<w>pstn</w>

View file

@ -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

View file

@ -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
}
}
}

View file

@ -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

View file

@ -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" />
</androidx.constraintlayout.widget.ConstraintLayout>