mirror of
https://github.com/element-hq/element-android
synced 2024-11-24 10:25:35 +03:00
Analytics: iterate on the config - and disable by default on forks
This commit is contained in:
parent
74e573ecdc
commit
c1438f0a65
7 changed files with 70 additions and 51 deletions
|
@ -233,11 +233,6 @@ 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-poc.lab.element.dev\""
|
||||
buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"rs-pJjsYJTuAkXJfhaMmPUNBhWliDyTKLOOxike6ck8\""
|
||||
buildConfigField "String", "ANALYTICS_POLICY_URL", "\"https://element.io/cookie-policy\""
|
||||
|
||||
signingConfig signingConfigs.debug
|
||||
}
|
||||
|
||||
|
@ -248,11 +243,6 @@ 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.hss.element.io\""
|
||||
buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO\""
|
||||
buildConfigField "String", "ANALYTICS_POLICY_URL", "\"https://element.io/cookie-policy\""
|
||||
|
||||
postprocessing {
|
||||
removeUnusedCode true
|
||||
removeUnusedResources true
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.config
|
||||
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.features.analytics.AnalyticsConfig
|
||||
|
||||
val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
|
||||
override val isEnabled = BuildConfig.APPLICATION_ID == "im.vector.app.debug"
|
||||
override val postHogHost = "https://posthog-poc.lab.element.dev"
|
||||
override val postHogApiKey = "rs-pJjsYJTuAkXJfhaMmPUNBhWliDyTKLOOxike6ck8"
|
||||
override val policyLink = "https://element.io/cookie-policy"
|
||||
}
|
|
@ -16,36 +16,9 @@
|
|||
|
||||
package im.vector.app.features.analytics
|
||||
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.features.analytics.log.analyticsTag
|
||||
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.tag(analyticsTag.value).w("Analytics is disabled, ANALYTICS_POSTHOG_HOST is empty")
|
||||
}
|
||||
val postHogApiKey = BuildConfig.ANALYTICS_POSTHOG_API_KEY.takeIf { it.isNotEmpty() }
|
||||
?: return null.also {
|
||||
Timber.tag(analyticsTag.value).w("Analytics is disabled, ANALYTICS_POSTHOG_API_KEY is empty")
|
||||
}
|
||||
|
||||
return AnalyticsConfig(
|
||||
postHogHost = postHogHost,
|
||||
postHogApiKey = postHogApiKey
|
||||
)
|
||||
}
|
||||
|
||||
fun isAnalyticsEnabled(): Boolean {
|
||||
return getConfig() != null
|
||||
}
|
||||
}
|
||||
interface AnalyticsConfig {
|
||||
val isEnabled: Boolean
|
||||
val postHogHost: String
|
||||
val postHogApiKey: String
|
||||
val policyLink: String
|
||||
}
|
||||
|
|
|
@ -20,11 +20,11 @@ import android.content.Context
|
|||
import com.posthog.android.PostHog
|
||||
import com.posthog.android.Properties
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.features.analytics.AnalyticsConfig
|
||||
import im.vector.app.config.analyticsConfig
|
||||
import im.vector.app.features.analytics.VectorAnalytics
|
||||
import im.vector.app.features.analytics.log.analyticsTag
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent
|
||||
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen
|
||||
import im.vector.app.features.analytics.log.analyticsTag
|
||||
import im.vector.app.features.analytics.store.AnalyticsStore
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
@ -123,10 +123,12 @@ class DefaultVectorAnalytics @Inject constructor(
|
|||
private fun createAnalyticsClient() {
|
||||
Timber.tag(analyticsTag.value).d("createAnalyticsClient()")
|
||||
|
||||
val config: AnalyticsConfig = AnalyticsConfig.getConfig()
|
||||
?: return Unit.also { Timber.tag(analyticsTag.value).w("Analytics is disabled") }
|
||||
if (analyticsConfig.isEnabled.not()) {
|
||||
Timber.tag(analyticsTag.value).w("Analytics is disabled")
|
||||
return
|
||||
}
|
||||
|
||||
posthog = PostHog.Builder(context, config.postHogApiKey, config.postHogHost)
|
||||
posthog = PostHog.Builder(context, analyticsConfig.postHogApiKey, analyticsConfig.postHogHost)
|
||||
// Record certain application events automatically! (off/false by default)
|
||||
// .captureApplicationLifecycleEvents()
|
||||
// Record screen views automatically! (off/false by default)
|
||||
|
|
|
@ -21,8 +21,8 @@ import android.view.LayoutInflater
|
|||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.airbnb.mvrx.activityViewModel
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.R
|
||||
import im.vector.app.config.analyticsConfig
|
||||
import im.vector.app.core.extensions.setTextWithColoredPart
|
||||
import im.vector.app.core.platform.VectorBaseFragment
|
||||
import im.vector.app.core.utils.openUrlInChromeCustomTab
|
||||
|
@ -60,7 +60,7 @@ class AnalyticsOptInFragment @Inject constructor(
|
|||
fullTextRes = R.string.analytics_opt_in_content,
|
||||
coloredTextRes = R.string.analytics_opt_in_content_link,
|
||||
onClick = {
|
||||
openUrlInChromeCustomTab(requireContext(), null, BuildConfig.ANALYTICS_POLICY_URL)
|
||||
openUrlInChromeCustomTab(requireContext(), null, analyticsConfig.policyLink)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
@ -35,6 +35,7 @@ import androidx.recyclerview.widget.RecyclerView
|
|||
import com.airbnb.mvrx.fragmentViewModel
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import im.vector.app.R
|
||||
import im.vector.app.config.analyticsConfig
|
||||
import im.vector.app.core.di.ActiveSessionHolder
|
||||
import im.vector.app.core.dialogs.ExportKeysDialog
|
||||
import im.vector.app.core.extensions.queryExportKeys
|
||||
|
@ -50,7 +51,6 @@ import im.vector.app.core.utils.copyToClipboard
|
|||
import im.vector.app.core.utils.openFileSelection
|
||||
import im.vector.app.core.utils.toast
|
||||
import im.vector.app.databinding.DialogImportE2eKeysBinding
|
||||
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
|
||||
|
@ -294,7 +294,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
|
|||
}
|
||||
|
||||
private fun setUpAnalytics() {
|
||||
analyticsCategory.isVisible = AnalyticsConfig.isAnalyticsEnabled()
|
||||
analyticsCategory.isVisible = analyticsConfig.isEnabled
|
||||
|
||||
analyticsConsent.setOnPreferenceClickListener {
|
||||
analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent(analyticsConsent.isChecked))
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
/*
|
||||
* 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.config
|
||||
|
||||
import im.vector.app.BuildConfig
|
||||
import im.vector.app.features.analytics.AnalyticsConfig
|
||||
|
||||
val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
|
||||
override val isEnabled = BuildConfig.APPLICATION_ID == "im.vector.app"
|
||||
override val postHogHost = "https://posthog.hss.element.io"
|
||||
override val postHogApiKey = "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO"
|
||||
override val policyLink = "https://element.io/cookie-policy"
|
||||
}
|
Loading…
Reference in a new issue