Analytics

Central analytics class for tracking user behavior and application metrics.

Overview

This class provides a unified interface for logging events and user properties to multiple analytics providers including Firebase Analytics and AppMetrica. All tracking methods are static for easy access throughout the application.

Key Features

  • Event tracking with custom parameters
  • User identification and property management
  • Predefined event names and parameter keys
  • Automatic logging to multiple analytics providers

Usage Examples

Basic Event Logging

// Simple event without parameters
Analytics.logEvent(Analytics.E_ONBOARD_STEP_DONE);

// Event with parameters
Bundle params = new Bundle();
params.putString(Analytics.P_STAGE, "welcome");
params.putLong(Analytics.P_DURATION, 5000);
Analytics.logEvent(Analytics.E_ONBOARD_STEP_DONE, params);

User Identification

// Set user ID for tracking
Analytics.setUserId("user_123");

// Set user properties
Analytics.setUserProperty("subscription_type", "premium");

Event Reference

E_ONBOARD_STEP_DONEUser completes an onboarding stepP_STAGE, P_DURATION
E_DETECTION_SESSIONDoomscrolling session trackingP_DURATION, P_COUNT
E_WARN1_SHOWN, E_WARN2_SHOWNWarning dialogs shown to user-
E_COOLDOWN_COMPLETEDUser completes cooldown periodP_DURATION

Best Practices

  • Always use predefined event names and parameter keys when available
  • Keep event names descriptive and consistent
  • Use snake_case for all custom event names and parameters
  • Be mindful of user privacy when logging potentially sensitive information

Author

DoomScrolling Team

Since

1.0

See also

Properties

Link copied to clipboard
val E_COOLDOWN_COMPLETED: String = "cooldown_completed"
Tracks when a cooldown is completed.
Link copied to clipboard
val E_COOLDOWN_RATIO: String = "cooldown_ratio"
Tracks the ratio of completed cooldowns to started cooldowns.
Link copied to clipboard
val E_DETECTION_SESSION: String = "doomscroll_session"
Tracks doomscrolling session summary.
Link copied to clipboard
val E_DOOM_SESSION_RATIO: String = "doom_session_ratio"
Tracks the ratio of actual doomscrolling sessions to total sessions.
Link copied to clipboard
val E_GRACE_RATIO: String = "grace_ratio"
Tracks the ratio of grace period usage to cooldown starts.
Link copied to clipboard
val E_GRACE_USED: String = "grace_used"
Tracks when the grace period is used.
Link copied to clipboard
val E_LOCK_GRACE_USED: String = "lock_grace_used"
Tracks when the grace period is used during lock.
Link copied to clipboard
val E_LOCK_STARTED: String = "lock_started"
Tracks when the app lock is started.
Link copied to clipboard
val E_ONBOARD_STEP_DONE: String = "onboarding_step_completed"
Tracks completion of onboarding steps.
Link copied to clipboard
val E_PERMISSION_DONE: String = "permissions_granted"
Tracks when permissions are granted.
Link copied to clipboard
val E_PERMISSIONS_REVOKED: String = "permission_revoked"
Tracks when permissions are revoked.
Link copied to clipboard
val E_REOPEN_WITHIN_2M: String = "reopen_within_2m"
Tracks when the app is reopened within 2 minutes.
Link copied to clipboard
val E_REOPEN_WITHIN_2M_RATIO: String = "reopen_within_2m_ratio"
Tracks how often users reopen the app within 2 minutes of closing it.
Link copied to clipboard
val E_SERVICE_TOGGLED: String = "service_toggled"
Tracks when the background service is toggled on/off.
Link copied to clipboard
val E_SURVEY_HELPFUL_ANSWER: String = "survey_helpful_answer"
Tracks user response to the helpfulness survey.
Link copied to clipboard
val E_SURVEY_HELPFUL_SHOWN: String = "survey_helpful_shown"
Tracks when the helpfulness survey is shown.
Link copied to clipboard
val E_SURVEY_INTRUSIVE_ANSWER: String = "survey_intrusive_answer"
Tracks user response to the intrusiveness survey.
Link copied to clipboard
val E_SURVEY_INTRUSIVE_SHOWN: String = "survey_intrusive_shown"
Tracks when the intrusiveness survey is shown.
Link copied to clipboard
val E_TAKE_REST_GLOBAL_RATIO: String = "take_rest_global_ratio"
Tracks the global ratio of take rest actions to total popups shown.
Link copied to clipboard
val E_WARN1_ACTION: String = "warn1_action"
Tracks user action after the first warning.
Link copied to clipboard
val E_WARN1_KEEP_SCROLL_RATIO: String = "warn1_keep_scroll_ratio"
Tracks user response to the first warning (keep scrolling option).
Link copied to clipboard
val E_WARN1_SHOWN: String = "warn1_shown"
Tracks when the first warning is shown to the user.
Link copied to clipboard
val E_WARN1_TAKE_REST_RATIO: String = "warn1_take_rest_ratio"
Tracks user response to the first warning (take rest option).
Link copied to clipboard
val E_WARN2_ACTION: String = "warn2_action"
Tracks user action after the second warning.
Link copied to clipboard
val E_WARN2_KEEP_SCROLL_RATIO: String = "warn2_keep_scroll_ratio"
Tracks user response to the second warning (keep scrolling option).
Link copied to clipboard
val E_WARN2_SHOWN: String = "warn2_shown"
Tracks when the second warning is shown to the user.
Link copied to clipboard
val E_WARN2_TAKE_REST_RATIO: String = "warn2_take_rest_ratio"
Tracks user response to the second warning (take rest option).
Link copied to clipboard
val KEY_INSTALL_TS: String = "install_ts"
Timestamp of when the app was installed
Link copied to clipboard
val P_ACTION: String = "action"
The user's action in response to an intervention.
Link copied to clipboard
val P_ANSWER: String = "answer"
User's response to a survey question
Link copied to clipboard
val P_COOLDOWN_COMPLETED: String = "cooldown_completed"
Number of times cooldown was successfully completed
Link copied to clipboard
val P_COOLDOWN_RATIO: String = "cooldown_ratio"
Ratio of completed cooldowns to started cooldowns (cooldown_completed / cooldown_started)
Link copied to clipboard
val P_COOLDOWN_STARTED: String = "cooldown_started"
Number of times cooldown was initiated
Link copied to clipboard
val P_COUNT: String = "count"
Count value
Link copied to clipboard
val P_DAYS_SINCE_INSTALL: String = "days_since_install"
Number of days since the app was installed
Link copied to clipboard
val P_DURATION: String = "duration_ms"
Duration in milliseconds
Link copied to clipboard
val P_GRACE_RATIO: String = "grace_ratio"
Ratio of grace period usage to cooldown starts (grace_used / cooldown_started)
Link copied to clipboard
val P_GRACE_USED: String = "grace_used"
Number of times grace period was used
Link copied to clipboard
val P_PKG: String = "package"
The package name of the app being used
Link copied to clipboard
val P_REOPEN_RATIO: String = "reopen_ratio"
Ratio of reopens to take rest actions (reopen_within_2m / take_rest_clicked)
Link copied to clipboard
val P_REOPEN_WITHIN_2M: String = "reopen_within_2m"
Number of times app was reopened within 2 minutes
Link copied to clipboard
val P_RESULT: String = "result"
Generic result parameter
Link copied to clipboard
val P_STAGE: String = "stage"
The current stage of the intervention.
Link copied to clipboard
val P_SUCCESS: String = "success"
Success flag (1 for success, 0 for failure)
Link copied to clipboard
val P_SURVEY_NAME: String = "survey_name"
Name of the survey being shown/answered
Link copied to clipboard
val P_TAKE_REST_CLICKED: String = "take_rest_clicked"
Number of times take rest button was clicked
Link copied to clipboard
val P_TAKE_REST_COUNT: String = "take_rest_count"
Total number of times user chose to take rest
Link copied to clipboard
val P_TAKE_REST_RATIO: String = "take_rest_ratio"
Global ratio of take rest actions to popups shown (take_rest_count / total_popups)
Link copied to clipboard
val P_TOTAL_POPUPS: String = "total_popups"
Total number of popups shown to the user
Link copied to clipboard
val P_TOTAL_SESSIONS: String = "total_sessions"
Total number of sessions tracked
Link copied to clipboard
val P_TRUE_DOOM_RATIO: String = "true_doom_ratio"
Ratio of doomscrolling sessions to total sessions (true_doom_sessions / total_sessions)
Link copied to clipboard
val P_TRUE_DOOM_SESSIONS: String = "true_doom_sessions"
Number of sessions identified as doomscrolling
Link copied to clipboard
val P_WARN1_KEEP_SCROLL: String = "warn1_keep_scroll"
Number of times user chose to keep scrolling after warning 1
Link copied to clipboard
val P_WARN1_KEEP_SCROLL_RATIO: String = "warn1_keep_scroll_ratio"
Ratio of keep scrolling actions to warning 1 shown
Link copied to clipboard
val P_WARN1_SHOWN: String = "warn1_shown"
Number of times warning 1 was shown to the user
Link copied to clipboard
val P_WARN1_TAKE_REST: String = "warn1_take_rest"
Number of times user chose to take rest after warning 1
Link copied to clipboard
val P_WARN1_TAKE_REST_RATIO: String = "warn1_take_rest_ratio"
Ratio of take rest actions to warning 1 shown
Link copied to clipboard
val P_WARN2_KEEP_SCROLL: String = "warn2_keep_scroll"
Number of times user chose to keep scrolling after warning 2
Link copied to clipboard
val P_WARN2_KEEP_SCROLL_RATIO: String = "warn2_keep_scroll_ratio"
Ratio of keep scrolling actions to warning 2 shown
Link copied to clipboard
val P_WARN2_SHOWN: String = "warn2_shown"
Number of times warning 2 was shown to the user
Link copied to clipboard
val P_WARN2_TAKE_REST: String = "warn2_take_rest"
Number of times user chose to take rest after warning 2
Link copied to clipboard
val P_WARN2_TAKE_REST_RATIO: String = "warn2_take_rest_ratio"
Ratio of take rest actions to warning 2 shown

Functions

Link copied to clipboard
open fun logEvent(@NonNull eventName: String)
Logs a basic analytics event without any additional parameters.
open fun logEvent(@NonNull eventName: String, @Nullable params: Bundle)
Logs an analytics event with the specified parameters.
Link copied to clipboard
open fun setUserId(@Nullable uid: String)
Sets the user ID for analytics tracking across all sessions and devices.
Link copied to clipboard
open fun setUserProperty(@NonNull key: String, @Nullable value: String)
Sets a user property for analytics tracking.