-
Couldn't load subscription status.
- Fork 46
feat: Add analytics tracking to VShare WebView #161
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -103,13 +103,10 @@ protected void init() { | |
|
|
||
| setupWebView(); | ||
|
|
||
| // Compute URL with theme parameter based on current app theme | ||
| // Compute URL with theme and source parameters for analytics tracking | ||
| String url = VSHARE_BASE_URL; | ||
| if (DarkModelUtils.isDarkMode()) { | ||
| url += "?theme=dark"; | ||
| } else { | ||
| url += "?theme=light"; | ||
| } | ||
| String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light"; | ||
| url += "?theme=" + themeParam + "&source=v2er-android"; | ||
|
||
| mWebView.loadUrl(url); | ||
| } | ||
|
|
||
|
|
@@ -143,6 +140,12 @@ private void setupWebView() { | |
|
|
||
| WebSettings settings = mWebView.getSettings(); | ||
|
|
||
| // Set custom User-Agent for analytics tracking | ||
| String defaultUserAgent = settings.getUserAgentString(); | ||
| String appVersion = getAppVersion(); | ||
| String customUserAgent = defaultUserAgent + " V2er-Android/" + appVersion; | ||
| settings.setUserAgentString(customUserAgent); | ||
|
Comment on lines
+148
to
+152
|
||
|
|
||
| // Enable JavaScript | ||
| settings.setJavaScriptEnabled(true); | ||
|
|
||
|
|
@@ -273,6 +276,18 @@ private int getStatusBarHeight() { | |
| return result; | ||
| } | ||
|
|
||
| /** | ||
| * Get app version name for User-Agent tracking | ||
| */ | ||
| private String getAppVersion() { | ||
| try { | ||
| return getPackageManager().getPackageInfo(getPackageName(), 0).versionName; | ||
| } catch (Exception e) { | ||
| Log.e(TAG, "Failed to get app version", e); | ||
| return "unknown"; | ||
|
||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Handle URL loading for WebView | ||
| * Returns true if the URL was handled externally, false if WebView should load it | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Manual string concatenation for query parameters can lead to errors if the base URL ever includes existing parameters or if values need encoding. Consider using Uri.Builder: Uri.parse(VSHARE_BASE_URL).buildUpon().appendQueryParameter("theme", themeParam).appendQueryParameter("source", "v2er-android").build().toString() for safer construction.