mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 22:34:59 +00:00
feat: Enhance analytics opt-in logic with user sampling and explicit control
This commit is contained in:
parent
3a28e74d89
commit
539a6cde63
4 changed files with 29 additions and 9 deletions
|
@ -62,8 +62,21 @@ class Analytics:
|
||||||
self.permanently_disable = True
|
self.permanently_disable = True
|
||||||
self.save_data()
|
self.save_data()
|
||||||
|
|
||||||
def need_to_ask(self):
|
def need_to_ask(self, args_analytics):
|
||||||
return not self.asked_opt_in and not self.permanently_disable
|
if args_analytics is False:
|
||||||
|
return False
|
||||||
|
|
||||||
|
could_ask = not self.asked_opt_in and not self.permanently_disable
|
||||||
|
if not could_ask:
|
||||||
|
return False
|
||||||
|
|
||||||
|
if args_analytics is True:
|
||||||
|
return True
|
||||||
|
|
||||||
|
assert args_analytics is None, args_analytics
|
||||||
|
|
||||||
|
# ask 1/16 of the users
|
||||||
|
return self.user_id < "1"
|
||||||
|
|
||||||
def get_data_file_path(self):
|
def get_data_file_path(self):
|
||||||
data_file = Path.home() / ".aider" / "analytics.json"
|
data_file = Path.home() / ".aider" / "analytics.json"
|
||||||
|
|
|
@ -562,8 +562,8 @@ def get_parser(default_config_files, git_root):
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--analytics",
|
"--analytics",
|
||||||
action=argparse.BooleanOptionalAction,
|
action=argparse.BooleanOptionalAction,
|
||||||
default=False,
|
default=None,
|
||||||
help="Enable/disable analytics for one session (default: False)",
|
help="Enable/disable analytics for current session (default: random)",
|
||||||
)
|
)
|
||||||
group.add_argument(
|
group.add_argument(
|
||||||
"--analytics-log",
|
"--analytics-log",
|
||||||
|
|
|
@ -506,8 +506,8 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F
|
||||||
io.tool_warning("Terminal does not support pretty output (UnicodeDecodeError)")
|
io.tool_warning("Terminal does not support pretty output (UnicodeDecodeError)")
|
||||||
|
|
||||||
analytics = Analytics(logfile=args.analytics_log, permanently_disable=args.analytics_disable)
|
analytics = Analytics(logfile=args.analytics_log, permanently_disable=args.analytics_disable)
|
||||||
if args.analytics:
|
if args.analytics is not False:
|
||||||
if analytics.need_to_ask():
|
if analytics.need_to_ask(args.analytics):
|
||||||
io.tool_output(
|
io.tool_output(
|
||||||
"Aider respects your privacy and never collects your code, chat messages, keys or"
|
"Aider respects your privacy and never collects your code, chat messages, keys or"
|
||||||
" personal info."
|
" personal info."
|
||||||
|
|
|
@ -91,10 +91,17 @@ def test_system_info(temp_data_dir):
|
||||||
|
|
||||||
def test_need_to_ask(temp_data_dir):
|
def test_need_to_ask(temp_data_dir):
|
||||||
analytics = Analytics()
|
analytics = Analytics()
|
||||||
assert analytics.need_to_ask() is True
|
assert analytics.need_to_ask(True) is True
|
||||||
|
assert analytics.need_to_ask(False) is False
|
||||||
|
|
||||||
|
analytics.user_id = "111"
|
||||||
|
assert analytics.need_to_ask(None) is False
|
||||||
|
|
||||||
|
analytics.user_id = "000"
|
||||||
|
assert analytics.need_to_ask(None) is True
|
||||||
|
|
||||||
analytics.asked_opt_in = True
|
analytics.asked_opt_in = True
|
||||||
assert analytics.need_to_ask() is False
|
assert analytics.need_to_ask(True) is False
|
||||||
|
|
||||||
analytics.permanently_disable = True
|
analytics.permanently_disable = True
|
||||||
assert analytics.need_to_ask() is False
|
assert analytics.need_to_ask(True) is False
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue