-
Notifications
You must be signed in to change notification settings - Fork 749
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4559 from vector-im/feature/bma/posthog
Analytics
- Loading branch information
Showing
71 changed files
with
2,166 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Analytics in Element | ||
|
||
## Solution | ||
|
||
Element is using PostHog to send analytics event. | ||
We ask for the user to give consent before sending any analytics data. | ||
|
||
## How to add a new Event | ||
|
||
The analytics plan is shared between all Element clients. To add an Event, please open a PR to this project: https://github.com/matrix-org/matrix-analytics-events | ||
|
||
Then, once the PR has been merged, you can run the tool `import_analytic_plan.sh` to import the plan to Element, and then you can use the new Event. Note that this tool is run by Github action once a week. | ||
|
||
## Forks of Element | ||
|
||
Analytics on forks are disabled by default. Please refer to AnalyticsConfig and there implementation to setup analytics on your project. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<dimen name="width_percent">0.6</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<dimen name="width_percent">0.5</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<resources> | ||
|
||
<dimen name="width_percent">1</dimen> | ||
|
||
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#!/usr/bin/env bash | ||
|
||
echo "Deleted existing plan..." | ||
rm vector/src/main/java/im/vector/app/features/analytics/plan/*.* | ||
|
||
echo "Cloning analytics project..." | ||
mkdir analytics_tmp | ||
cd analytics_tmp | ||
git clone https://github.com/matrix-org/matrix-analytics-events.git | ||
|
||
echo "Copy plan..." | ||
cp matrix-analytics-events/types/kotlin2/* ../vector/src/main/java/im/vector/app/features/analytics/plan/ | ||
|
||
echo "Cleanup." | ||
cd .. | ||
rm -rf analytics_tmp | ||
|
||
echo "Done." |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
vector/src/debug/java/im/vector/app/config/AnalyticsConfig.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
vector/src/debug/java/im/vector/app/features/debug/analytics/DebugAnalyticsActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* | ||
* 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.debug.analytics | ||
|
||
import dagger.hilt.android.AndroidEntryPoint | ||
import im.vector.app.core.extensions.addFragment | ||
import im.vector.app.core.platform.VectorBaseActivity | ||
import im.vector.app.databinding.ActivitySimpleBinding | ||
|
||
@AndroidEntryPoint | ||
class DebugAnalyticsActivity : VectorBaseActivity<ActivitySimpleBinding>() { | ||
|
||
override fun getBinding() = ActivitySimpleBinding.inflate(layoutInflater) | ||
|
||
override fun initUiAndData() { | ||
if (isFirstCreation()) { | ||
addFragment( | ||
views.simpleFragmentContainer, | ||
DebugAnalyticsFragment::class.java | ||
) | ||
} | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
vector/src/debug/java/im/vector/app/features/debug/analytics/DebugAnalyticsFragment.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* 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.debug.analytics | ||
|
||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import com.airbnb.mvrx.fragmentViewModel | ||
import com.airbnb.mvrx.withState | ||
import im.vector.app.core.epoxy.onClick | ||
import im.vector.app.core.extensions.toOnOff | ||
import im.vector.app.core.platform.VectorBaseFragment | ||
import im.vector.app.databinding.FragmentDebugAnalyticsBinding | ||
import me.gujun.android.span.span | ||
|
||
class DebugAnalyticsFragment : VectorBaseFragment<FragmentDebugAnalyticsBinding>() { | ||
|
||
private val viewModel: DebugAnalyticsViewModel by fragmentViewModel() | ||
|
||
override fun getBinding(inflater: LayoutInflater, container: ViewGroup?): FragmentDebugAnalyticsBinding { | ||
return FragmentDebugAnalyticsBinding.inflate(inflater, container, false) | ||
} | ||
|
||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) { | ||
super.onViewCreated(view, savedInstanceState) | ||
|
||
setViewListeners() | ||
} | ||
|
||
private fun setViewListeners() { | ||
views.showAnalyticsOptIn.onClick { | ||
navigator.openAnalyticsOptIn(requireContext()) | ||
} | ||
views.resetAnalyticsOptInDisplayed.onClick { | ||
viewModel.handle(DebugAnalyticsViewActions.ResetAnalyticsOptInDisplayed) | ||
} | ||
} | ||
|
||
override fun invalidate() = withState(viewModel) { state -> | ||
views.analyticsStoreContent.text = span { | ||
+"AnalyticsId: " | ||
span { | ||
textStyle = "bold" | ||
text = state.analyticsId.orEmpty() | ||
} | ||
+"\nOptIn: " | ||
span { | ||
textStyle = "bold" | ||
text = state.userConsent.toOnOff() | ||
} | ||
+"\nDidAsk: " | ||
span { | ||
textStyle = "bold" | ||
text = state.didAskUserConsent.toString() | ||
} | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
vector/src/debug/java/im/vector/app/features/debug/analytics/DebugAnalyticsViewActions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* 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.debug.analytics | ||
|
||
import im.vector.app.core.platform.VectorViewModelAction | ||
|
||
sealed interface DebugAnalyticsViewActions : VectorViewModelAction { | ||
object ResetAnalyticsOptInDisplayed : DebugAnalyticsViewActions | ||
} |
64 changes: 64 additions & 0 deletions
64
vector/src/debug/java/im/vector/app/features/debug/analytics/DebugAnalyticsViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.debug.analytics | ||
|
||
import com.airbnb.mvrx.MavericksViewModelFactory | ||
import dagger.assisted.Assisted | ||
import dagger.assisted.AssistedFactory | ||
import dagger.assisted.AssistedInject | ||
import im.vector.app.core.di.MavericksAssistedViewModelFactory | ||
import im.vector.app.core.di.hiltMavericksViewModelFactory | ||
import im.vector.app.core.extensions.exhaustive | ||
import im.vector.app.core.platform.EmptyViewEvents | ||
import im.vector.app.core.platform.VectorViewModel | ||
import im.vector.app.features.analytics.store.AnalyticsStore | ||
import kotlinx.coroutines.launch | ||
|
||
class DebugAnalyticsViewModel @AssistedInject constructor( | ||
@Assisted initialState: DebugAnalyticsViewState, | ||
private val analyticsStore: AnalyticsStore | ||
) : VectorViewModel<DebugAnalyticsViewState, DebugAnalyticsViewActions, EmptyViewEvents>(initialState) { | ||
|
||
@AssistedFactory | ||
interface Factory : MavericksAssistedViewModelFactory<DebugAnalyticsViewModel, DebugAnalyticsViewState> { | ||
override fun create(initialState: DebugAnalyticsViewState): DebugAnalyticsViewModel | ||
} | ||
|
||
companion object : MavericksViewModelFactory<DebugAnalyticsViewModel, DebugAnalyticsViewState> by hiltMavericksViewModelFactory() | ||
|
||
init { | ||
observerStore() | ||
} | ||
|
||
private fun observerStore() { | ||
analyticsStore.analyticsIdFlow.setOnEach { copy(analyticsId = it) } | ||
analyticsStore.userConsentFlow.setOnEach { copy(userConsent = it) } | ||
analyticsStore.didAskUserConsentFlow.setOnEach { copy(didAskUserConsent = it) } | ||
} | ||
|
||
override fun handle(action: DebugAnalyticsViewActions) { | ||
when (action) { | ||
DebugAnalyticsViewActions.ResetAnalyticsOptInDisplayed -> handleResetAnalyticsOptInDisplayed() | ||
}.exhaustive | ||
} | ||
|
||
private fun handleResetAnalyticsOptInDisplayed() { | ||
viewModelScope.launch { | ||
analyticsStore.setDidAskUserConsent(false) | ||
} | ||
} | ||
} |
Oops, something went wrong.