-
-
Notifications
You must be signed in to change notification settings - Fork 45
CI-423 Categorize Demo Users In Analytics #3454
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
CI-423 Categorize Demo Users In Analytics #3454
Conversation
Added isDemo user property to firebase analytics reporting.
Optimized imports.
Added null check in case there is a non-fatal error.
📝 WalkthroughWalkthroughThis PR adds demo user tracking to analytics by introducing a detection mechanism across the stack. It exposes the private Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes
Possibly related PRs
Suggested labels
Suggested reviewers
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
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.
Actionable comments posted: 0
🧹 Nitpick comments (2)
app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java (1)
239-241: Accessor for demo flag looks good; consider brief documentation.The getter cleanly exposes the persisted
isDemoflag and matches its use fromReportingUtils. To align with howConnectUserRecordfields are generally documented, you might add a short Javadoc explaining what counts as a “demo” user in this context (e.g., Personal ID demo account vs other demo states).
Based on learnings, this class benefits from field/method Javadocs.app/src/org/commcare/android/logging/ReportingUtils.java (1)
13-13: Avoid exception-driven flow ingetIsDemoUserto reduce log noise.Right now, if there’s no Personal ID user (or
getUserreturns null), you’ll likely hit aNullPointerExceptioninside thetryand log an exception every timesetUserPropertiesruns, which can be frequent on pre-login or non‑Personal‑ID flows. You already short‑circuit withisloggedIn()ingetPersonalID; mirroring that here would avoid treating expected states as errors.One possible refactor:
@@ - public static Boolean getIsDemoUser() { - try { - CommCareApplication app = CommCareApplication.instance(); - PersonalIdManager manager = PersonalIdManager.getInstance(); - return manager.getUser(app).getIsDemo(); - } catch (Exception e) { - String errorMessage = - "Error checking if user is a demo user for Firebase analytics reporting"; - Logger.exception(errorMessage, e); - return null; - } - } + public static Boolean getIsDemoUser() { + try { + CommCareApplication app = CommCareApplication.instance(); + PersonalIdManager manager = PersonalIdManager.getInstance(); + + if (!manager.isloggedIn()) { + return null; + } + + // getUser may still return null in edge cases; treat that as "unknown" demo status + if (manager.getUser(app) == null) { + return null; + } + + return manager.getUser(app).getIsDemo(); + } catch (Exception e) { + String errorMessage = + "Error checking if user is a demo user for Firebase analytics reporting"; + Logger.exception(errorMessage, e); + return null; + } + }(You can cache
manager.getUser(app)in a local variable if desired to avoid calling it twice.)Also applies to: 163-174
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (4)
app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java(1 hunks)app/src/org/commcare/android/logging/ReportingUtils.java(2 hunks)app/src/org/commcare/google/services/analytics/CCAnalyticsParam.java(1 hunks)app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java(2 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-01-21T17:28:09.007Z
Learnt from: OrangeAndGreen
Repo: dimagi/commcare-android PR: 2912
File: app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java:66-71
Timestamp: 2025-01-21T17:28:09.007Z
Learning: The ConnectUserRecord class in CommCare Android uses Persisting annotations with sequential indices for field persistence, and MetaField annotations for fields that have corresponding META constants. Fields should be documented with Javadoc comments explaining their purpose, format requirements, and relationships with other fields.
Applied to files:
app/src/org/commcare/android/database/connect/models/ConnectUserRecord.java
📚 Learning: 2025-01-27T15:14:56.422Z
Learnt from: pm-dimagi
Repo: dimagi/commcare-android PR: 2847
File: app/src/org/commcare/utils/EncryptionUtils.java:167-167
Timestamp: 2025-01-27T15:14:56.422Z
Learning: MD5 hashing is acceptable for non-security purposes like analytics tracking in FirebaseAnalyticsUtil.
Applied to files:
app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java
🧬 Code graph analysis (2)
app/src/org/commcare/android/logging/ReportingUtils.java (2)
app/src/org/commcare/CommCareApplication.java (1)
CommCareApplication(158-1255)app/src/org/commcare/connect/PersonalIdManager.java (1)
PersonalIdManager(63-581)
app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java (2)
app/src/org/commcare/android/logging/ReportingUtils.java (1)
ReportingUtils(20-175)app/src/org/commcare/google/services/analytics/CCAnalyticsParam.java (1)
CCAnalyticsParam(7-51)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: Lint Code Base
🔇 Additional comments (2)
app/src/org/commcare/google/services/analytics/CCAnalyticsParam.java (1)
50-50: NewIS_DEMO_USERanalytics param is consistent and clear.The constant name and value follow the existing convention in
CCAnalyticsParamand are appropriate for a Firebase user property key.app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java (1)
28-28: Demo user property wiring into Firebase looks correct and null‑safe.Fetching
Boolean isDemoUserfromReportingUtilsand only settingIS_DEMO_USERwhen it’s non‑null is consistent with how other user properties are handled, andString.valueOf(isDemoUser)matches the existing pattern of stringified booleans (e.g.,CCC_ENABLED). No functional issues spotted here.Also applies to: 127-130
app/src/org/commcare/google/services/analytics/FirebaseAnalyticsUtil.java
Show resolved
Hide resolved
app/src/org/commcare/google/services/analytics/CCAnalyticsParam.java
Outdated
Show resolved
Hide resolved
Added check for if the user is logged in to prevent unnecessary exception logs.
Refactored code to note distinction between a Personal ID demo user and a CommCare demo user.
Refactored non-fatal error device log to be more ambiguous, but also specific to Personal ID.
|
@damagatchi retest this please |
CI-423
Technical Summary
These changes complete the first step in the ticket:
Later, my plan is to modify our query for the user funnel based on this new property.
Safety Assurance
Safety story
I will run a test query to make sure that the new parameter for my test user shows as expected before I merge these changes in.