From 324077c20bc3c2e810a724b72a8b2412304cfab4 Mon Sep 17 00:00:00 2001 From: Nathan Bu <370788475@qq.com> Date: Thu, 25 Jan 2024 17:34:15 +0800 Subject: [PATCH] Add clarity initialization in the MainActivity.java (#636) ## Description We want to leverage clarity to understand the usage data of Hydra Lab client. This can enable data dashboard, error diagnostic, etc. A related update to reflect the change: https://github.com/microsoft/HydraLab/pull/637/files ### Linked GitHub issue ID: # ## Pull Request Checklist - [ ] Tests for the changes have been added (for bug fixes / features) - [x] Code compiles correctly with all tests are passed. - [x] I've read the [contributing guide](https://github.com/microsoft/HydraLab/blob/main/CONTRIBUTING.md#making-changes-to-the-code) and followed the recommended practices. - [x] [Wikis](https://github.com/microsoft/HydraLab/wiki) or [README](https://github.com/microsoft/HydraLab/blob/main/README.md) have been reviewed and added / updated if needed (for bug fixes / features) ### Does this introduce a breaking change? *If this introduces a breaking change for Hydra Lab users, please describe the impact and migration path.* - [x] Yes - [ ] No ## How you tested it *Please make sure the change is tested, you can test it by adding UTs, do local test and share the screenshots, etc.* Build and run the app. This integration practice comply with [android-sdk installation](https://learn.microsoft.com/en-us/clarity/mobile-sdk/android-sdk). Please check the type of change your PR introduces: - [ ] Bugfix - [x] Feature - [ ] Technical design - [ ] Build related changes - [ ] Refactoring (no functional changes, no api changes) - [ ] Code style update (formatting, renaming) or Documentation content changes - [ ] Other (please describe): ### Feature UI screenshots or Technical design diagrams *If this is a relatively large or complex change, kick it off by drawing the tech design with PlantUML and explaining why you chose the solution you did and what alternatives you considered, etc...* --- android_client/app/build.gradle | 2 +- .../hydralab/android/client/MainActivity.java | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/android_client/app/build.gradle b/android_client/app/build.gradle index b13e7f71d..c2b9da677 100644 --- a/android_client/app/build.gradle +++ b/android_client/app/build.gradle @@ -62,7 +62,7 @@ dependencies { implementation 'androidx.core:core-ktx:1.10.1' implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.6.1' implementation 'androidx.annotation:annotation-jvm:1.6.0' - implementation 'com.microsoft.clarity:clarity:1.3.3' + implementation 'com.microsoft.clarity:clarity:2.1.1' androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' androidTestImplementation 'androidx.test.uiautomator:uiautomator:2.2.0' androidTestImplementation 'androidx.test:runner:1.4.0' diff --git a/android_client/app/src/main/java/com/microsoft/hydralab/android/client/MainActivity.java b/android_client/app/src/main/java/com/microsoft/hydralab/android/client/MainActivity.java index b892e2ce5..a65767fa9 100644 --- a/android_client/app/src/main/java/com/microsoft/hydralab/android/client/MainActivity.java +++ b/android_client/app/src/main/java/com/microsoft/hydralab/android/client/MainActivity.java @@ -43,12 +43,17 @@ import android.widget.Switch; import android.widget.Toast; +import com.microsoft.clarity.Clarity; +import com.microsoft.clarity.ClarityConfig; +import com.microsoft.clarity.models.ApplicationFramework; +import com.microsoft.clarity.models.LogLevel; import com.microsoft.hydralab.android.client.view.NamedSpinner; import java.io.File; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; import java.util.Locale; @@ -137,6 +142,23 @@ protected void onCreate(Bundle savedInstanceState) { mAudioSwitch.setChecked( PreferenceManager.getDefaultSharedPreferences(getApplicationContext()) .getBoolean(getResources().getResourceEntryName(mAudioSwitch.getId()), false)); + initClarity(); + } + + private void initClarity() { + ClarityConfig config = new ClarityConfig( + "kj0ror1pki", + null, // Default user id + LogLevel.Info, + false, // Disallow metered network usage + true, // Enable web view capturing + Collections.singletonList("*"), // Allowed domains + ApplicationFramework.Native, + Collections.emptyList(), + Collections.emptyList(), + false); + + Clarity.initialize(getApplicationContext(), config); } @Override