-
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
Conversation
Add custom User-Agent and source parameter to track V2er app traffic
to VShare page for analytics purposes.
Changes:
- Set custom User-Agent: "Mozilla/5.0... V2er-Android/{version}"
- Add source parameter to URL: "?theme={theme}&source=v2er-android"
- Add getAppVersion() method to retrieve app version for User-Agent
This enables VShare page to:
1. Identify traffic from V2er Android app via User-Agent header
2. Track app version distribution
3. Filter analytics by source parameter
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
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.
Pull Request Overview
Adds analytics tracking to the VShare WebView by augmenting the loaded URL and the WebView's User-Agent to identify app-originated traffic and version usage.
- Appends theme and source query parameters to the VShare URL.
- Extends the WebView User-Agent with app version info via a new getAppVersion() helper.
- Introduces a method to safely obtain the app version for tracking.
| String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light"; | ||
| url += "?theme=" + themeParam + "&source=v2er-android"; |
Copilot
AI
Oct 18, 2025
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.
| private String getAppVersion() { | ||
| try { | ||
| return getPackageManager().getPackageInfo(getPackageName(), 0).versionName; | ||
| } catch (Exception e) { | ||
| Log.e(TAG, "Failed to get app version", e); | ||
| return "unknown"; |
Copilot
AI
Oct 18, 2025
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] Using PackageManager#getPackageInfo with a raw int flag is deprecated on newer API levels and catching generic Exception is overly broad. Prefer BuildConfig.VERSION_NAME directly (no try/catch needed) or catch PackageManager.NameNotFoundException specifically. Example: return BuildConfig.VERSION_NAME != null ? BuildConfig.VERSION_NAME : "unknown";.
| // Set custom User-Agent for analytics tracking | ||
| String defaultUserAgent = settings.getUserAgentString(); | ||
| String appVersion = getAppVersion(); | ||
| String customUserAgent = defaultUserAgent + " V2er-Android/" + appVersion; | ||
| settings.setUserAgentString(customUserAgent); |
Copilot
AI
Oct 18, 2025
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.
New User-Agent augmentation logic lacks automated test coverage (e.g., instrumentation test asserting WebView#getSettings().getUserAgentString() ends with the expected suffix). Adding a focused test would protect analytics integrity across refactors.
| String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light"; | ||
| url += "?theme=" + themeParam + "&source=v2er-android"; |
Copilot
AI
Oct 18, 2025
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.
The new URL construction adding theme and source parameters is not covered by a test verifying the final loaded URL (e.g., via a mocked WebView client or Uri parse assertion). Adding a test ensures analytics query parameters are consistently present.
Address code review feedback from Copilot: 1. Use Uri.Builder for safer URL construction - Replace manual string concatenation with Uri.Builder - Properly encode query parameters - Handle existing parameters correctly 2. Replace PackageManager with BuildConfig.VERSION_NAME - Use BuildConfig.VERSION_NAME directly (no try/catch needed) - Avoid deprecated PackageManager.getPackageInfo() call - Simpler and more reliable implementation Changes: - VshareWebActivity.java:106-114: Use Uri.Builder for URL construction - VshareWebActivity.java:286-288: Simplify getAppVersion() with BuildConfig - Add BuildConfig import Note: Test coverage suggestions noted but deferred for future enhancement. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
Summary
Add custom User-Agent and source parameter to track V2er app traffic to VShare page for analytics purposes.
Changes
Custom User-Agent: Append
V2er-Android/{version}to the default User-Agent stringMozilla/5.0 ... V2er-Android/2.3.12Source Parameter: Add
source=v2er-androidto VShare URLhttps://v2er.app/vshare?theme={dark|light}&source=v2er-androidApp Version Retrieval: Add
getAppVersion()helper methodBenefits
Testing
./gradlew assembleDebugFiles Changed
app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java(+21, -6)🤖 Generated with Claude Code