Skip to content

Commit c1438f0

Browse files
committed
Analytics: iterate on the config - and disable by default on forks
1 parent 74e573e commit c1438f0

File tree

7 files changed

+70
-51
lines changed

7 files changed

+70
-51
lines changed

vector/build.gradle

-10
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,6 @@ android {
233233
// Set to true if you want to enable strict mode in debug
234234
buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false"
235235

236-
// Analytics. Set to empty strings to just disable analytics
237-
buildConfigField "String", "ANALYTICS_POSTHOG_HOST", "\"https://posthog-poc.lab.element.dev\""
238-
buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"rs-pJjsYJTuAkXJfhaMmPUNBhWliDyTKLOOxike6ck8\""
239-
buildConfigField "String", "ANALYTICS_POLICY_URL", "\"https://element.io/cookie-policy\""
240-
241236
signingConfig signingConfigs.debug
242237
}
243238

@@ -248,11 +243,6 @@ android {
248243
buildConfigField "boolean", "LOW_PRIVACY_LOG_ENABLE", "false"
249244
buildConfigField "boolean", "ENABLE_STRICT_MODE_LOGS", "false"
250245

251-
// Analytics. Set to empty strings to just disable analytics
252-
buildConfigField "String", "ANALYTICS_POSTHOG_HOST", "\"https://posthog.hss.element.io\""
253-
buildConfigField "String", "ANALYTICS_POSTHOG_API_KEY", "\"phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO\""
254-
buildConfigField "String", "ANALYTICS_POLICY_URL", "\"https://element.io/cookie-policy\""
255-
256246
postprocessing {
257247
removeUnusedCode true
258248
removeUnusedResources true
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2021 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.config
18+
19+
import im.vector.app.BuildConfig
20+
import im.vector.app.features.analytics.AnalyticsConfig
21+
22+
val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
23+
override val isEnabled = BuildConfig.APPLICATION_ID == "im.vector.app.debug"
24+
override val postHogHost = "https://posthog-poc.lab.element.dev"
25+
override val postHogApiKey = "rs-pJjsYJTuAkXJfhaMmPUNBhWliDyTKLOOxike6ck8"
26+
override val policyLink = "https://element.io/cookie-policy"
27+
}

vector/src/main/java/im/vector/app/features/analytics/AnalyticsConfig.kt

+5-32
Original file line numberDiff line numberDiff line change
@@ -16,36 +16,9 @@
1616

1717
package im.vector.app.features.analytics
1818

19-
import im.vector.app.BuildConfig
20-
import im.vector.app.features.analytics.log.analyticsTag
21-
import timber.log.Timber
22-
23-
data class AnalyticsConfig(
24-
val postHogHost: String,
25-
val postHogApiKey: String
26-
) {
27-
companion object {
28-
/**
29-
* Read the analytics config from the Build config
30-
*/
31-
fun getConfig(): AnalyticsConfig? {
32-
val postHogHost = BuildConfig.ANALYTICS_POSTHOG_HOST.takeIf { it.isNotEmpty() }
33-
?: return null.also {
34-
Timber.tag(analyticsTag.value).w("Analytics is disabled, ANALYTICS_POSTHOG_HOST is empty")
35-
}
36-
val postHogApiKey = BuildConfig.ANALYTICS_POSTHOG_API_KEY.takeIf { it.isNotEmpty() }
37-
?: return null.also {
38-
Timber.tag(analyticsTag.value).w("Analytics is disabled, ANALYTICS_POSTHOG_API_KEY is empty")
39-
}
40-
41-
return AnalyticsConfig(
42-
postHogHost = postHogHost,
43-
postHogApiKey = postHogApiKey
44-
)
45-
}
46-
47-
fun isAnalyticsEnabled(): Boolean {
48-
return getConfig() != null
49-
}
50-
}
19+
interface AnalyticsConfig {
20+
val isEnabled: Boolean
21+
val postHogHost: String
22+
val postHogApiKey: String
23+
val policyLink: String
5124
}

vector/src/main/java/im/vector/app/features/analytics/impl/DefaultVectorAnalytics.kt

+7-5
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ import android.content.Context
2020
import com.posthog.android.PostHog
2121
import com.posthog.android.Properties
2222
import im.vector.app.BuildConfig
23-
import im.vector.app.features.analytics.AnalyticsConfig
23+
import im.vector.app.config.analyticsConfig
2424
import im.vector.app.features.analytics.VectorAnalytics
25-
import im.vector.app.features.analytics.log.analyticsTag
2625
import im.vector.app.features.analytics.itf.VectorAnalyticsEvent
2726
import im.vector.app.features.analytics.itf.VectorAnalyticsScreen
27+
import im.vector.app.features.analytics.log.analyticsTag
2828
import im.vector.app.features.analytics.store.AnalyticsStore
2929
import kotlinx.coroutines.GlobalScope
3030
import kotlinx.coroutines.flow.Flow
@@ -123,10 +123,12 @@ class DefaultVectorAnalytics @Inject constructor(
123123
private fun createAnalyticsClient() {
124124
Timber.tag(analyticsTag.value).d("createAnalyticsClient()")
125125

126-
val config: AnalyticsConfig = AnalyticsConfig.getConfig()
127-
?: return Unit.also { Timber.tag(analyticsTag.value).w("Analytics is disabled") }
126+
if (analyticsConfig.isEnabled.not()) {
127+
Timber.tag(analyticsTag.value).w("Analytics is disabled")
128+
return
129+
}
128130

129-
posthog = PostHog.Builder(context, config.postHogApiKey, config.postHogHost)
131+
posthog = PostHog.Builder(context, analyticsConfig.postHogApiKey, analyticsConfig.postHogHost)
130132
// Record certain application events automatically! (off/false by default)
131133
// .captureApplicationLifecycleEvents()
132134
// Record screen views automatically! (off/false by default)

vector/src/main/java/im/vector/app/features/analytics/ui/consent/AnalyticsOptInFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ import android.view.LayoutInflater
2121
import android.view.View
2222
import android.view.ViewGroup
2323
import com.airbnb.mvrx.activityViewModel
24-
import im.vector.app.BuildConfig
2524
import im.vector.app.R
25+
import im.vector.app.config.analyticsConfig
2626
import im.vector.app.core.extensions.setTextWithColoredPart
2727
import im.vector.app.core.platform.VectorBaseFragment
2828
import im.vector.app.core.utils.openUrlInChromeCustomTab
@@ -60,7 +60,7 @@ class AnalyticsOptInFragment @Inject constructor(
6060
fullTextRes = R.string.analytics_opt_in_content,
6161
coloredTextRes = R.string.analytics_opt_in_content_link,
6262
onClick = {
63-
openUrlInChromeCustomTab(requireContext(), null, BuildConfig.ANALYTICS_POLICY_URL)
63+
openUrlInChromeCustomTab(requireContext(), null, analyticsConfig.policyLink)
6464
}
6565
)
6666
}

vector/src/main/java/im/vector/app/features/settings/VectorSettingsSecurityPrivacyFragment.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import androidx.recyclerview.widget.RecyclerView
3535
import com.airbnb.mvrx.fragmentViewModel
3636
import com.google.android.material.dialog.MaterialAlertDialogBuilder
3737
import im.vector.app.R
38+
import im.vector.app.config.analyticsConfig
3839
import im.vector.app.core.di.ActiveSessionHolder
3940
import im.vector.app.core.dialogs.ExportKeysDialog
4041
import im.vector.app.core.extensions.queryExportKeys
@@ -50,7 +51,6 @@ import im.vector.app.core.utils.copyToClipboard
5051
import im.vector.app.core.utils.openFileSelection
5152
import im.vector.app.core.utils.toast
5253
import im.vector.app.databinding.DialogImportE2eKeysBinding
53-
import im.vector.app.features.analytics.AnalyticsConfig
5454
import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewActions
5555
import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewModel
5656
import im.vector.app.features.analytics.ui.consent.AnalyticsConsentViewState
@@ -294,7 +294,7 @@ class VectorSettingsSecurityPrivacyFragment @Inject constructor(
294294
}
295295

296296
private fun setUpAnalytics() {
297-
analyticsCategory.isVisible = AnalyticsConfig.isAnalyticsEnabled()
297+
analyticsCategory.isVisible = analyticsConfig.isEnabled
298298

299299
analyticsConsent.setOnPreferenceClickListener {
300300
analyticsConsentViewModel.handle(AnalyticsConsentViewActions.SetUserConsent(analyticsConsent.isChecked))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
* Copyright (c) 2021 New Vector Ltd
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package im.vector.app.config
18+
19+
import im.vector.app.BuildConfig
20+
import im.vector.app.features.analytics.AnalyticsConfig
21+
22+
val analyticsConfig: AnalyticsConfig = object : AnalyticsConfig {
23+
override val isEnabled = BuildConfig.APPLICATION_ID == "im.vector.app"
24+
override val postHogHost = "https://posthog.hss.element.io"
25+
override val postHogApiKey = "phc_Jzsm6DTm6V2705zeU5dcNvQDlonOR68XvX2sh1sEOHO"
26+
override val policyLink = "https://element.io/cookie-policy"
27+
}

0 commit comments

Comments
 (0)