Skip to content

Conversation

@graycreate
Copy link
Member

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 string

    • Example: Mozilla/5.0 ... V2er-Android/2.3.12
    • Enables identification of V2er app traffic via User-Agent header
  • Source Parameter: Add source=v2er-android to VShare URL

    • URL format: https://v2er.app/vshare?theme={dark|light}&source=v2er-android
    • Provides additional tracking method via URL parameters
  • App Version Retrieval: Add getAppVersion() helper method

    • Safely retrieves current app version from PackageManager
    • Returns "unknown" if version cannot be retrieved

Benefits

  • Dual Tracking: Both User-Agent and URL parameter provide redundant tracking methods
  • Version Tracking: Analytics can track which app versions are accessing VShare
  • Analytics Flexibility: Can filter by either User-Agent or source parameter
  • Backward Compatible: Changes don't affect existing functionality

Testing

  • ✅ Build successful with ./gradlew assembleDebug
  • Manual testing recommended: Open VShare from app and verify URL parameters and User-Agent in network logs

Files Changed

  • app/src/main/java/me/ghui/v2er/module/vshare/VshareWebActivity.java (+21, -6)

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings October 18, 2025 03:30
Copy link

Copilot AI left a 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.

Comment on lines 108 to 109
String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light";
url += "?theme=" + themeParam + "&source=v2er-android";
Copy link

Copilot AI Oct 18, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 282 to 287
private String getAppVersion() {
try {
return getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
} catch (Exception e) {
Log.e(TAG, "Failed to get app version", e);
return "unknown";
Copy link

Copilot AI Oct 18, 2025

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";.

Copilot uses AI. Check for mistakes.
Comment on lines +143 to +147
// Set custom User-Agent for analytics tracking
String defaultUserAgent = settings.getUserAgentString();
String appVersion = getAppVersion();
String customUserAgent = defaultUserAgent + " V2er-Android/" + appVersion;
settings.setUserAgentString(customUserAgent);
Copy link

Copilot AI Oct 18, 2025

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.

Copilot generated this review using guidance from repository custom instructions.
Comment on lines 108 to 109
String themeParam = DarkModelUtils.isDarkMode() ? "dark" : "light";
url += "?theme=" + themeParam + "&source=v2er-android";
Copy link

Copilot AI Oct 18, 2025

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.

Copilot generated this review using guidance from repository custom instructions.
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>
@graycreate graycreate merged commit 40fb779 into main Oct 18, 2025
5 checks passed
@graycreate graycreate deleted the feature/vshare-analytics-tracking branch October 18, 2025 03:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants